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-1071 Common Cartridge microservice creates boards during import #5435

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b46284d
adding access modifiers
psachmann Jan 14, 2025
0f390f0
creating new boards client
psachmann Jan 14, 2025
3a633ae
updating api client
psachmann Jan 15, 2025
6f0f7ab
updating boards-client-adapter and module
psachmann Jan 15, 2025
d730d64
adding tests
psachmann Jan 15, 2025
009282e
updating courses client
psachmann Jan 15, 2025
d188e16
adding create course response
psachmann Jan 15, 2025
f825469
creating boards via cc import micro service
psachmann Jan 15, 2025
5c21284
Merge branch 'main' into EW-1071
psachmann Jan 21, 2025
8ff4671
fixing linter warnings
psachmann Jan 21, 2025
9a50658
fixing test
psachmann Jan 21, 2025
d5f18b0
adding tests
psachmann Jan 21, 2025
e595ec8
skipping test
psachmann Jan 21, 2025
d8ea2ab
fixing sonar cloud issue
psachmann Jan 21, 2025
9965fd3
fixing module imports
psachmann Jan 21, 2025
6e1ef6d
removing old boards client
psachmann Jan 21, 2025
e26898b
Merge branch 'main' into EW-1071
psachmann Jan 21, 2025
810596a
fixing errors after merge
psachmann Jan 21, 2025
5a22c40
fixing errors
psachmann Jan 22, 2025
c6c79f9
Merge branch 'main' into EW-1071
psachmann Jan 22, 2025
e917828
Update apps/server/src/infra/boards-client/boards-client.adapter.spec.ts
psachmann Jan 22, 2025
2c5c205
Update apps/server/src/infra/boards-client/boards-client.adapter.spec.ts
psachmann Jan 22, 2025
7708c8f
changing test names
psachmann Jan 22, 2025
35c665d
removing duplicated test
psachmann Jan 22, 2025
0627de8
Merge branch 'main' into EW-1071
psachmann Jan 23, 2025
0b90f81
Merge branch 'main' into EW-1071
psachmann Jan 23, 2025
32d2e36
fixing merge error
psachmann Jan 23, 2025
227f42a
Merge branch 'main' into EW-1071
psachmann Jan 23, 2025
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
107 changes: 107 additions & 0 deletions apps/server/src/infra/boards-client/boards-client.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Test, TestingModule } from '@nestjs/testing';
import { createMock } from '@golevelup/ts-jest';
import { faker } from '@faker-js/faker';
import { axiosResponseFactory } from '@testing/factory/axios-response.factory';
import { BoardsClientAdapter } from './boards-client.adapter';
import { BoardApi, BoardResponse, CreateBoardBodyParams, CreateBoardResponse } from './generated';

describe(BoardsClientAdapter.name, () => {
let module: TestingModule;
let sut: BoardsClientAdapter;

const boardApiMock = createMock<BoardApi>();

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
BoardsClientAdapter,
{
provide: BoardApi,
useValue: boardApiMock,
},
],
}).compile();
sut = module.get(BoardsClientAdapter);
});

afterAll(async () => {
await module.close();
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be defined', () => {
expect(sut).toBeDefined();
});

describe('createBoard', () => {
describe('when called', () => {
Fshmit marked this conversation as resolved.
Show resolved Hide resolved
const setup = () => {
const params: CreateBoardBodyParams = {
title: faker.lorem.words(),
layout: 'columns',
parentId: faker.string.uuid(),
parentType: 'course',
};
const responseData: CreateBoardResponse = {
id: faker.string.uuid(),
};

boardApiMock.boardControllerCreateBoard.mockResolvedValue(axiosResponseFactory.build({ data: responseData }));

return {
params,
responseData,
};
};

it('should call boardApi.boardControllerCreateBoard', async () => {
const { params, responseData } = setup();

const response = await sut.createBoard(params);

expect(response).toEqual(responseData);
expect(boardApiMock.boardControllerCreateBoard).toHaveBeenCalledWith(params);
});
});
});

