Skip to content

Commit b2f063d

Browse files
committed
refactor(server-nestjs): migrate package managers to NestJS
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
1 parent 7d31648 commit b2f063d

10 files changed

Lines changed: 1141 additions & 0 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ConfigurationService } from '@/cpin-module/infrastructure/configuration/configuration.service'
2+
import { Inject, Injectable } from '@nestjs/common'
3+
import axios from 'axios'
4+
import type { AxiosInstance } from 'axios'
5+
import { removeTrailingSlash } from './nexus.utils'
6+
7+
@Injectable()
8+
export class NexusClientService {
9+
readonly axios: AxiosInstance
10+
11+
constructor(
12+
@Inject(ConfigurationService) private readonly config: ConfigurationService,
13+
) {
14+
this.axios = axios.create({
15+
baseURL: `${removeTrailingSlash(this.config.nexusInternalUrl!)}/service/rest/v1/`,
16+
auth: {
17+
username: this.config.nexusAdmin!,
18+
password: this.config.nexusAdminPassword!,
19+
},
20+
headers: {
21+
Accept: 'application/json',
22+
},
23+
})
24+
}
25+
26+
async deleteIfExists(path: string) {
27+
return this.axios({
28+
method: 'delete',
29+
url: path,
30+
validateStatus: code => code === 404 || code < 300,
31+
})
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Module } from '@nestjs/common'
2+
import { ConfigurationModule } from '@/cpin-module/infrastructure/configuration/configuration.module'
3+
import { InfrastructureModule } from '@/cpin-module/infrastructure/infrastructure.module'
4+
import { VaultModule } from '../vault/vault.module'
5+
import { NexusClientService } from './nexus-client.service'
6+
import { NexusService } from './nexus.service'
7+
8+
@Module({
9+
imports: [ConfigurationModule, InfrastructureModule, VaultModule],
10+
providers: [NexusService, NexusClientService],
11+
exports: [NexusService],
12+
})
13+
export class NexusModule {}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)