From 553a9f7005365420131e11bcae5a11741f33a429 Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:00:15 +0000 Subject: [PATCH 1/5] Fix test to properly mimic event API responses during errors --- packages/inngest/src/components/Inngest.test.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/inngest/src/components/Inngest.test.ts b/packages/inngest/src/components/Inngest.test.ts index 8097bd5bd..032982ca7 100644 --- a/packages/inngest/src/components/Inngest.test.ts +++ b/packages/inngest/src/components/Inngest.test.ts @@ -141,13 +141,16 @@ describe("send", () => { error, }: Partial = {}) => { return jest.fn((url: string, opts: { body: string }) => { - const json = { - status, - ids: - ids ?? - (JSON.parse(opts.body) as EventPayload[]).map(() => "test-id"), - error, - }; + const json = error + ? { + error, + } + : { + status, + ids: + ids ?? + (JSON.parse(opts.body) as EventPayload[]).map(() => "test-id"), + }; return Promise.resolve({ status, From d822982195bc89714c7f8e868e4559271993de49 Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:01:06 +0000 Subject: [PATCH 2/5] Fix parsing throwing when dealing with event API errors --- packages/inngest/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/inngest/src/types.ts b/packages/inngest/src/types.ts index 47bca9b3f..272080991 100644 --- a/packages/inngest/src/types.ts +++ b/packages/inngest/src/types.ts @@ -493,12 +493,12 @@ export const sendEventResponseSchema = z.object({ /** * Event IDs */ - ids: z.array(z.string()), + ids: z.array(z.string()).default([]), /** * HTTP Status Code. Will be undefined if no request was sent. */ - status: z.number(), + status: z.number().default(0), /** * Error message. Will be undefined if no error occurred. From 654d286c6d40b6036d742649100fb80c82136877 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Tue, 9 Apr 2024 14:06:41 +0100 Subject: [PATCH 3/5] Create witty-numbers-nail.md --- .changeset/witty-numbers-nail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/witty-numbers-nail.md diff --git a/.changeset/witty-numbers-nail.md b/.changeset/witty-numbers-nail.md new file mode 100644 index 000000000..cbb5d8a59 --- /dev/null +++ b/.changeset/witty-numbers-nail.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Fix sending events sometimes returning generic errors when we can be more specific From e7aeb7b26bf5f9971e9a8c387f7636f28df150f2 Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:47:52 +0000 Subject: [PATCH 4/5] Fix test assignment errors for Node 20 --- packages/inngest/src/components/Inngest.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/inngest/src/components/Inngest.test.ts b/packages/inngest/src/components/Inngest.test.ts index 032982ca7..6bd977c69 100644 --- a/packages/inngest/src/components/Inngest.test.ts +++ b/packages/inngest/src/components/Inngest.test.ts @@ -165,7 +165,12 @@ describe("send", () => { }; beforeAll(() => { - global.fetch = setFetch(); + Object.defineProperties(global, { + fetch: { + value: setFetch(), + configurable: true, + }, + }); }); beforeEach(() => { @@ -174,7 +179,13 @@ describe("send", () => { }); afterAll(() => { - global.fetch = originalFetch; + Object.defineProperties(global, { + fetch: { + value: originalFetch, + configurable: true, + }, + }); + process.env = originalProcessEnv; }); From c85b9c989f76a8d2e1853158e0298f645079aae4 Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:50:11 +0000 Subject: [PATCH 5/5] Fix further fetch assignment issues --- .../inngest/src/components/Inngest.test.ts | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/inngest/src/components/Inngest.test.ts b/packages/inngest/src/components/Inngest.test.ts index 6bd977c69..ba2cb3be4 100644 --- a/packages/inngest/src/components/Inngest.test.ts +++ b/packages/inngest/src/components/Inngest.test.ts @@ -494,22 +494,31 @@ describe("send", () => { }); test("should return error from Inngest if parsed", () => { - global.fetch = setFetch({ status: 400, error: "Test Error" }); - const inngest = createClient({ id: "test", eventKey: testEventKey }); + const inngest = createClient({ + id: "test", + eventKey: testEventKey, + fetch: setFetch({ status: 400, error: "Test Error" }), + }); return expect(inngest.send(testEvent)).rejects.toThrowError("Test Error"); }); test("should return error from Inngest if parsed even for 200", () => { - global.fetch = setFetch({ status: 200, error: "Test Error" }); - const inngest = createClient({ id: "test", eventKey: testEventKey }); + const inngest = createClient({ + id: "test", + eventKey: testEventKey, + fetch: setFetch({ status: 200, error: "Test Error" }), + }); return expect(inngest.send(testEvent)).rejects.toThrowError("Test Error"); }); test("should return error if bad status code with no error string", () => { - global.fetch = setFetch({ status: 400 }); - const inngest = createClient({ id: "test", eventKey: testEventKey }); + const inngest = createClient({ + id: "test", + eventKey: testEventKey, + fetch: setFetch({ status: 400 }), + }); return expect(inngest.send(testEvent)).rejects.toThrowError( "Cannot process event payload" @@ -517,8 +526,11 @@ describe("send", () => { }); test("should return unknown error from response text if very bad status code", () => { - global.fetch = setFetch({ status: 600 }); - const inngest = createClient({ id: "test", eventKey: testEventKey }); + const inngest = createClient({ + id: "test", + eventKey: testEventKey, + fetch: setFetch({ status: 600 }), + }); return expect(inngest.send(testEvent)).rejects.toThrowError("600"); });