Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions apps/backend/src/app/workflow/workflow.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
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
Expand All @@ -15,10 +18,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;
Expand All @@ -30,8 +35,9 @@ describe("WorkflowService", () => {

dbTest = new DbTestHelper(module);
db = dbTest.db as never;
service = module.get<WorkflowService>(WorkflowService);
service = module.get(WorkflowService);
graphService = module.get(GraphService);
nodeService = module.get(NodeService);
});

afterAll(() => dbTest.close());
Expand All @@ -41,7 +47,7 @@ describe("WorkflowService", () => {
});

describe("Activation", () => {
beforeAll(() => dbTest.refresh());
beforeEach(() => dbTest.refresh());

it("should activate a workflow", async () => {
const [{ _id }] = db.workflows;
Expand All @@ -56,6 +62,34 @@ 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", () => {
Expand Down