Skip to content

Commit eb5f88d

Browse files
authored
BC-9076 Move documentation to seperate docu repo. (#5557)
* Move files-storage documentation to docu repo. * Move configuration documentation to docu repo. * Add config test helper with usage by one example.
1 parent aa812ed commit eb5f88d

File tree

5 files changed

+53
-474
lines changed

5 files changed

+53
-474
lines changed

apps/server/src/modules/board/controller/media-board/api-test/media-board.api.spec.ts

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Test, TestingModule } from '@nestjs/testing';
1111
import { DateToString } from '@testing/date-to-string';
1212
import { UserAndAccountTestFactory } from '@testing/factory/user-and-account.test.factory';
1313
import { TestApiClient } from '@testing/test-api-client';
14+
import { TestConfigHelper } from '@testing/test-config.helper';
1415
import { BoardExternalReferenceType, BoardLayout, MediaBoardColors } from '../../../domain';
1516
import { BoardNodeEntity } from '../../../repo';
1617
import {
@@ -33,6 +34,7 @@ describe('Media Board (API)', () => {
3334
let app: INestApplication;
3435
let em: EntityManager;
3536
let testApiClient: TestApiClient;
37+
let testConfigHelper: TestConfigHelper<ServerConfig>;
3638

3739
beforeAll(async () => {
3840
const module: TestingModule = await Test.createTestingModule({
@@ -43,17 +45,23 @@ describe('Media Board (API)', () => {
4345
await app.init();
4446
em = module.get(EntityManager);
4547
testApiClient = new TestApiClient(app, baseRouteName);
48+
49+
const config = serverConfig();
50+
testConfigHelper = new TestConfigHelper(config);
4651
});
4752

4853
afterAll(async () => {
4954
await app.close();
5055
});
5156

57+
afterEach(() => {
58+
testConfigHelper.reset();
59+
});
60+
5261
describe('[GET] /media-boards/me', () => {
5362
describe('when a valid user accesses their media board', () => {
5463
const setup = async () => {
55-
const config: ServerConfig = serverConfig();
56-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
64+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
5765

5866
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
5967

@@ -125,8 +133,7 @@ describe('Media Board (API)', () => {
125133

126134
describe('when the media board feature is disabled', () => {
127135
const setup = async () => {
128-
const config: ServerConfig = serverConfig();
129-
config.FEATURE_MEDIA_SHELF_ENABLED = false;
136+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', false);
130137

131138
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
132139

@@ -157,8 +164,7 @@ describe('Media Board (API)', () => {
157164

158165
describe('when the user is invalid', () => {
159166
const setup = () => {
160-
const config: ServerConfig = serverConfig();
161-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
167+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
162168
};
163169

164170
it('should return unauthorized', async () => {
@@ -180,8 +186,7 @@ describe('Media Board (API)', () => {
180186
describe('[POST] /media-boards/:boardId/media-lines', () => {
181187
describe('when a valid user creates a line on their media board', () => {
182188
const setup = async () => {
183-
const config: ServerConfig = serverConfig();
184-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
189+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
185190

186191
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
187192

@@ -224,8 +229,7 @@ describe('Media Board (API)', () => {
224229

225230
describe('when the media board feature is disabled', () => {
226231
const setup = async () => {
227-
const config: ServerConfig = serverConfig();
228-
config.FEATURE_MEDIA_SHELF_ENABLED = false;
232+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', false);
229233

230234
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
231235
const mediaBoard = mediaBoardEntityFactory.build({
@@ -263,8 +267,7 @@ describe('Media Board (API)', () => {
263267

264268
describe('when the user is invalid', () => {
265269
const setup = async () => {
266-
const config: ServerConfig = serverConfig();
267-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
270+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
268271

269272
const mediaBoard = mediaBoardEntityFactory.build({
270273
context: {
@@ -300,8 +303,7 @@ describe('Media Board (API)', () => {
300303
describe('[GET] /media-board/:boardId/media-available-line', () => {
301304
describe('when a valid user requests their available media line', () => {
302305
const setup = async () => {
303-
const config: ServerConfig = serverConfig();
304-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
306+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
305307

306308
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
307309

@@ -390,8 +392,7 @@ describe('Media Board (API)', () => {
390392

391393
describe('when the user is unauthorized', () => {
392394
const setup = async () => {
393-
const config: ServerConfig = serverConfig();
394-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
395+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
395396

396397
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
397398

@@ -427,8 +428,7 @@ describe('Media Board (API)', () => {
427428

428429
describe('when the user is invalid', () => {
429430
const setup = async () => {
430-
const config: ServerConfig = serverConfig();
431-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
431+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
432432

433433
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
434434

@@ -467,8 +467,7 @@ describe('Media Board (API)', () => {
467467

468468
describe('when the media board feature is disabled', () => {
469469
const setup = async () => {
470-
const config: ServerConfig = serverConfig();
471-
config.FEATURE_MEDIA_SHELF_ENABLED = false;
470+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', false);
472471

473472
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
474473

@@ -507,9 +506,8 @@ describe('Media Board (API)', () => {
507506

508507
describe('when a licensing feature is enabled', () => {
509508
const setup = async () => {
510-
const config: ServerConfig = serverConfig();
511-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
512-
config.FEATURE_SCHULCONNEX_MEDIA_LICENSE_ENABLED = true;
509+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
510+
testConfigHelper.set('FEATURE_SCHULCONNEX_MEDIA_LICENSE_ENABLED', true);
513511

514512
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
515513

@@ -624,8 +622,7 @@ describe('Media Board (API)', () => {
624622
describe('[GET] /media-board/:boardId/media-available-line/collapse', () => {
625623
describe('when a valid user requests their available media line', () => {
626624
const setup = async () => {
627-
const config: ServerConfig = serverConfig();
628-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
625+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
629626

630627
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
631628

@@ -697,8 +694,7 @@ describe('Media Board (API)', () => {
697694

698695
describe('when the user is unauthorized', () => {
699696
const setup = async () => {
700-
const config: ServerConfig = serverConfig();
701-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
697+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
702698

703699
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
704700

@@ -739,8 +735,7 @@ describe('Media Board (API)', () => {
739735

740736
describe('when the user is invalid', () => {
741737
const setup = async () => {
742-
const config: ServerConfig = serverConfig();
743-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
738+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
744739

745740
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
746741

@@ -786,8 +781,7 @@ describe('Media Board (API)', () => {
786781
describe('[GET] /media-board/:boardId/media-available-line/color', () => {
787782
describe('when a valid user requests their available media line', () => {
788783
const setup = async () => {
789-
const config: ServerConfig = serverConfig();
790-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
784+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
791785

792786
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
793787

@@ -856,8 +850,7 @@ describe('Media Board (API)', () => {
856850

857851
describe('when the user is unauthorized', () => {
858852
const setup = async () => {
859-
const config: ServerConfig = serverConfig();
860-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
853+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
861854

862855
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
863856

@@ -895,8 +888,7 @@ describe('Media Board (API)', () => {
895888

896889
describe('when the user is invalid', () => {
897890
const setup = async () => {
898-
const config: ServerConfig = serverConfig();
899-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
891+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
900892

901893
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
902894

@@ -937,8 +929,7 @@ describe('Media Board (API)', () => {
937929

938930
describe('when the media board feature is disabled', () => {
939931
const setup = async () => {
940-
const config: ServerConfig = serverConfig();
941-
config.FEATURE_MEDIA_SHELF_ENABLED = false;
932+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', false);
942933

943934
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
944935

@@ -981,8 +972,7 @@ describe('Media Board (API)', () => {
981972
describe('[GET] /media-board/:boardId/layout', () => {
982973
describe('when a valid user set layout for media board', () => {
983974
const setup = async () => {
984-
const config: ServerConfig = serverConfig();
985-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
975+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
986976

987977
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
988978

@@ -1023,8 +1013,7 @@ describe('Media Board (API)', () => {
10231013

10241014
describe('when the user is unauthorized', () => {
10251015
const setup = async () => {
1026-
const config: ServerConfig = serverConfig();
1027-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
1016+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
10281017

10291018
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
10301019

@@ -1060,8 +1049,7 @@ describe('Media Board (API)', () => {
10601049

10611050
describe('when the user is invalid', () => {
10621051
const setup = async () => {
1063-
const config: ServerConfig = serverConfig();
1064-
config.FEATURE_MEDIA_SHELF_ENABLED = true;
1052+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
10651053

10661054
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
10671055

@@ -1100,8 +1088,7 @@ describe('Media Board (API)', () => {
11001088

11011089
describe('when the media board feature is disabled', () => {
11021090
const setup = async () => {
1103-
const config: ServerConfig = serverConfig();
1104-
config.FEATURE_MEDIA_SHELF_ENABLED = false;
1091+
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', false);
11051092

11061093
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent();
11071094

apps/server/src/modules/files-storage/README.md

Lines changed: 0 additions & 108 deletions
This file was deleted.

apps/server/src/modules/server/server.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,5 @@ const config: ServerConfig = {
351351
FEATURE_MEDIA_METADATA_SYNC_ENABLED: Configuration.get('FEATURE_MEDIA_METADATA_SYNC_ENABLED') as boolean,
352352
};
353353

354-
export const serverConfig = () => config;
354+
export const serverConfig = (): ServerConfig => config;
355355
export const SERVER_CONFIG_TOKEN = 'SERVER_CONFIG_TOKEN';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export class TestConfigHelper<T, K extends keyof T = Extract<keyof T, string>> {
2+
private originConfigs = new Map<K, T[K]>();
3+
4+
constructor(private readonly config: T) {}
5+
6+
public set(key: K, value: T[K]): void {
7+
if (Object.prototype.hasOwnProperty.call(this.config, key)) {
8+
this.originConfigs.set(key, this.config[key]);
9+
this.config[key] = value;
10+
}
11+
}
12+
13+
public reset(): void {
14+
this.originConfigs.forEach((value, key) => {
15+
this.config[key] = value;
16+
});
17+
18+
this.originConfigs.clear();
19+
}
20+
}

0 commit comments

Comments
 (0)