Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/N21-2149-merlin-bibliothek-eleme…
Browse files Browse the repository at this point in the history
…nt' into N21-2149-merlin-bibliothek-element

# Conflicts:
#	apps/server/src/modules/tool/tool-launch/mapper/tool-launch.mapper.spec.ts
#	backup/setup/external-tools.json
  • Loading branch information
mrikallab committed Nov 6, 2024
2 parents fa8573d + ac988e9 commit 91c67b2
Show file tree
Hide file tree
Showing 110 changed files with 3,024 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ data:
"upsert": true
}
);'
mongosh $DATABASE__URL --quiet --eval 'db.getCollection("external-tools").updateOne(
{
"name": "Merlin Bibliothek",
},
{ $set: {
"config_secret": "'$CTL_SEED_SECRET_MERLIN'",
} },
{
"upsert": true
}
);'
echo "Inserted ctl seed data secrets to external-tools."

# ========== End of the CTL seed data configuration section.
Expand Down
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';

describe(CardClientAdapter.name, () => {
const jwtToken = faker.string.alphanumeric(20);
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 () => {
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

0 comments on commit 91c67b2

Please sign in to comment.