Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -11,6 +11,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { DateToString } from '@testing/date-to-string';
import { UserAndAccountTestFactory } from '@testing/factory/user-and-account.test.factory';
import { TestApiClient } from '@testing/test-api-client';
import { TestConfigHelper } from '@testing/test-config.helper';
import { BoardExternalReferenceType, BoardLayout, MediaBoardColors } from '../../../domain';
import { BoardNodeEntity } from '../../../repo';
import {
Expand All @@ -33,6 +34,7 @@ describe('Media Board (API)', () => {
let app: INestApplication;
let em: EntityManager;
let testApiClient: TestApiClient;
let testConfigHelper: TestConfigHelper<ServerConfig>;

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -43,17 +45,23 @@ describe('Media Board (API)', () => {
await app.init();
em = module.get(EntityManager);
testApiClient = new TestApiClient(app, baseRouteName);

const config = serverConfig();
testConfigHelper = new TestConfigHelper(config);
});

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

afterEach(() => {
testConfigHelper.reset();
});

describe('[GET] /media-boards/me', () => {
describe('when a valid user accesses their media board', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

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

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

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

describe('when the user is invalid', () => {
const setup = () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
};

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

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

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

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

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

describe('when the user is invalid', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

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

describe('when the user is unauthorized', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

describe('when the user is invalid', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

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

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

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

describe('when a licensing feature is enabled', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
config.FEATURE_SCHULCONNEX_MEDIA_LICENSE_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);
testConfigHelper.set('FEATURE_SCHULCONNEX_MEDIA_LICENSE_ENABLED', true);

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

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

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

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

describe('when the user is unauthorized', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

describe('when the user is invalid', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

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

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

describe('when the user is unauthorized', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

describe('when the user is invalid', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

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

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

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

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

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

describe('when the user is unauthorized', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

describe('when the user is invalid', () => {
const setup = async () => {
const config: ServerConfig = serverConfig();
config.FEATURE_MEDIA_SHELF_ENABLED = true;
testConfigHelper.set('FEATURE_MEDIA_SHELF_ENABLED', true);

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

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

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

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

Expand Down
108 changes: 0 additions & 108 deletions apps/server/src/modules/files-storage/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion apps/server/src/modules/server/server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,5 @@ const config: ServerConfig = {
FEATURE_MEDIA_METADATA_SYNC_ENABLED: Configuration.get('FEATURE_MEDIA_METADATA_SYNC_ENABLED') as boolean,
};

export const serverConfig = () => config;
export const serverConfig = (): ServerConfig => config;
export const SERVER_CONFIG_TOKEN = 'SERVER_CONFIG_TOKEN';
20 changes: 20 additions & 0 deletions apps/server/src/testing/test-config.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class TestConfigHelper<T, K extends keyof T = Extract<keyof T, string>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the name suffix Helper. Can we just call the class TestConfig?

private originConfigs = new Map<K, T[K]>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use the singular originalConfig.


constructor(private readonly config: T) {}
Copy link
Contributor

@uidp uidp Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand the purpose of this class is to first initialize a test configuration and then later be able to reset it to its initial state? If that's the case wouldn't it be a good idea when we copy the initial config to originalConfig in the constructor? The copy in the set() method is quite hard to understand IMHO.


public set(key: K, value: T[K]): void {
if (Object.prototype.hasOwnProperty.call(this.config, key)) {
Copy link
Contributor

@uidp uidp Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this runtime-check really necessary? Or can we just rely on the type of the config (which basically defines which properties exist)?
Besides that: Wouldn't be this.config.hasOwnProperty() sufficient? Why the additional function binding?

this.originConfigs.set(key, this.config[key]);
this.config[key] = value;
}
}

public reset(): void {
this.originConfigs.forEach((value, key) => {
this.config[key] = value;
});

this.originConfigs.clear();
}
}
Loading
Loading