Skip to content

Commit

Permalink
Merge pull request #9 from ruiquelhas/support/update-test-suite
Browse files Browse the repository at this point in the history
Update test suite to use stream payloads
  • Loading branch information
ruiquelhas committed Jul 8, 2016
2 parents 9c54690 + 6f744a8 commit 09d8bb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ server.connection({
const plugin = {
register: Burton,
options: {
// Allow png files only
whitelist: ['image/png']
// Allow png files only
whitelist: ['image/png']
}
};

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
},
"homepage": "https://github.com/ruiquelhas/burton#readme",
"devDependencies": {
"code": "2.x.x",
"code": "3.x.x",
"content": "3.x.x",
"coveralls": "2.x.x",
"form-data": "0.x.x",
"hapi": "13.x.x",
"lab": "10.x.x",
"stream-to-promise": "1.x.x"
"multi-part": "1.x.x"
},
"dependencies": {
"henning": "2.x.x",
Expand Down
31 changes: 12 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ const Path = require('path');

const Code = require('code');
const Content = require('content');
const FormData = require('form-data');
const Form = require('multi-part');
const Hapi = require('hapi');
const Lab = require('lab');
const StreamToPromise = require('stream-to-promise');

const Burton = require('../lib/');

Expand Down Expand Up @@ -81,17 +80,14 @@ lab.experiment('burton', () => {
const png = Path.join(Os.tmpdir(), 'foo.png');
Fs.createWriteStream(png).end(new Buffer('89504e47', 'hex'));

const form = new FormData();
const form = new Form();
form.append('file', Fs.createReadStream(png));

StreamToPromise(form).then((payload) => {
server.inject({ headers: { 'Content-Type': 'application/json' }, method: 'POST', payload: form.get(), url: '/main' }, (response) => {

server.inject({ headers: { 'Content-Type': 'application/json' }, method: 'POST', payload: payload, url: '/main' }, (response) => {

Code.expect(response.statusCode).to.equal(415);
Code.expect(response.headers['content-validation']).to.not.exist();
done();
});
Code.expect(response.statusCode).to.equal(415);
Code.expect(response.headers['content-validation']).to.not.exist();
done();
});
});

Expand All @@ -100,20 +96,17 @@ lab.experiment('burton', () => {
const png = Path.join(Os.tmpdir(), 'foo.png');
Fs.createWriteStream(png).end(new Buffer('89504e47', 'hex'));

const form = new FormData();
const form = new Form();
form.append('file1', Fs.createReadStream(png));
form.append('file2', Fs.createReadStream(png));
form.append('foo', 'bar');

StreamToPromise(form).then((payload) => {

server.inject({ headers: form.getHeaders(), method: 'POST', payload: payload, url: '/main' }, (response) => {
server.inject({ headers: form.getHeaders(), method: 'POST', payload: form.get(), url: '/main' }, (response) => {

Code.expect(response.statusCode).to.equal(200);
Code.expect(response.headers['content-validation']).to.equal('success');
Code.expect(Content.type(response.headers['content-type']).mime).to.equal('multipart/form-data');
done();
});
Code.expect(response.statusCode).to.equal(200);
Code.expect(response.headers['content-validation']).to.equal('success');
Code.expect(Content.type(response.headers['content-type']).mime).to.equal('multipart/form-data');
done();
});
});
});

0 comments on commit 09d8bb1

Please sign in to comment.