Skip to content

Commit

Permalink
Only map data for find method (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Aug 29, 2018
1 parent f74207f commit a7261d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/authentication-local/lib/hooks/protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function (...fields) {

if (Array.isArray(result)) {
context.dispatch = result.map(o);
} else if (result.data) {
} else if (result.data && context.method === 'find') {
context.dispatch = Object.assign({}, result, {
data: result.data.map(o)
});
Expand Down
19 changes: 19 additions & 0 deletions packages/authentication-local/test/hooks/protect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ function testOmit (title, property) {
});
});

it('handles `data` property only for find', () => {
const data = {
email: '[email protected]',
password: 'supersecret',
data: 'yes'
};
const context = {
[property]: data
};
const result = fn(context);

expect(result).to.deep.equal({
[property]: data,
dispatch: { email: '[email protected]', data: 'yes' }
});
});

it('omits from array', () => {
const data = [{
email: '[email protected]',
Expand Down Expand Up @@ -58,11 +75,13 @@ function testOmit (title, property) {
}]
};
const context = {
method: 'find',
[property]: data
};
const result = fn(context);

expect(result).to.deep.equal({
method: 'find',
[property]: data,
dispatch: {
total: 2,
Expand Down

0 comments on commit a7261d5

Please sign in to comment.