From 98b296ca0ce74ecda589869faf978391192cdf40 Mon Sep 17 00:00:00 2001 From: Mendes Hugo Date: Wed, 8 Nov 2023 17:55:52 +0100 Subject: [PATCH 1/2] test(workflow/trigger): add test to accept the activation of workflows with a trigger reference --- .../src/app/workflow/workflow.service.spec.ts | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/app/workflow/workflow.service.spec.ts b/apps/backend/src/app/workflow/workflow.service.spec.ts index 59c1841f..5a1ed1ad 100644 --- a/apps/backend/src/app/workflow/workflow.service.spec.ts +++ b/apps/backend/src/app/workflow/workflow.service.spec.ts @@ -1,5 +1,8 @@ import { NotFoundError, UniqueConstraintViolationException } from "@mikro-orm/core"; import { Test, TestingModule } from "@nestjs/testing"; +import { NodeBehaviorType } from "~/lib/common/app/node/dtos/behaviors/node-behavior.type"; +import { NodeTriggerType } from "~/lib/common/app/node/dtos/behaviors/triggers"; +import { NodeKindType } from "~/lib/common/app/node/dtos/kind/node-kind.type"; import { WorkflowCreateDto, WorkflowUpdateDto } from "~/lib/common/app/workflow/dtos"; import { BASE_SEED } from "~/lib/common/seeds"; @@ -9,10 +12,12 @@ import { WorkflowService } from "./workflow.service"; import { DbTestHelper } from "../../../test/db-test"; import { OrmModule } from "../../orm/orm.module"; import { GraphService } from "../graph/graph.service"; +import { NodeService } from "../node/node.service"; describe("WorkflowService", () => { let dbTest: DbTestHelper; let graphService: GraphService; + let nodeService: NodeService; let service: WorkflowService; let db: typeof BASE_SEED; @@ -24,8 +29,9 @@ describe("WorkflowService", () => { dbTest = new DbTestHelper(module); db = dbTest.db as never; - service = module.get(WorkflowService); + service = module.get(WorkflowService); graphService = module.get(GraphService); + nodeService = module.get(NodeService); }); afterAll(() => dbTest.close()); @@ -35,7 +41,7 @@ describe("WorkflowService", () => { }); describe("Activation", () => { - beforeAll(() => dbTest.refresh()); + beforeEach(() => dbTest.refresh()); it("should activate a workflow", async () => { const [{ _id }] = db.workflows; @@ -48,6 +54,25 @@ describe("WorkflowService", () => { WorkflowNoTriggerException ); }); + + it("should activate a workflow with a node-reference to a trigger", async () => { + const [, { __graph, _id }] = db.workflows; + const base = await nodeService.create({ + behavior: { + trigger: { cron: "* * * 0 12", type: NodeTriggerType.CRON }, + type: NodeBehaviorType.TRIGGER + }, + kind: { active: true, type: NodeKindType.TEMPLATE }, + name: "trigger00" + }); + + await nodeService.create({ + behavior: { __node: base._id, type: NodeBehaviorType.REFERENCE }, + kind: { __graph, position: { x: 0, y: 0 }, type: NodeKindType.VERTEX }, + name: "ref" + }); + await expect(service.update(_id, { active: true })).resolves.toBeDefined(); + }); }); describe("With Graph", () => { From 1f2218ea77a3acbf2a085673266bd523a95a86e6 Mon Sep 17 00:00:00 2001 From: Mendes Hugo Date: Wed, 24 Jan 2024 23:04:14 +0100 Subject: [PATCH 2/2] chore: lint --- .../src/app/workflow/workflow.service.spec.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/backend/src/app/workflow/workflow.service.spec.ts b/apps/backend/src/app/workflow/workflow.service.spec.ts index 2536d561..db4f65ae 100644 --- a/apps/backend/src/app/workflow/workflow.service.spec.ts +++ b/apps/backend/src/app/workflow/workflow.service.spec.ts @@ -6,7 +6,10 @@ import { Test, TestingModule } from "@nestjs/testing"; import { NodeBehaviorType } from "~/lib/common/app/node/dtos/behaviors/node-behavior.type"; import { NodeTriggerType } from "~/lib/common/app/node/dtos/behaviors/triggers"; import { NodeKindType } from "~/lib/common/app/node/dtos/kind/node-kind.type"; -import { WorkflowCreateDto, WorkflowUpdateDto } from "~/lib/common/app/workflow/dtos"; +import { + WorkflowCreateDto, + WorkflowUpdateDto +} from "~/lib/common/app/workflow/dtos"; import { BASE_SEED } from "~/lib/common/seeds"; import { WorkflowNoTriggerException } from "./exceptions"; @@ -72,11 +75,20 @@ describe("WorkflowService", () => { }); await nodeService.create({ - behavior: { __node: base._id, type: NodeBehaviorType.REFERENCE }, - kind: { __graph, position: { x: 0, y: 0 }, type: NodeKindType.VERTEX }, + behavior: { + __node: base._id, + type: NodeBehaviorType.REFERENCE + }, + kind: { + __graph, + position: { x: 0, y: 0 }, + type: NodeKindType.VERTEX + }, name: "ref" }); - await expect(service.update(_id, { active: true })).resolves.toBeDefined(); + await expect( + service.update(_id, { active: true }) + ).resolves.toBeDefined(); }); });