Skip to content

Commit

Permalink
feat: validate lower case scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Moreau committed Jul 31, 2023
1 parent c4a82b4 commit 98b09d6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export const actionSchema = {
type: 'object',
properties: {
generateFile: { type: 'boolean' },
scope: { type: 'string', enum: Object.values(ActionScopeEnum) },
scope: {
type: 'string',
enum: [
...Object.values(ActionScopeEnum),
...Object.values(ActionScopeEnum).map(scope => scope.toLowerCase()),
],
},
form: { type: 'array' }, // validated in fieldActionSchema
execute: { typeof: 'function' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,34 @@ describe('ActionValidator', () => {
describe('validateActionConfiguration', () => {
test('it should validate an action without form', () => {
const action: ActionDefinition = {
scope: 'Global',
execute: () => {},
scope: 'Single',
form: [
{
label: 'PDF',
description: 'DJHBD',
type: 'File',
},
{
label: 'Amount',
description: 'The amount (USD) to charge the credit card. Example: 42.50',
type: 'Number',
},
{
label: 'description',
description: 'Explain the reason why you want to charge manually the customer here',
isRequired: true,
type: 'String',
if: context => Number(context.formValues.Amount) > 4,
},
{
label: 'stripe_id',
type: 'String',
if: () => false,
},
],
execute: async (context, resultBuilder) => {
return resultBuilder.success(`Well well done ${context.caller.email}!`);
},
};
expect(() => ActionValidator.validateActionConfiguration('TheName', action)).not.toThrow();
});
Expand Down Expand Up @@ -37,6 +63,21 @@ describe('ActionValidator', () => {
expect(() => ActionValidator.validateActionConfiguration('TheName', action)).not.toThrow();
});

test('it should validate an action with lower case scope', () => {
const action = {
scope: 'single',
execute: async (context, resultBuilder) => {
return resultBuilder.success(`Well well done !`);
},
};
expect(() =>
ActionValidator.validateActionConfiguration(
'TheName',
action as unknown as ActionDefinition,
),
).not.toThrow();
});

describe('documentation samples', () => {
test('it should validate the action at https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions#in-your-code', () => {
const action: ActionDefinition = {
Expand Down Expand Up @@ -271,7 +312,7 @@ describe('ActionValidator', () => {
'TheName',
action as unknown as ActionDefinition,
),
).toThrow('scope must be equal to one of the allowed values ,(Single,Bulk,Global)');
).toThrow('scope must be equal to one of the allowed values ,(Single,Bulk,Global');
});
test('it should reject an action with added unknown field', () => {
const action = {
Expand Down

0 comments on commit 98b09d6

Please sign in to comment.