Skip to content

Commit

Permalink
fix: add test for context.cancel inside context.run
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Dec 19, 2024
1 parent 3363e87 commit 6d0cab6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/workflow-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,39 @@ describe("Workflow Requests", () => {
expect(result.value).toBe("workflow-finished");
});

test("should call onCancel if context.cancel is called inside context.run", async () => {
const workflowRunId = nanoid();
const token = "myToken";

const context = new WorkflowContext({
qstashClient: new Client({ baseUrl: MOCK_SERVER_URL, token }),
workflowRunId: workflowRunId,
initialPayload: undefined,
headers: new Headers({}) as Headers,
steps: [],
url: WORKFLOW_ENDPOINT,
});

const finished = new FinishState();
const result = await triggerRouteFunction({
onStep: async () => {
await context.run("should call cancel", async () => {
await context.cancel();
});
},
onCleanup: async () => {
throw new Error("shouldn't call");
},
onCancel: async () => {
finished.finish();
},
});
finished.check();
expect(result.isOk()).toBeTrue();
// @ts-expect-error value will be set since result isOk
expect(result.value).toBe("workflow-finished");
});

test("should call publishJSON in triggerWorkflowDelete", async () => {
const workflowRunId = nanoid();
const token = "myToken";
Expand Down

0 comments on commit 6d0cab6

Please sign in to comment.