Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #43 from zapier/feature-improve-id-checks
Browse files Browse the repository at this point in the history
Improving ID checks
  • Loading branch information
Bruno Bernardino authored Jul 18, 2017
2 parents d3d467f + 9f41a4f commit b4673ec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app-middlewares/after/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const checkOutput = (output) => {
if (runChecks) {
const rawResults = checks
.filter((check) => {
return check.shouldRun(event.method);
return check.shouldRun(event.method, event.bundle);
})
.map((check) => {
return check.run(event.method, output.results)
Expand Down
2 changes: 1 addition & 1 deletion src/checks/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
const exampleChecker = {
name: 'exampleChecker',
shouldRun: (method) => {
shouldRun: (method/*, bundle*/) => {
return method && true;
},
run: (method, results) => {
Expand Down
7 changes: 5 additions & 2 deletions src/checks/trigger-has-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ const isTrigger = require('./is-trigger');
*/
const triggerHasId = {
name: 'triggerHasId',
shouldRun: isTrigger,
shouldRun: (method, bundle) => {
// Hooks will have a bundle.cleanedRequest and we don't need to check they've got an id
return (isTrigger(method) && !bundle.cleanedRequest);
},
run: (method, results) => {
const missingIdResult = _.find(results, (result) => {
return _.isUndefined(result.id) || _.isNull(result.id);
return !result || _.isUndefined(result.id) || _.isNull(result.id);
});

if (missingIdResult) {
Expand Down
3 changes: 3 additions & 0 deletions test/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ describe('checks', () => {
checks.triggerHasId.run(testMethod, [{id: 1}, {id: 2}]).length.should.eql(0);
checks.triggerHasId.run(testMethod, [{game_id: 1}]).length.should.eql(1);
checks.triggerHasId.run(testMethod, []).length.should.eql(0, 'blank array');
checks.triggerHasId.run(testMethod, [1]).length.should.eql(1);
checks.triggerHasId.run(testMethod, [{id: null}]).length.should.eql(1);
checks.triggerHasId.run(testMethod, [{}]).length.should.eql(1);
});

it('should check for unique ids via triggerHasUniqueIds', () => {
Expand Down

0 comments on commit b4673ec

Please sign in to comment.