-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/N21-2149-merlin-bibliothek-eleme…
…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
Showing
110 changed files
with
3,024 additions
and
502 deletions.
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
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
92 changes: 92 additions & 0 deletions
92
.../modules/common-cartridge/common-cartridge-client/card-client/card-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,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); | ||
}); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
...r/src/modules/common-cartridge/common-cartridge-client/card-client/card-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,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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...er/src/modules/common-cartridge/common-cartridge-client/card-client/card-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,5 @@ | ||
import { ConfigurationParameters } from './cards-api-client'; | ||
|
||
export interface CardClientConfig extends ConfigurationParameters { | ||
basePath?: string; | ||
} |
28 changes: 28 additions & 0 deletions
28
...c/modules/common-cartridge/common-cartridge-client/card-client/card-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,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(); | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...er/src/modules/common-cartridge/common-cartridge-client/card-client/card-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,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], | ||
}; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../modules/common-cartridge/common-cartridge-client/card-client/cards-api-client/.gitignore
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,4 @@ | ||
wwwroot/*.js | ||
node_modules | ||
typings | ||
dist |
1 change: 1 addition & 0 deletions
1
.../modules/common-cartridge/common-cartridge-client/card-client/cards-api-client/.npmignore
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 @@ | ||
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm |
23 changes: 23 additions & 0 deletions
23
...-cartridge/common-cartridge-client/card-client/cards-api-client/.openapi-generator-ignore
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,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 |
37 changes: 37 additions & 0 deletions
37
...n-cartridge/common-cartridge-client/card-client/cards-api-client/.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 |
---|---|---|
@@ -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 |
18 changes: 18 additions & 0 deletions
18
.../src/modules/common-cartridge/common-cartridge-client/card-client/cards-api-client/api.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,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'; | ||
|
Oops, something went wrong.