Skip to content

Commit

Permalink
Adding meta support to hapi decorator, fix typo, add test (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbrett authored Mar 4, 2020
1 parent 541cc54 commit 83cf5ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ module.exports.hapi = {
return;
}

const calibrateDeocorator = function (data) {
const calibrateDecorator = function (data, meta) {

return internals.calibrate(data);
return internals.calibrate(data, meta);
};

server.decorate('toolkit', 'calibrate', calibrateDeocorator);
server.decorate('toolkit', 'calibrate', calibrateDecorator);
}
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ const validOutput = JSON.stringify({
},
meta: {}
});
const validOutputWithMeta = JSON.stringify({
statusCode: 200,
data: {
'message': 'test'
},
meta: {
'count': 50
}
});

describe('Calibrate', () => {

Expand Down Expand Up @@ -128,6 +137,31 @@ describe('Calibrate', () => {
expect(res.payload).to.equal(validOutput);
});

it('response using hapi decorator includes meta', async () => {

const server = new Hapi.Server();

await server.register({
plugin: Calibrate.hapi,
options: { onResponse: false }
});

server.route({
method: 'GET',
path: '/',
config: {
handler: function (request, h) {

return h.calibrate({ message: 'test' }, { count: 50 });
}
}
});

const res = await server.inject({ method: 'GET', url: '/' });

expect(res.payload).to.equal(validOutputWithMeta);
});

it('adds default calibrate wrapper to response', async () => {

const server = new Hapi.Server();
Expand Down

0 comments on commit 83cf5ef

Please sign in to comment.