forked from expressjs/multer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcfc80d
commit ba9a31a
Showing
4 changed files
with
65 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
*.DS_Store | ||
temp/ |
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
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,59 @@ | ||
var fs = require('fs'); | ||
var rimraf = require('rimraf'); | ||
var expect = require('chai').expect | ||
var request = require('supertest'); | ||
var express = require('express'); | ||
var multer = require('../'); | ||
|
||
describe('Functionality', function () { | ||
|
||
// delete the temp dir after the tests are run | ||
after(function (done) { rimraf('./temp', done); }); | ||
|
||
var app = express(); | ||
app.use(multer({ | ||
dest: './temp', | ||
rename: function (fieldname, filename) { | ||
return fieldname + filename; | ||
} | ||
})); | ||
app.post('/', function (req, res) { | ||
var form = { | ||
body: req.body, | ||
files: req.files | ||
} | ||
res.send(form); | ||
}); | ||
|
||
|
||
it('should upload the file to the `dest` dir', function (done) { | ||
request(app) | ||
.post('/') | ||
.type('form') | ||
.attach('small0', __dirname + '/files/small0.dat') | ||
.expect(200) | ||
.end(function (err, res) { | ||
var form = res.body; | ||
expect(err).to.be.null; | ||
expect(fs.existsSync('./temp/small0small0.dat')).to.equal(true); | ||
done(); | ||
}) | ||
}) | ||
|
||
|
||
it('should rename the uploaded file', function (done) { | ||
request(app) | ||
.post('/') | ||
.type('form') | ||
.attach('small0', __dirname + '/files/small0.dat') | ||
.expect(200) | ||
.end(function (err, res) { | ||
var form = res.body; | ||
expect(err).to.be.null; | ||
expect(form.files.small0.name).to.equal('small0small0.dat'); | ||
done(); | ||
}) | ||
}) | ||
|
||
|
||
}) |