From 3746c098b54eac245c0443e7441dffdfaa43ec3f Mon Sep 17 00:00:00 2001 From: Chris Farhood Date: Mon, 4 May 2026 04:38:26 +0000 Subject: [PATCH] fix(GRO-982): simplify test mocks to match actual code flow --- .../messaging/__tests__/inbound.test.ts | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/apps/api/src/services/messaging/__tests__/inbound.test.ts b/apps/api/src/services/messaging/__tests__/inbound.test.ts index a62427e..b905824 100644 --- a/apps/api/src/services/messaging/__tests__/inbound.test.ts +++ b/apps/api/src/services/messaging/__tests__/inbound.test.ts @@ -221,18 +221,8 @@ describe("handleMessageReceived", () => { }); it("creates conversation and message for valid inbound", async () => { - const businessLookup = { - from: vi.fn().mockReturnValue({ - where: vi.fn().mockReturnValue({ - limit: vi.fn().mockReturnValue([{ id: "biz-1" }]), - }), - }), - }; - let selectCallCount = 0; - mockDb.select.mockImplementation(() => { - selectCallCount++; - if (selectCallCount === 1) return businessLookup; - return { + mockDb.select + .mockReturnValueOnce({ from: vi.fn().mockReturnValue({ where: vi.fn().mockReturnValue({ limit: vi.fn().mockReturnValue([{ id: "biz-1" }]), @@ -245,18 +235,18 @@ describe("handleMessageReceived", () => { limit: vi.fn().mockReturnValue([]), }), }), - }; - }); - mockDb.insert.mockReturnValueOnce({ - values: vi.fn().mockReturnValue({ - returning: vi.fn().mockReturnValue([{ id: "client-new" }]), - }), - }); - mockDb.insert.mockReturnValueOnce({ - values: vi.fn().mockReturnValue({ - returning: vi.fn().mockReturnValue([{ id: "conv-new", clientId: "client-new" }]), - }), - }); + }); + mockDb.insert + .mockReturnValueOnce({ + values: vi.fn().mockReturnValue({ + returning: vi.fn().mockReturnValue([{ id: "client-new" }]), + }), + }) + .mockReturnValueOnce({ + values: vi.fn().mockReturnValue({ + returning: vi.fn().mockReturnValue([{ id: "conv-new", clientId: "client-new" }]), + }), + }); mockDb.update.mockReturnValueOnce({ set: vi.fn().mockReturnValue({ where: vi.fn().mockReturnValue({}),