chore: Add step validation to import step API endpoint
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import { renderObject } from '../../../../helpers/renderer.js';
|
||||
import importFlow from '../../../../helpers/import-flow.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const flow = await importFlow(request.currentUser, flowParams(request));
|
||||
export default async function importFlowController(request, response) {
|
||||
const flow = await importFlow(
|
||||
request.currentUser,
|
||||
flowParams(request),
|
||||
response
|
||||
);
|
||||
|
||||
return renderObject(response, flow, { status: 201 });
|
||||
};
|
||||
}
|
||||
|
||||
const flowParams = (request) => {
|
||||
return {
|
||||
|
||||
@@ -325,4 +325,31 @@ describe('POST /api/v1/flows/import', () => {
|
||||
`{{step.${newTriggerStepId}.query.sample}}`
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error in case there is no trigger step', async () => {
|
||||
const currentUserFlow = await createFlow({ userId: currentUser.id });
|
||||
|
||||
await createPermission({
|
||||
action: 'create',
|
||||
subject: 'Flow',
|
||||
roleId: currentUserRole.id,
|
||||
conditions: ['isCreator'],
|
||||
});
|
||||
|
||||
const importFlowData = {
|
||||
id: currentUserFlow.id,
|
||||
name: currentUserFlow.name,
|
||||
steps: [],
|
||||
};
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/v1/flows/import')
|
||||
.set('Authorization', token)
|
||||
.send(importFlowData)
|
||||
.expect(422);
|
||||
|
||||
expect(response.body.errors.steps).toStrictEqual([
|
||||
'The first step must be a trigger!',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user