Skip to content

Commit

Permalink
Test renamed, fixed !Array throwing error
Browse files Browse the repository at this point in the history
  • Loading branch information
villamide committed Oct 13, 2017
1 parent 67927e4 commit 15568e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 1 addition & 4 deletions filter/matched-data.js
Expand Up @@ -4,9 +4,6 @@ const selectFields = require('../check/select-fields');
module.exports = (req, options = {}) => {
let onlyValidData = options.onlyValidData === undefined ? true : options.onlyValidData
let customLocations = options.locations === undefined ? false : options.locations
if (customLocations && !Array.isArray(customLocations)) {
throw new Error('returnLocations must be an Array')
}

const validityFilter = !onlyValidData ? () => true : field => {
return !req._validationErrors.find(error =>
Expand All @@ -15,7 +12,7 @@ module.exports = (req, options = {}) => {
);
};

const locationsFilter = !customLocations ? () => true : v => {
const locationsFilter = !customLocations || customLocations.length === 0 ? () => true : v => {
return customLocations.indexOf(v.location) !== -1
}

Expand Down
22 changes: 21 additions & 1 deletion filter/matched-data.spec.js
Expand Up @@ -98,7 +98,7 @@ describe('filter: matchedData', () => {
});
});

it('returns object with the specified location in the array', () => {
it('returns object with the specified locations in the array', () => {
const req = {
query: { foo: '123', bar: 'abc' },
body: { baz: '234' }
Expand All @@ -117,5 +117,25 @@ describe('filter: matchedData', () => {
});
});
});

it('returns object all the specified locations if not specified', () => {
const req = {
query: { foo: '123', bar: 'abc' },
body: { baz: '234' }
};

return check(['foo', 'bar', 'baz']).isInt()(req, {}, () => {}).then(() => {
const data = matchedData(req, {
onlyValidData: false,
locations: []
});

expect(data).to.eql({
foo: '123',
bar: 'abc',
baz: '234'
});
});
});
});
});

0 comments on commit 15568e9

Please sign in to comment.