diff --git a/packages/backend/test/factories/step.ts b/packages/backend/test/factories/step.ts new file mode 100644 index 00000000..560808dd --- /dev/null +++ b/packages/backend/test/factories/step.ts @@ -0,0 +1,21 @@ +import Step from '../../src/models/step'; +import { createFlow } from './flow'; + +export const createStep = async (params: Partial = {}) => { + params.flowId = params?.flowId || (await createFlow()).id; + params.type = params?.type || 'action'; + + const [lastStep] = await global.knex + .table('steps') + .where('flowId', params.flowId) + .andWhere('deletedAt', '!=', null) + .orderBy('createdAt', 'desc') + .first(); + + params.position = params?.position || (lastStep?.position || 0) + 1; + params.status = params?.status || 'incomplete'; + + const [step] = await global.knex.table('steps').insert(params).returning('*'); + + return step; +};