I'm adding integration tests to a legacy code-base prior to refactoring. For this case, uploading a file.
The Test:
it('uploads a photo at the specified index', done => {
chai.request(server.instance)
.post('/profile/photo/0')
.set('Access-Token', `${token}`)
.set('API-Key', testConfig.apiKey)
.field({contentId: 'foobar'})
.attach('file', fs.readFileSync(__dirname + '/logo.png'), 'file')
.end((err, res) => {
console.log(JSON.stringify(res.body))
res.should.have.status(200)
done()
})
})
The endpoint being tested works ok in production. But to get the test to pass, I have to comment out the following lines in make-middleware.js of the multer module:
if (!includeFile) {
// appender.removePlaceholder(placeholder)
// return fileStream.resume()
}
Being inexperienced with node, I must've missed some configuration or something. How can I make my test pass (without modifying an external module's code)?