Skip to content
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
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Dec 4, 2024
2d6476b
Working on create course endpoint
psachmann Dec 4, 2024
5166b62
updating and moving courses client
psachmann Dec 5, 2024
21d9d87
removing old courses client
psachmann Dec 5, 2024
e50bdc3
fixing imports
psachmann Dec 5, 2024
e1c1081
Merge branch 'main' into EW-1070
psachmann Dec 5, 2024
2b5536f
removing todos
psachmann Dec 6, 2024
ae0fcc4
Merge branch 'main' into EW-1070
psachmann Dec 6, 2024
54d5eb5
adding tests
psachmann Dec 6, 2024
24b2cae
working on tests
psachmann Dec 6, 2024
296f717
tests
psachmann Dec 6, 2024
0dfb6a6
working on tests
psachmann Dec 6, 2024
0701698
Merge branch 'main' into EW-1070
psachmann Dec 9, 2024
d435b35
moving pipe utils
psachmann Dec 9, 2024
eb6a12c
updating config
psachmann Dec 9, 2024
7fb8097
adding tests for import service
psachmann Dec 9, 2024
1fa8fed
fixing imports
psachmann Dec 9, 2024
456fd63
adding api test
psachmann Dec 11, 2024
b15d58f
updating test
psachmann Dec 11, 2024
610aa1f
Merge branch 'main' into EW-1070
psachmann Dec 11, 2024
af3c4fc
updating tests
psachmann Dec 11, 2024
63ed335
updating tests
psachmann Dec 11, 2024
8d2429e
adding cc route to ingress
psachmann Dec 11, 2024
c5e5b79
testing auth-guard module
psachmann Dec 11, 2024
6b1b7fc
updating imports
psachmann Dec 11, 2024
09e6ba9
updating config
psachmann Dec 11, 2024
665cca4
Merge branch 'main' into EW-1070
psachmann Dec 11, 2024
044931f
changing config
psachmann Dec 11, 2024
459cb2e
fixing path
psachmann Dec 11, 2024
ae0806d
fixing tests
psachmann Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ansible/roles/common-cartridge/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
- service

# This is a testing route and will not be deployed
# - name: Ingress
# kubernetes.core.k8s:
# kubeconfig: ~/.kube/config
# namespace: "{{ NAMESPACE }}"
# template: ingress.yml.j2
# when: WITH_COMMON_CARTRIDGE is defined and WITH_COMMON_CARTRIDGE|bool
# tags:
# - ingress
- name: Ingress
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
template: ingress.yml.j2
when: WITH_COMMON_CARTRIDGE is defined and WITH_COMMON_CARTRIDGE|bool
tags:
- ingress
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 apps/server/src/infra/courses-client/courses-client.adapter.ts
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 {
Copy link
Contributor

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?

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 apps/server/src/infra/courses-client/courses-client.config.ts
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 apps/server/src/infra/courses-client/courses-client.module.spec.ts
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 apps/server/src/infra/courses-client/courses-client.module.ts
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 {}
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
Loading
Loading