From 2648869f5345abcc288174f03e1babd8faae8861 Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Tue, 21 Jul 2026 20:46:22 +0200 Subject: [PATCH] fix(tests): resolve 6 pre-existing test failures in pet-profile and stories suites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prisma mock was missing the inviteCode model entirely, so pets.create's starter-invite-code check crashed on undefined.count(). STORY-02 tests mocked story.count, but hasActiveStory actually calls story.findMany (needs the ids for the follow-up storyView.count query) — updated the tests to match the real implementation. --- src/__tests__/helpers/prisma-mock.ts | 12 ++++++++++++ src/__tests__/stories.test.ts | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/__tests__/helpers/prisma-mock.ts b/src/__tests__/helpers/prisma-mock.ts index d9b1ace..f8d260b 100644 --- a/src/__tests__/helpers/prisma-mock.ts +++ b/src/__tests__/helpers/prisma-mock.ts @@ -30,6 +30,11 @@ interface MockOwnerClient { update: MockFn; } +interface MockInviteCodeClient { + count: MockFn; + createMany: MockFn; +} + interface MockLegalDocumentVersionClient { create: MockFn; findMany: MockFn; @@ -203,6 +208,7 @@ interface MockNotificationClient { interface MockPrismaClient { pet: MockPetClient; owner: MockOwnerClient; + inviteCode: MockInviteCodeClient; species: MockSpeciesClient; breed: MockBreedClient; // Phase 2 @@ -249,6 +255,12 @@ export function createMockPrisma(): MockPrismaClient { create: vi.fn(), update: vi.fn(), }, + // pets.create's idempotent starter-invite-code seeding runs on every call — + // default to "no codes yet" so tests unrelated to invites don't need to stub it. + inviteCode: { + count: vi.fn().mockResolvedValue(0), + createMany: vi.fn().mockResolvedValue({ count: 0 }), + }, legalDocumentVersion: { create: vi.fn(), findMany: vi.fn(), diff --git a/src/__tests__/stories.test.ts b/src/__tests__/stories.test.ts index f3288e7..44efc38 100644 --- a/src/__tests__/stories.test.ts +++ b/src/__tests__/stories.test.ts @@ -97,12 +97,12 @@ describe("stories.hasActiveStory", () => { it("STORY-02 — hasActiveStory returns true when a non-expired story exists", async () => { const { caller, mockPrisma } = createCaller(); - mockPrisma.story.count.mockResolvedValue(1); + mockPrisma.story.findMany.mockResolvedValue([{ id: "story-1" }]); const result = await caller.hasActiveStory({ petId: "pet-1" }); - expect(result).toBe(true); - expect(mockPrisma.story.count).toHaveBeenCalledWith( + expect(result).toMatchObject({ hasStory: true }); + expect(mockPrisma.story.findMany).toHaveBeenCalledWith( expect.objectContaining({ where: expect.objectContaining({ petId: "pet-1", @@ -115,11 +115,11 @@ describe("stories.hasActiveStory", () => { it("STORY-02 — hasActiveStory returns false when no active stories exist", async () => { const { caller, mockPrisma } = createCaller(); - mockPrisma.story.count.mockResolvedValue(0); + mockPrisma.story.findMany.mockResolvedValue([]); const result = await caller.hasActiveStory({ petId: "pet-1" }); - expect(result).toBe(false); + expect(result).toMatchObject({ hasStory: false }); }); });