Skip to content

Commit

Permalink
BC-8510 - Wrong handling of WITH_TLDRAW2 by ConfigModule (#5383)
Browse files Browse the repository at this point in the history
* BC-8510 - Add Tldraw client configuration to board collaboration settings

* BC-8510 - Remove WITH_TLDRAW2 configuration and related logic from Tldraw client
  • Loading branch information
SevenWaysDP authored Dec 6, 2024
1 parent 19821f8 commit 8a4deae
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 46 deletions.
2 changes: 2 additions & 0 deletions apps/server/src/modules/board/board-collaboration.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Configuration } from '@hpi-schul-cloud/commons';
import { JwtAuthGuardConfig } from '@infra/auth-guard';
import { Algorithm } from 'jsonwebtoken';
import { getTldrawClientConfig } from '../tldraw-client';

export interface BoardCollaborationConfig extends JwtAuthGuardConfig {
NEST_LOG_LEVEL: string;
Expand All @@ -13,6 +14,7 @@ const boardCollaborationConfig: BoardCollaborationConfig = {
JWT_PUBLIC_KEY: (Configuration.get('JWT_PUBLIC_KEY') as string).replace(/\\n/g, '\n'),
JWT_SIGNING_ALGORITHM: Configuration.get('JWT_SIGNING_ALGORITHM') as Algorithm,
SC_DOMAIN: Configuration.get('SC_DOMAIN') as string,
...getTldrawClientConfig(),
};

export const config = () => boardCollaborationConfig;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface TldrawClientConfig {
TLDRAW_ADMIN_API_CLIENT_BASE_URL: string;
TLDRAW_ADMIN_API_CLIENT_API_KEY: string;
WITH_TLDRAW2: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ describe(DrawingElementAdapterService.name, () => {
});

describe('deleteDrawingBinData', () => {
describe('when WITH_TLDRAW2 env var is true', () => {
describe('when deleteDrawingBinData is called', () => {
const setup = () => {
const apiKey = 'a4a20e6a-8036-4603-aba6-378006fedce2';
const baseUrl = 'http://localhost:3349';
const WITH_TLDRAW2 = true;

configService.get.mockReturnValueOnce(baseUrl);
configService.get.mockReturnValueOnce(WITH_TLDRAW2);
configService.get.mockReturnValueOnce(apiKey);
httpService.delete.mockReturnValue(
of(
Expand All @@ -81,37 +79,5 @@ describe(DrawingElementAdapterService.name, () => {
});
});
});

describe('when WITH_TLDRAW2 env var is false', () => {
const setup = () => {
const apiKey = 'a4a20e6a-8036-4603-aba6-378006fedce2';
const baseUrl = 'http://localhost:3349';
const WITH_TLDRAW2 = false;
configService.get.mockReturnValueOnce(baseUrl);
configService.get.mockReturnValueOnce(WITH_TLDRAW2);
configService.get.mockReturnValueOnce(apiKey);
httpService.delete.mockReturnValue(
of(
axiosResponseFactory.build({
data: '',
status: HttpStatus.OK,
statusText: 'OK',
})
)
);

return { apiKey, baseUrl };
};

it('should call axios delete method', async () => {
const { apiKey, baseUrl } = setup();

await service.deleteDrawingBinData('test');

expect(httpService.delete).toHaveBeenCalledWith(`${baseUrl}/api/v3/tldraw-document/test`, {
headers: { 'X-Api-Key': apiKey, Accept: 'Application/json' },
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export class DrawingElementAdapterService {

async deleteDrawingBinData(parentId: string): Promise<void> {
const baseUrl = this.configService.get<string>('TLDRAW_ADMIN_API_CLIENT_BASE_URL');
const isTlDraw2 = this.configService.get<boolean>('WITH_TLDRAW2');
const endpointUrl = isTlDraw2 ? '/api/tldraw-document' : '/api/v3/tldraw-document';
const endpointUrl = '/api/tldraw-document';
const tldrawDocumentEndpoint = new URL(endpointUrl, baseUrl).toString();

await firstValueFrom(this.httpService.delete(`${tldrawDocumentEndpoint}/${parentId}`, this.defaultHeaders()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ describe(getTldrawClientConfig.name, () => {

Configuration.set('TLDRAW_ADMIN_API_CLIENT__BASE_URL', baseUrl);
Configuration.set('TLDRAW_ADMIN_API_CLIENT__API_KEY', apiKey);
Configuration.set('WITH_TLDRAW2', true);

const expectedConfig = {
TLDRAW_ADMIN_API_CLIENT_BASE_URL: baseUrl,
TLDRAW_ADMIN_API_CLIENT_API_KEY: apiKey,
WITH_TLDRAW2: true,
};

return { expectedConfig };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ export const getTldrawClientConfig = (): TldrawClientConfig => {
return {
TLDRAW_ADMIN_API_CLIENT_BASE_URL: Configuration.get('TLDRAW_ADMIN_API_CLIENT__BASE_URL') as string,
TLDRAW_ADMIN_API_CLIENT_API_KEY: Configuration.get('TLDRAW_ADMIN_API_CLIENT__API_KEY') as string,
WITH_TLDRAW2: Configuration.get('WITH_TLDRAW2') as boolean,
};
};
5 changes: 0 additions & 5 deletions config/default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1648,11 +1648,6 @@
"default": "http://localhost:3349",
"description": "Address for tldraw management app"
},
"WITH_TLDRAW2": {
"type": "boolean",
"default": false,
"description": "Enables tldraw2 feature"
},
"SCHULCONNEX_CLIENT": {
"type": "object",
"description": "Configuration of the schulcloud's schulconnex client.",
Expand Down

0 comments on commit 8a4deae

Please sign in to comment.