|
| 1 | +import { Test } from '@nestjs/testing' |
| 2 | +import type { TestingModule } from '@nestjs/testing' |
| 3 | +import { describe, it, expect, beforeEach } from 'vitest' |
| 4 | +import { mockDeep, mockReset } from 'vitest-mock-extended' |
| 5 | +import { NexusService } from './nexus.service' |
| 6 | +import { NexusClientService } from './nexus-client.service' |
| 7 | +import { VaultService } from '../vault/vault.service' |
| 8 | +import { ConfigurationService } from '@/cpin-module/infrastructure/configuration/configuration.service' |
| 9 | + |
| 10 | +const nexusClientMock = mockDeep<NexusClientService>() |
| 11 | +const vaultMock = mockDeep<VaultService>() |
| 12 | + |
| 13 | +function createNexusServiceTestingModule() { |
| 14 | + return Test.createTestingModule({ |
| 15 | + providers: [ |
| 16 | + NexusService, |
| 17 | + { |
| 18 | + provide: NexusClientService, |
| 19 | + useValue: nexusClientMock, |
| 20 | + }, |
| 21 | + { |
| 22 | + provide: VaultService, |
| 23 | + useValue: vaultMock, |
| 24 | + }, |
| 25 | + { |
| 26 | + provide: ConfigurationService, |
| 27 | + useValue: { |
| 28 | + nexusSecretExposedUrl: 'https://nexus.example', |
| 29 | + projectRootPath: 'forge', |
| 30 | + } satisfies Partial<ConfigurationService>, |
| 31 | + }, |
| 32 | + ], |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +describe('nexusService', () => { |
| 37 | + let service: NexusService |
| 38 | + |
| 39 | + beforeEach(async () => { |
| 40 | + mockReset(nexusClientMock) |
| 41 | + mockReset(vaultMock) |
| 42 | + const module: TestingModule = await createNexusServiceTestingModule().compile() |
| 43 | + service = module.get(NexusService) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should be defined', () => { |
| 47 | + expect(service).toBeDefined() |
| 48 | + }) |
| 49 | +}) |
0 commit comments