-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EW-1070 creating post endpoints to create a course #5385
Open
psachmann
wants to merge
30
commits into
main
Choose a base branch
from
EW-1070
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+988
−1,149
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4fb4793
Adding new import endpoint to cc micro service
psachmann 2d6476b
Working on create course endpoint
psachmann 5166b62
updating and moving courses client
psachmann 21d9d87
removing old courses client
psachmann e50bdc3
fixing imports
psachmann e1c1081
Merge branch 'main' into EW-1070
psachmann 2b5536f
removing todos
psachmann ae0fcc4
Merge branch 'main' into EW-1070
psachmann 54d5eb5
adding tests
psachmann 24b2cae
working on tests
psachmann 296f717
tests
psachmann 0dfb6a6
working on tests
psachmann 0701698
Merge branch 'main' into EW-1070
psachmann d435b35
moving pipe utils
psachmann eb6a12c
updating config
psachmann 7fb8097
adding tests for import service
psachmann 1fa8fed
fixing imports
psachmann 456fd63
adding api test
psachmann b15d58f
updating test
psachmann 610aa1f
Merge branch 'main' into EW-1070
psachmann af3c4fc
updating tests
psachmann 63ed335
updating tests
psachmann 8d2429e
adding cc route to ingress
psachmann c5e5b79
testing auth-guard module
psachmann 6b1b7fc
updating imports
psachmann 09e6ba9
updating config
psachmann 665cca4
Merge branch 'main' into EW-1070
psachmann 044931f
changing config
psachmann 459cb2e
fixing path
psachmann ae0806d
fixing tests
psachmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 {} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should we move common-cartridge to infra?