I'm doing the unit-testing
with lab
for a service in hapijs
. The service basically asks for a file:
server.route({
method: 'POST',
path: '/file',
config: {
payload:{
output:'stream',
parse: true,
allow: 'multipart/form-data'
}
},
handler: function(request, reply){
reply({ message: 'File saved' });
}
});
Being your unit-test
:
var request = {
method: 'POST',
url: '/file',
payload: {
file: {
value: fs.createReadStream('input.csv')
}
}
};
lab.test('it return the default message to file index', (done) => {
server.inject(request, (response) => {
Code.expect(response.result.message).to.match(/File saved/);
Code.expect(response.statusCode).to.equal(200);
done();
});
});
The fact is that when I run the unit testing returns { statusCode: 415, error: 'Unsupported Media Type' }
. So I think I should indicate the content-type in headers but I'm not sure what values are needed and where they should go.