-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from zapier/non-required-label
fix(schema): Make label & description optional for hidden actions
- Loading branch information
Showing
7 changed files
with
153 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/schema/lib/functional-constraints/labelWhenVisible.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const _ = require('lodash'); | ||
const jsonschema = require('jsonschema'); | ||
|
||
const actionTypes = ['triggers', 'searches', 'creates']; | ||
|
||
const labelWhenVisible = definition => { | ||
const errors = []; | ||
|
||
for (const actionType of actionTypes) { | ||
const group = definition[actionType] || {}; | ||
_.each(group, (action, key) => { | ||
const { display } = action; | ||
if (!display.hidden && !(display.label && display.description)) { | ||
errors.push( | ||
new jsonschema.ValidationError( | ||
`visible actions must have a label and description`, | ||
action, | ||
`/BasicDisplaySchema`, | ||
`instance.${actionType}.${key}.display`, | ||
'invalid', | ||
'key' | ||
) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
module.exports = labelWhenVisible; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/schema/test/functional-constraints/labelWhenVisible.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const should = require('should'); | ||
const schema = require('../../schema'); | ||
|
||
describe('labelWhenVisible', () => { | ||
it('should not error when label is gone and action is hidden', () => { | ||
const definition = { | ||
version: '1.0.0', | ||
platformVersion: '1.0.0', | ||
creates: { | ||
foo: { | ||
key: 'foo', | ||
noun: 'Foo', | ||
display: { | ||
hidden: true | ||
}, | ||
operation: { | ||
perform: '$func$2$f$' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const results = schema.validateAppDefinition(definition); | ||
results.errors.should.have.length(0); | ||
}); | ||
|
||
it('should error when label is missing and action is visible ', () => { | ||
const definition = { | ||
version: '1.0.0', | ||
platformVersion: '1.0.0', | ||
creates: { | ||
foo: { | ||
key: 'foo', | ||
noun: 'Foo', | ||
display: { | ||
hidden: false | ||
}, | ||
operation: { | ||
perform: '$func$2$f$' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const results = schema.validateAppDefinition(definition); | ||
results.errors.should.have.length(1); | ||
const err = results.errors[0]; | ||
should(err.codeLinks[0].includes('BasicDisplaySchema')).be.true(); | ||
err.property.should.eql('instance.creates.foo.display'); | ||
}); | ||
|
||
it('should error when label is alone when create is visible ', () => { | ||
const definition = { | ||
version: '1.0.0', | ||
platformVersion: '1.0.0', | ||
creates: { | ||
foo: { | ||
key: 'foo', | ||
noun: 'Foo', | ||
display: { | ||
label: 'nea' | ||
}, | ||
operation: { | ||
perform: '$func$2$f$' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const results = schema.validateAppDefinition(definition); | ||
results.errors.should.have.length(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters