124 lines
4.0 KiB
TypeScript
124 lines
4.0 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { createLocalAuthContext } from "../src/modules/auth/auth.controller.ts";
|
|
import { createWorkspaceModule } from "../src/modules/workspaces/workspaces.module.ts";
|
|
import { createProjectsModule } from "../src/modules/projects/projects.module.ts";
|
|
import { createWorkflowsModule } from "../src/modules/workflows/workflows.module.ts";
|
|
import { createRunsModule } from "../src/modules/runs/runs.module.ts";
|
|
|
|
test("create workflow definition", () => {
|
|
const auth = createLocalAuthContext("user-7");
|
|
const workspaces = createWorkspaceModule();
|
|
const projects = createProjectsModule(workspaces.service);
|
|
const workflows = createWorkflowsModule();
|
|
|
|
const workspace = workspaces.controller.bootstrapPersonalWorkspace(auth);
|
|
const project = projects.controller.createProject(auth, {
|
|
workspaceId: workspace.id,
|
|
name: "Workflow",
|
|
slug: "workflow",
|
|
description: "Workflow project",
|
|
});
|
|
|
|
const definition = workflows.controller.createWorkflowDefinition(auth, {
|
|
workspaceId: workspace.id,
|
|
projectId: project.id,
|
|
name: "Delivery Flow",
|
|
slug: "delivery-flow",
|
|
});
|
|
|
|
assert.equal(definition.name, "Delivery Flow");
|
|
assert.equal(definition.status, "draft");
|
|
});
|
|
|
|
test("save workflow version", () => {
|
|
const auth = createLocalAuthContext("user-8");
|
|
const workspaces = createWorkspaceModule();
|
|
const projects = createProjectsModule(workspaces.service);
|
|
const workflows = createWorkflowsModule();
|
|
|
|
const workspace = workspaces.controller.bootstrapPersonalWorkspace(auth);
|
|
const project = projects.controller.createProject(auth, {
|
|
workspaceId: workspace.id,
|
|
name: "Versions",
|
|
slug: "versions",
|
|
description: "Workflow version project",
|
|
});
|
|
const definition = workflows.controller.createWorkflowDefinition(auth, {
|
|
workspaceId: workspace.id,
|
|
projectId: project.id,
|
|
name: "Versioned Flow",
|
|
slug: "versioned-flow",
|
|
});
|
|
|
|
const version = workflows.controller.saveWorkflowVersion(auth, {
|
|
workflowDefinitionId: definition.id,
|
|
visualGraph: { nodes: [], edges: [] },
|
|
logicGraph: {
|
|
nodes: [
|
|
{ id: "source", type: "Source" },
|
|
{ id: "validate", type: "Inspect" },
|
|
],
|
|
edges: [{ from: "source", to: "validate" }],
|
|
},
|
|
runtimeGraph: { nodes: [] },
|
|
pluginRefs: [],
|
|
});
|
|
|
|
assert.equal(version.versionNumber, 1);
|
|
assert.equal(version.workflowDefinitionId, definition.id);
|
|
});
|
|
|
|
test("create workflow run from saved version and derive initial run tasks", () => {
|
|
const auth = createLocalAuthContext("user-9");
|
|
const workspaces = createWorkspaceModule();
|
|
const projects = createProjectsModule(workspaces.service);
|
|
const workflows = createWorkflowsModule();
|
|
const runs = createRunsModule(workflows.service);
|
|
|
|
const workspace = workspaces.controller.bootstrapPersonalWorkspace(auth);
|
|
const project = projects.controller.createProject(auth, {
|
|
workspaceId: workspace.id,
|
|
name: "Runs",
|
|
slug: "runs",
|
|
description: "Run project",
|
|
});
|
|
const definition = workflows.controller.createWorkflowDefinition(auth, {
|
|
workspaceId: workspace.id,
|
|
projectId: project.id,
|
|
name: "Run Flow",
|
|
slug: "run-flow",
|
|
});
|
|
const version = workflows.controller.saveWorkflowVersion(auth, {
|
|
workflowDefinitionId: definition.id,
|
|
visualGraph: { nodes: [], edges: [] },
|
|
logicGraph: {
|
|
nodes: [
|
|
{ id: "source", type: "Source" },
|
|
{ id: "rename", type: "Transform" },
|
|
{ id: "export", type: "Export" },
|
|
],
|
|
edges: [
|
|
{ from: "source", to: "rename" },
|
|
{ from: "rename", to: "export" },
|
|
],
|
|
},
|
|
runtimeGraph: { nodes: [] },
|
|
pluginRefs: [],
|
|
});
|
|
|
|
const run = runs.controller.createWorkflowRun(auth, {
|
|
workflowDefinitionId: definition.id,
|
|
workflowVersionId: version.id,
|
|
});
|
|
|
|
const tasks = runs.controller.listRunTasks(run.id);
|
|
|
|
assert.equal(run.status, "queued");
|
|
assert.equal(tasks.length, 3);
|
|
assert.equal(tasks[0].nodeId, "source");
|
|
assert.equal(tasks[0].status, "queued");
|
|
assert.equal(tasks[1].status, "pending");
|
|
});
|