Created
August 11, 2016 10:57
-
-
Save vesse/44ad4a1d3fd3b9ea6580f8b6baf06f09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var chai = require('chai'), | |
should = chai.should(), | |
expect = chai.expect(), | |
assert = chai.assert, | |
supertest = require('supertest-as-promised'), | |
api = supertest('http://localhost:3000'); | |
describe('Pictures', function () { | |
it('should add a picture', function (done) { | |
api.post('/api/v1/pictures') | |
.set('Accept', 'application/json') | |
.attach('userPhoto', __dirname + '/import/user0.jpg') | |
.expect(200) | |
.then(function (response) { | |
done(); | |
}); | |
}); | |
}); |
This file contains hidden or 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
var express = require('express'), | |
path = require('path'), | |
logger = require('morgan'), | |
bodyParser = require('body-parser'), | |
app = express(), | |
methodOverride = require('method-override'), | |
multer = require('multer'), | |
upload = multer({ | |
dest: 'uploads/', | |
fileFilter: function(req,file,cb){ | |
cb(null,true); | |
} | |
}).single('userPhoto'); | |
app.use(logger('dev')); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended:false})); | |
app.use(methodOverride('X-HTTP-Method')); // Microsoft | |
app.use(methodOverride('X-HTTP-Method-Override')); // Google/GData | |
app.use(methodOverride('X-Method-Override')); | |
app.post('/api/v1/pictures', function(req, res) { | |
upload(req, res, function(err) { | |
if(err) { | |
console.log(err); | |
res.status(409).send('file not uploaded correctly'); | |
} | |
else { | |
res.end('File uploaded correctly'); | |
} | |
}); | |
}); | |
app.listen(3000); |
This file contains hidden or 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
{ | |
"dependencies": { | |
"body-parser": "^1.15.2", | |
"chai": "^3.5.0", | |
"express": "^4.14.0", | |
"method-override": "^2.3.6", | |
"mocha": "^3.0.2", | |
"morgan": "^1.7.0", | |
"multer": "^1.2.0", | |
"supertest": "^2.0.0", | |
"supertest-as-promised": "^3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment