-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Haggus/handle-file-limit
Handle 'limit' event when file is over fileSize
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const request = require('supertest'); | ||
const server = require('./server'); | ||
const app = server.setup({ | ||
limits: {fileSize: 200 * 1024} // set 200kb upload limit | ||
}); | ||
const clearUploadsDir = server.clearUploadsDir; | ||
const fileDir = server.fileDir; | ||
|
||
describe('Test Single File Upload With File Size Limit', function() { | ||
it(`upload 'basketball.png' (~154kb) with 200kb size limit`, function(done) { | ||
let filePath = path.join(fileDir, 'basketball.png'); | ||
|
||
clearUploadsDir(); | ||
|
||
request(app) | ||
.post('/upload/single') | ||
.attach('testFile', filePath) | ||
.expect(200) | ||
.end(done); | ||
}); | ||
|
||
it(`fail when uploading 'car.png' (~269kb) with 200kb size limit`, function(done) { | ||
let filePath = path.join(fileDir, 'car.png'); | ||
|
||
clearUploadsDir(); | ||
|
||
request(app) | ||
.post('/upload/single') | ||
.attach('testFile', filePath) | ||
.expect(413) | ||
.end(done); | ||
}); | ||
}); |