From f4a40b573e28670a2704e46e3cf95942c8e51279 Mon Sep 17 00:00:00 2001 From: maaz519 Date: Thu, 28 May 2026 01:00:09 +0530 Subject: [PATCH] fix(api): add clearAllMocks and explicit return type to GroupsModule - Add jest.clearAllMocks() in beforeEach of both spec files to prevent call-history state from leaking between tests as the suites grow - Define GroupSummary interface and use it as explicit return type for GroupsService.list() to satisfy TypeScript strict typing requirements Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/modules/groups/groups.controller.spec.ts | 4 ++++ apps/api/src/modules/groups/groups.service.spec.ts | 4 ++++ apps/api/src/modules/groups/groups.service.ts | 11 ++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/api/src/modules/groups/groups.controller.spec.ts b/apps/api/src/modules/groups/groups.controller.spec.ts index fa81063..6e3770a 100644 --- a/apps/api/src/modules/groups/groups.controller.spec.ts +++ b/apps/api/src/modules/groups/groups.controller.spec.ts @@ -10,6 +10,10 @@ const mockService = { list: jest.fn().mockResolvedValue(mockGroups) }; describe('GroupsController', () => { let controller: GroupsController; + beforeEach(() => { + jest.clearAllMocks(); + }); + beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [GroupsController], diff --git a/apps/api/src/modules/groups/groups.service.spec.ts b/apps/api/src/modules/groups/groups.service.spec.ts index d7bdb1a..3fda63e 100644 --- a/apps/api/src/modules/groups/groups.service.spec.ts +++ b/apps/api/src/modules/groups/groups.service.spec.ts @@ -11,6 +11,10 @@ describe('GroupsService', () => { let service: GroupsService; const mockPrisma = { group: { findMany: jest.fn().mockResolvedValue(mockGroups) } }; + beforeEach(() => { + jest.clearAllMocks(); + }); + beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ providers: [ diff --git a/apps/api/src/modules/groups/groups.service.ts b/apps/api/src/modules/groups/groups.service.ts index 4720430..994c65b 100644 --- a/apps/api/src/modules/groups/groups.service.ts +++ b/apps/api/src/modules/groups/groups.service.ts @@ -1,11 +1,20 @@ import { Injectable } from '@nestjs/common'; import { PrismaService } from '../../prisma/prisma.service'; +interface GroupSummary { + id: string; + name: string; + platform: string; + platformId: string; + isActive: boolean; + accountId: string | null; +} + @Injectable() export class GroupsService { constructor(private readonly prisma: PrismaService) {} - list() { + list(): Promise { return this.prisma.group.findMany({ orderBy: { name: 'asc' }, select: { id: true, name: true, platform: true, platformId: true, isActive: true, accountId: true },