Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Nov 28, 2024
1 parent 47fd42a commit 3e1e1ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe("workflow client", () => {
"upstash-retries": "15",
"upstash-workflow-init": "true",
"upstash-workflow-runid": `wfr_${myWorkflowRunId}`,
"upstash-workflow-url": "https://www.my-website.com/api",
"upstash-workflow-url": "https://requestcatcher.com/api",
},
},
});
Expand Down
21 changes: 12 additions & 9 deletions src/serve/serve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
WORKFLOW_INIT_HEADER,
WORKFLOW_PROTOCOL_VERSION_HEADER,
} from "../constants";
import { processOptions } from "./options";
import { AUTH_FAIL_MESSAGE, processOptions } from "./options";

const someWork = (input: string) => {
return `processed '${input}'`;
Expand Down Expand Up @@ -239,7 +239,8 @@ describe("serve", () => {
}
);

const request = getRequest(WORKFLOW_ENDPOINT, "wfr-foo", "my-payload", []);
const workflowRunId = "wfr-foo";
const request = getRequest(WORKFLOW_ENDPOINT, workflowRunId, "my-payload", []);
let called = false;
await mockQStashServer({
execute: async () => {
Expand All @@ -248,7 +249,7 @@ describe("serve", () => {
workflowRunId: string;
finishCondition: FinishCondition;
};
expect(workflowRunId).toBe("no-workflow-id");
expect(workflowRunId).toBe(workflowRunId);
expect(finishCondition).toBe("auth-fail");
called = true;
},
Expand Down Expand Up @@ -553,18 +554,16 @@ describe("serve", () => {
});

test("should receive env passed in options", async () => {
const request = new Request("http://endpoint.com", {
headers: {
[WORKFLOW_INIT_HEADER]: "false",
[WORKFLOW_ID_HEADER]: "wfr-id",
},
const request = new Request(WORKFLOW_ENDPOINT, {
headers: {},
});
let called = false;
const { handler: endpoint } = serve(
async (context) => {
expect(context.env["env-var-1"]).toBe("value-1");
expect(context.env["env-var-2"]).toBe("value-2");
called = true;
return;
},
{
qstashClient,
Expand All @@ -576,7 +575,11 @@ describe("serve", () => {
}
);
const response = await endpoint(request);
expect(response.status).toBe(200);
expect(response.status).toBe(400);
expect(await response.json()).toEqual({
message: AUTH_FAIL_MESSAGE,
workflowRunId: "no-workflow-id",
});
expect(called).toBeTrue();
});

Expand Down
2 changes: 1 addition & 1 deletion src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const MOCK_QSTASH_SERVER_PORT = 8080;
export const MOCK_QSTASH_SERVER_URL = `http://localhost:${MOCK_QSTASH_SERVER_PORT}`;

export const MOCK_SERVER_URL = "https://requestcatcher.com/";
export const WORKFLOW_ENDPOINT = "https://www.my-website.com/api";
export const WORKFLOW_ENDPOINT = "https://requestcatcher.com/api";

export type ResponseFields = {
body: unknown;
Expand Down
3 changes: 1 addition & 2 deletions src/workflow-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Workflow Requests", () => {
},
receivesRequest: {
method: "POST",
url: `${MOCK_QSTASH_SERVER_URL}/v2/publish/https://www.my-website.com/api`,
url: `${MOCK_QSTASH_SERVER_URL}/v2/publish/https://requestcatcher.com/api`,
token,
body: initialPayload,
headers: {
Expand Down Expand Up @@ -562,7 +562,6 @@ describe("Workflow Requests", () => {
});

await triggerFirstInvocation(context, 3);

const debug = new WorkflowLogger({ logLevel: "INFO", logOutput: "console" });
const spy = spyOn(debug, "log");

Expand Down

0 comments on commit 3e1e1ae

Please sign in to comment.