From 31f2cddc91ddda8a4a7a8b0819bdaa8007295e25 Mon Sep 17 00:00:00 2001 From: mytharcher Date: Sat, 22 Apr 2023 23:27:19 +0800 Subject: [PATCH] test(plugin-workflow): add test case --- .../__tests__/instructions/manual.test.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/plugins/workflow/src/server/__tests__/instructions/manual.test.ts b/packages/plugins/workflow/src/server/__tests__/instructions/manual.test.ts index e07b569035..6c61deafaf 100644 --- a/packages/plugins/workflow/src/server/__tests__/instructions/manual.test.ts +++ b/packages/plugins/workflow/src/server/__tests__/instructions/manual.test.ts @@ -670,6 +670,52 @@ describe('workflow > instructions > manual', () => { }); describe('update', () => { + it('update as configured', async () => { + const n1 = await workflow.createNode({ + type: 'manual', + config: { + assignees: [users[0].id], + forms: { + f1: { + type: 'update', + actions: [JOB_STATUS.RESOLVED], + collection: 'posts', + } + } + } + }); + + const post = await PostRepo.create({ values: { title: 't1' } }); + + await sleep(500); + + const UserJobModel = db.getModel('users_jobs'); + const pendingJobs = await UserJobModel.findAll({ + order: [[ 'userId', 'ASC' ]] + }); + expect(pendingJobs.length).toBe(1); + + const res1 = await userAgents[0].resource('users_jobs').submit({ + filterByTk: pendingJobs[0].get('id'), + values: { + status: JOB_STATUS.RESOLVED, + result: { f1: { title: 't2' } } + } + }); + expect(res1.status).toBe(202); + + await sleep(1000); + + const [e2] = await workflow.getExecutions(); + expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED); + const [j1] = await e2.getJobs(); + expect(j1.status).toBe(JOB_STATUS.RESOLVED); + expect(j1.result).toMatchObject({ f1: { title: 't2' } }); + + const postsAfter = await PostRepo.find(); + expect(postsAfter.length).toBe(1); + expect(postsAfter[0]).toMatchObject({ title: 't2' }); + }); }); }); });