describe('getBoardSkeletonById', () => {
describe('when called', () => {
Fshmit marked this conversation as resolved.
Show resolved Hide resolved
const setup = () => {
const boardId = faker.string.uuid();
const responseData: BoardResponse = {
id: boardId,
title: faker.lorem.words(),
layout: 'columns',
columns: [],
isVisible: true,
timestamps: {
createdAt: faker.date.recent().toISOString(),
lastUpdatedAt: faker.date.recent().toISOString(),
},
};

boardApiMock.boardControllerGetBoardSkeleton.mockResolvedValue(
axiosResponseFactory.build({ data: responseData })
);

return {
boardId,
responseData,
};
};

it('should call boardApi.boardControllerGetBoardSkeleton', async () => {
const { boardId, responseData } = setup();

const response = await sut.getBoardSkeletonById(boardId);

expect(response).toEqual(responseData);
expect(boardApiMock.boardControllerGetBoardSkeleton).toHaveBeenCalledWith(boardId);
});
});
});
});
19 changes: 19 additions & 0 deletions apps/server/src/infra/boards-client/boards-client.adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@nestjs/common';
import { BoardApi, BoardResponse, CreateBoardBodyParams, CreateBoardResponse } from './generated';

@Injectable()
export class BoardsClientAdapter {
constructor(private readonly boardApi: BoardApi) {}

public async createBoard(params: CreateBoardBodyParams): Promise<CreateBoardResponse> {
const response = await this.boardApi.boardControllerCreateBoard(params);

return response.data;
}

public async getBoardSkeletonById(boardId: string): Promise<BoardResponse> {
const response = await this.boardApi.boardControllerGetBoardSkeleton(boardId);

return response.data;
}
}
3 changes: 3 additions & 0 deletions apps/server/src/infra/boards-client/boards-client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface BoardsClientConfig {
API_HOST: string;
}
60 changes: 60 additions & 0 deletions apps/server/src/infra/boards-client/boards-client.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigModule } from '@nestjs/config';
import { faker } from '@faker-js/faker';
import { Request } from 'express';
import { createMock } from '@golevelup/ts-jest';
import { REQUEST } from '@nestjs/core';
import { BoardsClientAdapter } from './boards-client.adapter';
import { BoardsClientConfig } from './boards-client.config';
import { BoardsClientModule } from './boards-client.module';

describe(BoardsClientModule.name, () => {
let module: TestingModule;

const requestMock = createMock<Request>({
headers: {
authorization: `Bearer ${faker.string.alphanumeric(42)}`,
},
});

beforeEach(async () => {
module = await Test.createTestingModule({
imports: [
BoardsClientModule,
ConfigModule.forRoot({
isGlobal: true,
load: [
(): BoardsClientConfig => {
return {
API_HOST: faker.internet.url(),
};
},
],
}),
],
})
.overrideProvider(REQUEST)
.useValue(requestMock)
.compile();
});

afterAll(async () => {
await module.close();
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be defined', () => {
expect(module).toBeDefined();
});

describe('when resolving dependencies', () => {
it('should resolve BoardsClientAdapter', async () => {
const adapter = await module.resolve(BoardsClientAdapter);

expect(adapter).toBeInstanceOf(BoardsClientAdapter);
});
});
});
31 changes: 31 additions & 0 deletions apps/server/src/infra/boards-client/boards-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';
import { Request } from 'express';
import { BoardsClientAdapter } from './boards-client.adapter';
import { BoardsClientConfig } from './boards-client.config';
import { Configuration, BoardApi } from './generated';

@Module({
providers: [
BoardsClientAdapter,
{
provide: BoardApi,
scope: Scope.REQUEST,
useFactory: (configService: ConfigService<BoardsClientConfig, true>, request: Request): BoardApi => {
const basePath = configService.getOrThrow<string>('API_HOST');
const accessToken = JwtExtractor.extractJwtFromRequest(request);
const configuration = new Configuration({
basePath: `${basePath}/v3`,
accessToken,
});

return new BoardApi(configuration);
},
inject: [ConfigService, REQUEST],
},
],
exports: [BoardsClientAdapter],
})
export class BoardsClientModule {}
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
.gitignore
.npmignore
api.ts
api/board-api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
models/api-validation-error.ts
models/board-context-response.ts
models/board-external-reference-type.ts
models/board-layout.ts
models/board-parent-type.ts
models/board-response.ts
models/card-skeleton-response.ts
models/column-response.ts
models/copy-api-response.ts
models/create-board-body-params.ts
models/create-board-response.ts
models/index.ts
models/timestamps-response.ts
models/update-board-title-params.ts
models/visibility-body-params.ts
.gitignore
.npmignore
.openapi-generator-ignore
api.ts
api/board-api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
models/board-layout.ts
models/board-parent-type.ts
models/board-response.ts
models/card-skeleton-response.ts
models/column-response.ts
models/create-board-body-params.ts
models/create-board-response.ts
models/index.ts
models/timestamps-response.ts
Loading
Loading