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-1009: Detach card dependency from boards #5306

Merged
merged 52 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3222525
ew-1009: update readme.md in common cartridge
HKayed Oct 15, 2024
f9e04c7
ew-1009: added generated API code
HKayed Oct 15, 2024
8c89ad5
ew-1009: created adapter, request config and module wrapper
HKayed Oct 15, 2024
b37a85f
ew-1009: modified return type of get request and extracted array of r…
HKayed Oct 15, 2024
fb0bafa
ew-1009: added all required DTOs for uc usage
HKayed Oct 18, 2024
5b88b9d
ew-1009: proper mapping for all DTOs implemented
HKayed Oct 18, 2024
2fbdf11
ew-1009: tests setup
HKayed Oct 22, 2024
abb9c5f
ew-1009: adapter tests implemented
HKayed Oct 22, 2024
0cd0562
ew-1009: usecase implemented
HKayed Oct 22, 2024
5e1e7db
ew-1009: mapper tests implemented
HKayed Oct 22, 2024
def768a
ew-1009: CardClientModule tests implemented
HKayed Oct 22, 2024
2a117d3
ew-1009: review comments fixed
HKayed Oct 22, 2024
9acca0a
Merge branch 'main' into EW-1009
Fshmit Oct 23, 2024
caede6f
Merge branch 'main' into EW-1009
MajedAlaitwniCap Oct 23, 2024
3bcdde9
Merge branch 'main' into EW-1009
MajedAlaitwniCap Oct 23, 2024
63b323f
ew-1009: few changes for unit tests is export service
HKayed Oct 23, 2024
e6ee88f
ew-1009: nullable types added to DTOs
HKayed Oct 24, 2024
0c2af99
EW-1029 adding additional information for HTTP error logs (#5305)
psachmann Oct 24, 2024
e9a18b8
BC-8311 - fix circular dependency between modules (#5311)
SevenWaysDP Oct 24, 2024
4968b04
ew-1009: mapper unit tests added
HKayed Oct 24, 2024
43e43a0
ew-1009: removed comments
HKayed Oct 24, 2024
2981b2f
ew-1009: test added for empty elements
HKayed Oct 24, 2024
375279b
ew-1009: removed hard coded string
HKayed Oct 24, 2024
29aeb7a
ew-1009: modified variable name
HKayed Oct 24, 2024
76d28aa
ew-1009: sonar coverage exclusion added
HKayed Oct 25, 2024
de69e73
ew-1009: added handling default case for switch statement
HKayed Oct 25, 2024
7979094
ew-1009: removed unneeded comments and added solution for unreachable…
HKayed Oct 25, 2024
8485ce4
ew-1009: trial 1, removing return
HKayed Oct 25, 2024
3989842
ew-1009: trial 1 removing return
HKayed Oct 25, 2024
9e602c6
ew-1009: modified mapper to include only one switch statement
HKayed Oct 25, 2024
7a36b36
ew-1009: removed unneeded hardcoded strings
HKayed Oct 25, 2024
d7d338c
ew-1009: test issue solved
HKayed Oct 25, 2024
5017ddb
ew-1009: property type changed
HKayed Oct 25, 2024
df45278
ew-1009: review comments
HKayed Oct 25, 2024
c417e47
ew-1009: unnecessary space removed
HKayed Oct 28, 2024
548fdf8
BC-8312 - fix state for External Secret for TLDraw server (#5312)
mamutmk5 Oct 24, 2024
9b20e70
EW-1008 Decouple lesson dependency from common-cartridge module (#5300)
MajedAlaitwniCap Oct 25, 2024
012a285
N21-2167 preferred tools for boards (#5282)
MBergCap Oct 25, 2024
5c633de
ew-1009: Modified files per review comments
HKayed Oct 28, 2024
db0f218
ew-1009: changes to test file structure according to review
HKayed Oct 28, 2024
9621e71
Merge branch 'main' into EW-1009
HKayed Oct 28, 2024
29f0b68
ew-1009: fixed tests structure and added describe when blocks
HKayed Oct 28, 2024
efe39d2
ew-1009: faker used where needed
HKayed Oct 28, 2024
504ecac
ew-1009: Repositioned test arrange to be in the describe block not th…
HKayed Oct 28, 2024
8b22961
ew-1009: fix according to review
HKayed Oct 28, 2024
2d7d8e5
EW-1009 modified test structure of card mapper
Fshmit Oct 28, 2024
de7e9f5
Merge branch 'main' into EW-1009
MajedAlaitwniCap Oct 28, 2024
80798ae
ew-1009: changes according to 2nd review
HKayed Oct 29, 2024
3fe4be3
ew-1009
HKayed Oct 29, 2024
073725e
ew-1009: removed test endpoint method in controller and usecase
HKayed Oct 29, 2024
0504b10
ew-1009:
HKayed Oct 29, 2024
c4f167c
ew-1009: review change
HKayed Oct 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You can run the script with a parameter, which is the path to the controller you

For example:
```bash
node ./scripts/filter-spec.js /courses
node ./scripts/filter_spec-apis.js /courses
```
The execution of the script will generate a new file in the script folder called **filtered-spec.json** with the filtered specification to the controller, you have passed as a parameter. This file should be used to generate the client code for the controller you want to use and should be **deleted** after that.
This script is also able to just select used models and operations from the swagger specification. Unused models will be ignored.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { faker } from '@faker-js/faker';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { REQUEST } from '@nestjs/core';
import { Test, TestingModule } from '@nestjs/testing';
import { AxiosResponse } from 'axios';
import { Request } from 'express';
import { UnauthorizedException } from '@nestjs/common';
import { CardListResponse, CardResponse } from './cards-api-client/models';
import { CardClientAdapter } from './card-client.adapter';
import { BoardCardApi } from './cards-api-client';

const jwtToken = faker.string.uuid();
MajedAlaitwniCap marked this conversation as resolved.
Show resolved Hide resolved

describe(CardClientAdapter.name, () => {
let module: TestingModule;
let adapterUnderTest: CardClientAdapter;
let cardApiMock: DeepMocked<BoardCardApi>;

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
CardClientAdapter,
{
provide: BoardCardApi,
useValue: createMock<BoardCardApi>(),
},
{
provide: REQUEST,
useValue: createMock<Request>({
headers: {
authorization: `Bearer ${jwtToken}`,
},
}),
},
],
}).compile();
adapterUnderTest = module.get(CardClientAdapter);
cardApiMock = module.get(BoardCardApi);
});

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

afterEach(() => {
jest.resetAllMocks();
});

it('CardClientAdapter should be defind', () => {
expect(adapterUnderTest).toBeDefined();
});

describe('getAllBoardCardsByIds', () => {
describe('when getAllBoardCardsByIds is called', () => {
const setup = () => {
const cardResponseData: CardResponse[] = [];
const data: CardListResponse = { data: cardResponseData };
const response = createMock<AxiosResponse<CardListResponse>>({
data,
});

cardApiMock.cardControllerGetCards.mockResolvedValue(response);

return faker.string.uuid();
};
it('it should return a list of card response', async () => {
MajedAlaitwniCap marked this conversation as resolved.
Show resolved Hide resolved
const ids: Array<string> = new Array<string>(setup());
await adapterUnderTest.getAllBoardCardsByIds(ids);
expect(cardApiMock.cardControllerGetCards).toHaveBeenCalled();
});
});
});

describe('When no JWT token is found', () => {
const setup = () => {
const ids: Array<string> = new Array<string>(faker.string.uuid());
const request = createMock<Request>({
headers: {},
});

const adapter: CardClientAdapter = new CardClientAdapter(cardApiMock, request);

return { ids, adapter };
};

it('should throw an UnauthorizedError', async () => {
const { ids, adapter } = setup();

await expect(adapter.getAllBoardCardsByIds(ids)).rejects.toThrowError(UnauthorizedException);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import { extractJwtFromHeader } from '@shared/common';
import { RawAxiosRequestConfig } from 'axios';
import { Request } from 'express';
import { REQUEST } from '@nestjs/core';
import { BoardCardApi } from './cards-api-client';
import { CardListResponseDto } from './dto/card-list-response.dto';
import { CardResponseMapper } from './mapper/card-response.mapper';

@Injectable()
export class CardClientAdapter {
constructor(private readonly boardCardApi: BoardCardApi, @Inject(REQUEST) private request: Request) {}

public async getAllBoardCardsByIds(cardsIds: string[]): Promise<CardListResponseDto> {
const options = this.createOptionParams();
const getBoardCardsResponse = await this.boardCardApi
.cardControllerGetCards(cardsIds, options)
.then((response) => response.data);

return CardResponseMapper.mapToCardListResponseDto(getBoardCardsResponse);
}

private createOptionParams(): RawAxiosRequestConfig {
const jwt = this.getJwt();
const options: RawAxiosRequestConfig = { headers: { authorization: `Bearer ${jwt}` } };

return options;
}

private getJwt(): string {
const jwt = extractJwtFromHeader(this.request) ?? this.request.headers.authorization;

if (!jwt) {
throw new UnauthorizedException('No JWT found in request');
}

return jwt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ConfigurationParameters } from './cards-api-client';

export interface CardClientConfig extends ConfigurationParameters {
basePath?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CardClientModule } from './card-client.module';
import { CardClientAdapter } from './card-client.adapter';

describe('CardClientModule', () => {
let module: TestingModule;

beforeAll(async () => {
module = await Test.createTestingModule({
imports: [
CardClientModule.register({
basePath: 'http://localhost:3030/api/v3',
}),
],
}).compile();
});

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

describe('when module is initialized', () => {
it('should have the CardClientAdapter defined', () => {
const cardClientAdapter = module.get(CardClientAdapter);
expect(cardClientAdapter).toBeDefined();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DynamicModule, Module } from '@nestjs/common';
import { CardClientConfig } from './card-client.config';
import { CardClientAdapter } from './card-client.adapter';
import { BoardCardApi, Configuration } from './cards-api-client';

@Module({})
export class CardClientModule {
static register(config: CardClientConfig): DynamicModule {
const providers = [
CardClientAdapter,
{
provide: BoardCardApi,
useFactory: () => {
const configuration = new Configuration(config);
return new BoardCardApi(configuration);
},
},
];
return {
module: CardClientModule,
providers,
exports: [CardClientAdapter],
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.gitignore
.npmignore
api.ts
api/board-card-api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
models/api-validation-error.ts
models/card-controller-create-element201-response.ts
models/card-list-response.ts
models/card-response-elements-inner.ts
models/card-response.ts
models/collaborative-text-editor-element-response.ts
models/content-element-type.ts
models/create-content-element-body-params.ts
models/deleted-element-content.ts
models/deleted-element-response.ts
models/drawing-element-content.ts
models/drawing-element-response.ts
models/external-tool-element-content.ts
models/external-tool-element-response.ts
models/file-element-content.ts
models/file-element-response.ts
models/index.ts
models/link-element-content.ts
models/link-element-response.ts
models/move-card-body-params.ts
models/rename-body-params.ts
models/rich-text-element-content.ts
models/rich-text-element-response.ts
models/set-height-body-params.ts
models/submission-container-element-content.ts
models/submission-container-element-response.ts
models/timestamps-response.ts
models/visibility-settings-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* tslint:disable */
/* eslint-disable */
/**
* Schulcloud-Verbund-Software Server API
* This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1.
*
* The version of the OpenAPI document: 3.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



export * from './api/board-card-api';

Loading
Loading