From 4a99d5eab7d0dac55138fab8c64b669c5e4a7a26 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 20 Mar 2024 02:03:31 +0100 Subject: [PATCH] fix: Adjust step factory to use objection instead of knex --- .../backend/src/graphql/queries/get-flow.test.js | 4 ++-- packages/backend/test/factories/step.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/graphql/queries/get-flow.test.js b/packages/backend/src/graphql/queries/get-flow.test.js index ccdb0c73..5a5f106f 100644 --- a/packages/backend/src/graphql/queries/get-flow.test.js +++ b/packages/backend/src/graphql/queries/get-flow.test.js @@ -136,7 +136,7 @@ describe('graphQL getFlow query', () => { id: actionStep.id, key: 'translateText', parameters: {}, - position: 1, + position: 2, status: actionStep.status, type: 'action', webhookUrl: 'http://localhost:3000/null', @@ -223,7 +223,7 @@ describe('graphQL getFlow query', () => { id: actionStep.id, key: 'translateText', parameters: {}, - position: 1, + position: 2, status: actionStep.status, type: 'action', webhookUrl: 'http://localhost:3000/null', diff --git a/packages/backend/test/factories/step.js b/packages/backend/test/factories/step.js index fd230764..52a878dd 100644 --- a/packages/backend/test/factories/step.js +++ b/packages/backend/test/factories/step.js @@ -5,19 +5,21 @@ export const createStep = async (params = {}) => { 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') + const lastStep = await Step.query() + .where('flow_id', params.flowId) + .andWhere('deleted_at', null) + .orderBy('position', 'desc') + .limit(1) .first(); - params.position = params?.position || (lastStep?.position || 0) + 1; + params.position = + params?.position || (lastStep?.position ? lastStep.position + 1 : 1); + params.status = params?.status || 'completed'; params.appKey = params?.appKey || (params.type === 'action' ? 'deepl' : 'webhook'); - const step = await Step.query().insert(params).returning('*'); + const step = await Step.query().insertAndFetch(params); return step; };