<h2>Simple upload / POST</h2>
<form action="http://localhost:8000/api/upload/simple" method="post"
enctype="multipart/form-data">
Name: <input type="file" name="file" /> <br />
<input type="submit" value="Call" />
</form>
It is working as expected, but if I try to write test for that, it is not working.
server.route({
method: 'POST',
path: '/api/upload/simple',
config: {
validate : {
payload: {file: Joi.object().required()}
},
handler: function(request, reply) {
// Some upload functionality.
reply('Done').type('text/plain');
},
}
});
describe('simple upload', function() {
var server = Hapi.createServer(0);
before(function(done) {
routes.attachHandlers(server);
server.start(done);
});
it('successfull', function(done) {
var payload = {
file : fs.readFileSync('./test_file')
};
server.inject({url : '/api/upload/simple', method: 'post', payload : payload}, function(res) {
console.log(res);
//expect(res.statusCode).to.equal(200);
done();
});
});
});
{ statusCode: 400,
error: 'Bad Request',
message: 'the value of file must be an object',
validation: { source: 'payload', keys: [] } } }
How should I simulate the file field to be object? Right now the file is filled with an instance of Buffer.