test: Add factory file for the step model

This commit is contained in:
Faruk AYDIN
2023-10-23 22:47:19 +02:00
parent 4cedbdbc60
commit d0fab0e1f1

View File

@@ -0,0 +1,21 @@
import Step from '../../src/models/step';
import { createFlow } from './flow';
export const createStep = async (params: Partial<Step> = {}) => {
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;
};