-
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.
Browse files
Browse the repository at this point in the history
* adding new import endpoint to cc microservice * updating and moving courses client * removing old courses client * updating config for cc microservice
- Loading branch information
Showing
71 changed files
with
1,043 additions
and
1,169 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
apps/server/src/infra/courses-client/courses-client.adapter.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,72 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CoursesClientAdapter } from './courses-client.adapter'; | ||
import { CoursesApi, CreateCourseBodyParams } from './generated'; | ||
|
||
describe(CoursesClientAdapter.name, () => { | ||
let module: TestingModule; | ||
let sut: CoursesClientAdapter; | ||
let coursesApiMock: DeepMocked<CoursesApi>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
CoursesClientAdapter, | ||
{ | ||
provide: CoursesApi, | ||
useValue: createMock<CoursesApi>(), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
sut = module.get(CoursesClientAdapter); | ||
coursesApiMock = module.get(CoursesApi); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(sut).toBeDefined(); | ||
}); | ||
|
||
describe('getCourseCommonCartridgeMetadata', () => { | ||
const setup = () => { | ||
const courseId = faker.string.uuid(); | ||
|
||
return { courseId }; | ||
}; | ||
|
||
it('should call courseControllerGetCourseCcMetadataById with the correct courseId', async () => { | ||
const { courseId } = setup(); | ||
|
||
await sut.getCourseCommonCartridgeMetadata(courseId); | ||
|
||
expect(coursesApiMock.courseControllerGetCourseCcMetadataById).toHaveBeenCalledWith(courseId); | ||
}); | ||
}); | ||
|
||
describe('createCourse', () => { | ||
const setup = () => { | ||
const params: CreateCourseBodyParams = { | ||
title: faker.word.noun(), | ||
}; | ||
|
||
return { params }; | ||
}; | ||
|
||
it('should call courseControllerCreateCourse with the correct params', async () => { | ||
const { params } = setup(); | ||
|
||
await sut.createCourse(params); | ||
|
||
expect(coursesApiMock.courseControllerCreateCourse).toHaveBeenCalledWith(params); | ||
}); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
apps/server/src/infra/courses-client/courses-client.adapter.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,17 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CourseCommonCartridgeMetadataResponse, CoursesApi, CreateCourseBodyParams } from './generated'; | ||
|
||
@Injectable() | ||
export class CoursesClientAdapter { | ||
constructor(private readonly coursesApi: CoursesApi) {} | ||
|
||
public async getCourseCommonCartridgeMetadata(courseId: string): Promise<CourseCommonCartridgeMetadataResponse> { | ||
const response = await this.coursesApi.courseControllerGetCourseCcMetadataById(courseId); | ||
|
||
return response.data; | ||
} | ||
|
||
public async createCourse(params: CreateCourseBodyParams): Promise<void> { | ||
await this.coursesApi.courseControllerCreateCourse(params); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/server/src/infra/courses-client/courses-client.config.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,3 @@ | ||
export interface CoursesClientConfig { | ||
API_HOST: string; | ||
} |
57 changes: 57 additions & 0 deletions
57
apps/server/src/infra/courses-client/courses-client.module.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,57 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
import { ConfigModule, ConfigService } from '@nestjs/config'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { Request } from 'express'; | ||
import { CoursesClientAdapter } from './courses-client.adapter'; | ||
import { CoursesClientModule } from './courses-client.module'; | ||
import { CoursesApi } from './generated'; | ||
|
||
describe(CoursesClientModule.name, () => { | ||
let module: TestingModule; | ||
let sut: CoursesClientModule; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [CoursesClientModule, ConfigModule.forRoot({ isGlobal: true })], | ||
}) | ||
.overrideProvider(ConfigService) | ||
.useValue( | ||
createMock<ConfigService>({ | ||
getOrThrow: () => faker.internet.url(), | ||
}) | ||
) | ||
.overrideProvider(REQUEST) | ||
.useValue({ headers: { authorization: `Bearer ${faker.string.alphanumeric(42)}` } } as Request) | ||
.compile(); | ||
|
||
sut = module.get(CoursesClientModule); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(sut).toBeDefined(); | ||
}); | ||
|
||
describe('when requesting dependencies', () => { | ||
it('should resolve CoursesApi', async () => { | ||
const dependency = await module.resolve(CoursesApi); | ||
|
||
expect(dependency).toBeInstanceOf(CoursesApi); | ||
}); | ||
|
||
it('should resolve CoursesClientAdapter', async () => { | ||
const dependency = await module.resolve(CoursesClientAdapter); | ||
|
||
expect(dependency).toBeInstanceOf(CoursesClientAdapter); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
apps/server/src/infra/courses-client/courses-client.module.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,31 @@ | ||
import { Module, Scope } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { JwtExtractor } from '@shared/common/utils'; | ||
import { Request } from 'express'; | ||
import { CoursesClientAdapter } from './courses-client.adapter'; | ||
import { CoursesClientConfig } from './courses-client.config'; | ||
import { Configuration, CoursesApi } from './generated'; | ||
|
||
@Module({ | ||
providers: [ | ||
CoursesClientAdapter, | ||
{ | ||
provide: CoursesApi, | ||
scope: Scope.REQUEST, | ||
useFactory: (configService: ConfigService<CoursesClientConfig, true>, request: Request): CoursesApi => { | ||
const basePath = configService.getOrThrow<string>('API_HOST'); | ||
const accessToken = JwtExtractor.extractJwtFromRequest(request); | ||
const configuration = new Configuration({ | ||
basePath: `${basePath}/v3`, | ||
accessToken, | ||
}); | ||
|
||
return new CoursesApi(configuration); | ||
}, | ||
inject: [ConfigService, REQUEST], | ||
}, | ||
], | ||
exports: [CoursesClientAdapter], | ||
}) | ||
export class CoursesClientModule {} |
32 changes: 16 additions & 16 deletions
32
...o/course-common-cartridge-metadata.dto.ts → .../courses-common-cartridge-metadata.dto.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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
export class CourseCommonCartridgeMetadataDto { | ||
id: string; | ||
|
||
courseName: string; | ||
|
||
creationDate?: string; | ||
|
||
copyRightOwners: Array<string>; | ||
|
||
constructor(props: CourseCommonCartridgeMetadataDto) { | ||
this.id = props.id; | ||
this.courseName = props.courseName; | ||
this.creationDate = props.creationDate; | ||
this.copyRightOwners = props.copyRightOwners; | ||
} | ||
} | ||
export class CourseCommonCartridgeMetadataDto { | ||
public id: string; | ||
|
||
public title: string; | ||
|
||
public creationDate: string; | ||
|
||
public copyRightOwners: Array<string>; | ||
|
||
constructor(props: CourseCommonCartridgeMetadataDto) { | ||
this.id = props.id; | ||
this.title = props.title; | ||
this.creationDate = props.creationDate; | ||
this.copyRightOwners = props.copyRightOwners; | ||
} | ||
} |
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 @@ | ||
export { CourseCommonCartridgeMetadataDto } from './courses-common-cartridge-metadata.dto'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 13 additions & 15 deletions
28
...ourse-api-client/.openapi-generator/FILES → ...client/generated/.openapi-generator/FILES
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
.gitignore | ||
.npmignore | ||
.openapi-generator-ignore | ||
api.ts | ||
api/courses-api.ts | ||
base.ts | ||
common.ts | ||
configuration.ts | ||
git_push.sh | ||
index.ts | ||
models/course-common-cartridge-metadata-response.ts | ||
models/course-export-body-params.ts | ||
models/course-metadata-list-response.ts | ||
models/course-metadata-response.ts | ||
models/index.ts | ||
.gitignore | ||
.npmignore | ||
.openapi-generator-ignore | ||
api.ts | ||
api/courses-api.ts | ||
base.ts | ||
common.ts | ||
configuration.ts | ||
git_push.sh | ||
index.ts | ||
models/course-common-cartridge-metadata-response.ts | ||
models/create-course-body-params.ts | ||
models/index.ts |
File renamed without changes.
Oops, something went wrong.