-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: validate actions configuration definition #782
base: main
Are you sure you want to change the base?
Conversation
packages/datasource-customizer/src/decorators/actions/collection.ts
Outdated
Show resolved
Hide resolved
packages/datasource-customizer/src/decorators/validation/action.ts
Outdated
Show resolved
Hide resolved
packages/datasource-customizer/src/decorators/validation/action.ts
Outdated
Show resolved
Hide resolved
}); | ||
|
||
describe('documentation samples', () => { | ||
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions#in-your-code', () => { |
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.
What if the documentation link change?
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.
Yes, this is not the best.
But I thought that validating our own doc was important, so I took the risk. Do you have another idea ?
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.
I think you can keep you links as comments of each test and specifically define what you are testing as I tried to do (it is not so simple) ^^
field: { label: 'field1', type: 'string' } as unknown as DynamicField, | ||
error: `type must be equal to one of the allowed values ,(Boolean,Collection`, | ||
}, | ||
].forEach(wrongField => { |
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.
💪
packages/datasource-customizer/src/decorators/validation/action.ts
Outdated
Show resolved
Hide resolved
export type ActionScope = `${ActionScopeEnum}`; | ||
|
||
export enum ActionScopeEnum { | ||
Single = 'Single', | ||
Bulk = 'Bulk', | ||
Global = 'Global', | ||
} |
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.
👌
export type ActionFieldType = `${ActionFieldTypeEnum}`; | ||
export enum ActionFieldTypeEnum { | ||
Boolean = 'Boolean', | ||
Collection = 'Collection', | ||
Enum = 'Enum', | ||
EnumList = 'EnumList', | ||
File = 'File', | ||
FileList = 'FileList', | ||
Json = 'Json', | ||
Number = 'Number', | ||
NumberList = 'NumberList', | ||
Date = 'Date', | ||
Dateonly = 'Dateonly', | ||
String = 'String', | ||
StringList = 'StringList', | ||
} |
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.
👌
You should probably change the |
What about old widget definition?
|
It will be updated in another PR |
@@ -124,6 +129,14 @@ export default class CollectionCustomizer< | |||
* }) | |||
*/ | |||
addAction(name: string, definition: ActionDefinition<S, N>): this { | |||
try { | |||
ActionValidator.validateActionConfiguration(name, definition as ActionDefinition<any, any>); |
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.
ActionValidator.validateActionConfiguration(name, definition as ActionDefinition<any, any>); | |
ActionValidator.validateActionConfiguration(name, definition as unknown as ActionDefinition); |
The linter is not happy with this. 😢
}); | ||
|
||
describe('documentation samples', () => { | ||
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions#in-your-code', () => { |
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.
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions#in-your-code', () => { | |
test('it should validate the action - smallest required properties defined', () => { |
ActionValidator.validateActionConfiguration('Mark as live', action), | ||
).not.toThrow(); | ||
}); | ||
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/scope-context#example-1-getting-data-from-the-selected-records', () => { |
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.
This is the same case as the previous definition.
ActionValidator.validateActionConfiguration('Mark as live', action), | ||
).not.toThrow(); | ||
}); | ||
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/forms-static#field-configuration', () => { |
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.
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/forms-static#field-configuration', () => { | |
test('it should validate the action - Static form definition', () => { |
ActionValidator.validateActionConfiguration('Mark as live', action), | ||
).not.toThrow(); | ||
}); | ||
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/forms-static#references-to-records', () => { |
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.
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/forms-static#references-to-records', () => { | |
test('it should validate the action - - Static form definition with field reference to records', () => { |
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.
I have implemented your suggestion
try { | ||
ActionValidator.validateActionConfiguration(name, definition as ActionDefinition<any, any>); | ||
} catch (error) { | ||
if (error instanceof ActionConfigurationValidationError) { |
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.
👌
Definition of Done
General
Security