diff --git a/apps/backend/src/modules/health/health.service.spec.ts b/apps/backend/src/modules/health/health.service.spec.ts index 3f6d21a..8c931e7 100644 --- a/apps/backend/src/modules/health/health.service.spec.ts +++ b/apps/backend/src/modules/health/health.service.spec.ts @@ -1,27 +1,43 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { ConfigModule } from '@nestjs/config'; +import { ConfigService } from '@nestjs/config'; import { HealthService } from './health.service'; import { PrismaService } from '../prisma/prisma.service'; -import configuration from '../../config/configuration'; describe('HealthService', () => { let service: HealthService; const prisma = { $queryRaw: vi.fn() } as any; + const config = { + get: vi.fn((key: string, fallback?: unknown) => { + const values: Record = { + 'app.moex.baseUrl': 'https://iss.moex.test/iss', + 'app.tbank.token': 'token-1', + }; + + return values[key] ?? fallback; + }), + } as unknown as ConfigService; + const fetchMock = vi.fn(); beforeEach(async () => { vi.clearAllMocks(); + vi.stubGlobal('fetch', fetchMock); + fetchMock.mockResolvedValue({ ok: true, status: 200 }); const module: TestingModule = await Test.createTestingModule({ - imports: [ConfigModule.forRoot({ load: [configuration], isGlobal: true })], providers: [ HealthService, { provide: PrismaService, useValue: prisma }, + { provide: ConfigService, useValue: config }, ], }).compile(); service = module.get(HealthService); }); + afterEach(() => { + vi.unstubAllGlobals(); + }); + it('returns ok when all dependencies are healthy', async () => { prisma.$queryRaw.mockResolvedValue([{ 1: 1 }]);