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 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,10 @@ const mockService = { list: jest.fn().mockResolvedValue(mockGroups) };
|
|||||||
describe('GroupsController', () => {
|
describe('GroupsController', () => {
|
||||||
let controller: GroupsController;
|
let controller: GroupsController;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [GroupsController],
|
controllers: [GroupsController],
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ describe('GroupsService', () => {
|
|||||||
let service: GroupsService;
|
let service: GroupsService;
|
||||||
const mockPrisma = { group: { findMany: jest.fn().mockResolvedValue(mockGroups) } };
|
const mockPrisma = { group: { findMany: jest.fn().mockResolvedValue(mockGroups) } };
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { PrismaService } from '../../prisma/prisma.service';
|
import { PrismaService } from '../../prisma/prisma.service';
|
||||||
|
|
||||||
|
interface GroupSummary {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
platform: string;
|
||||||
|
platformId: string;
|
||||||
|
isActive: boolean;
|
||||||
|
accountId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GroupsService {
|
export class GroupsService {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
list() {
|
list(): Promise<GroupSummary[]> {
|
||||||
return this.prisma.group.findMany({
|
return this.prisma.group.findMany({
|
||||||
orderBy: { name: 'asc' },
|
orderBy: { name: 'asc' },
|
||||||
select: { id: true, name: true, platform: true, platformId: true, isActive: true, accountId: true },
|
select: { id: true, name: true, platform: true, platformId: true, isActive: true, accountId: true },
|
||||||
|
|||||||
Reference in New Issue
Block a user