-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './generated/api'; | ||
export * from './generated/models'; | ||
export * from './vidis-client-config'; | ||
export * from './vidis-client-factory'; | ||
export * from './vidis-client.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface VidisClientConfig { | ||
VIDIS_API_CLIENT_BASE_URL: string; | ||
} |
42 changes: 42 additions & 0 deletions
42
apps/server/src/infra/vidis-client/vidis-client-factory.integration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { createMock } from '@golevelup/ts-jest'; | ||
import { ServerTestModule } from '@modules/server'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { VidisClientFactory } from './vidis-client-factory'; | ||
import { VidisClientModule } from './vidis-client.module'; | ||
|
||
describe.skip('VidisClientFactory Integration', () => { | ||
let module: TestingModule; | ||
let sut: VidisClientFactory; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [ServerTestModule, VidisClientModule], | ||
}) | ||
.overrideProvider(ConfigService) | ||
.useValue( | ||
createMock<ConfigService>({ | ||
getOrThrow: (key: string) => { | ||
switch (key) { | ||
case 'VIDIS_API_CLIENT_BASE_URL': | ||
return 'https://test2.schulportal-thueringen.de/tip-ms/api'; | ||
|
||
default: | ||
throw new Error(`Unknown key: ${key}`); | ||
} | ||
}, | ||
}) | ||
) | ||
.compile(); | ||
|
||
sut = module.get(VidisClientFactory); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(sut).toBeDefined(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
apps/server/src/infra/vidis-client/vidis-client-factory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { DeepMocked, createMock } from '@golevelup/ts-jest'; | ||
import { ServerConfig } from '@modules/server'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { VidisClientFactory } from './vidis-client-factory'; | ||
|
||
describe('TspClientFactory', () => { | ||
let module: TestingModule; | ||
let sut: VidisClientFactory; | ||
let configServiceMock: DeepMocked<ConfigService<ServerConfig, true>>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
VidisClientFactory, | ||
{ | ||
provide: ConfigService, | ||
useValue: createMock<ConfigService<ServerConfig, true>>({ | ||
getOrThrow: (key: string) => { | ||
switch (key) { | ||
case 'VIDIS_API_CLIENT_BASE_URL': | ||
return faker.internet.url(); | ||
default: | ||
throw new Error(`Unknown key: ${key}`); | ||
} | ||
}, | ||
}), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
sut = module.get(VidisClientFactory); | ||
configServiceMock = module.get(ConfigService); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
jest.restoreAllMocks(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(sut).toBeDefined(); | ||
}); | ||
|
||
describe('createExportClient', () => { | ||
describe('when createExportClient is called', () => { | ||
it('should return ExportApiInterface', () => { | ||
const result = sut.createExportClient({ | ||
password: faker.string.alpha(), | ||
username: faker.string.alpha(), | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(configServiceMock.getOrThrow).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
apps/server/src/infra/vidis-client/vidis-client-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Configuration, IDMBetreiberApiFactory, IDMBetreiberApiInterface } from './generated'; | ||
import { VidisClientConfig } from './vidis-client-config'; | ||
|
||
type FactoryParams = { | ||
username: string; | ||
password: string; | ||
}; | ||
|
||
@Injectable() | ||
export class VidisClientFactory { | ||
private readonly baseUrl: string; | ||
|
||
constructor(private readonly configService: ConfigService<VidisClientConfig, true>) { | ||
this.baseUrl = configService.getOrThrow<string>('VIDIS_API_CLIENT_BASE_URL'); | ||
} | ||
|
||
public createExportClient(params: FactoryParams): IDMBetreiberApiInterface { | ||
const factory = IDMBetreiberApiFactory( | ||
new Configuration({ | ||
username: params.username, | ||
password: params.password, | ||
basePath: this.baseUrl, | ||
}) | ||
); | ||
|
||
return factory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { VidisClientFactory } from './vidis-client-factory'; | ||
|
||
@Module({ | ||
imports: [], | ||
providers: [VidisClientFactory], | ||
exports: [VidisClientFactory], | ||
}) | ||
export class VidisClientModule {} |