fix(tests): resolve 6 pre-existing test failures in pet-profile and stories suites

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.
This commit is contained in:
admin committed 2026-07-21 20:46:22 +02:00
1 parent 215fba80d4
commit 2648869f53
2 files changed
+17 -5

No files matched your search

+12
View File
@@ -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(),
+5 -5
View File
@@ -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 });
});
});