-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(schema): Make label & description optional for hidden actions #69
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
`/${_.capitalize(actionType)}Schema`, | ||
`instance.${key}.key`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, I think the path should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. went with |
||
'invalid', | ||
'key' | ||
) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
module.exports = labelWhenVisible; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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); | ||
}); | ||
|
||
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we link to
BasicDisplaySchema
instead?