From f40c26f11b2dd019c587448ec436707408b6fa9f Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 13 Sep 2023 09:10:30 +0200 Subject: [PATCH 1/3] Delete two unused services --- .../gateways/autoupdate-adapter.service.spec.ts | 16 ---------------- .../app/gateways/autoupdate-adapter.service.ts | 8 -------- .../applause-bar-display.service.spec.ts | 16 ---------------- .../components/applause-bar-display.service.ts | 8 -------- 4 files changed, 48 deletions(-) delete mode 100644 client/src/app/gateways/autoupdate-adapter.service.spec.ts delete mode 100644 client/src/app/gateways/autoupdate-adapter.service.ts delete mode 100644 client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.spec.ts delete mode 100644 client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.ts diff --git a/client/src/app/gateways/autoupdate-adapter.service.spec.ts b/client/src/app/gateways/autoupdate-adapter.service.spec.ts deleted file mode 100644 index 952c6df470..0000000000 --- a/client/src/app/gateways/autoupdate-adapter.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { AutoupdateAdapterService } from './autoupdate-adapter.service'; - -xdescribe(`AutoupdateAdapterService`, () => { - let service: AutoupdateAdapterService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(AutoupdateAdapterService); - }); - - it(`should be created`, () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/client/src/app/gateways/autoupdate-adapter.service.ts b/client/src/app/gateways/autoupdate-adapter.service.ts deleted file mode 100644 index 440cc0e364..0000000000 --- a/client/src/app/gateways/autoupdate-adapter.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable({ - providedIn: `root` -}) -export class AutoupdateAdapterService { - constructor() {} -} diff --git a/client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.spec.ts b/client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.spec.ts deleted file mode 100644 index 6be545b73d..0000000000 --- a/client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { ApplauseBarDisplayService } from './applause-bar-display.service'; - -xdescribe(`ApplauseBarDisplayService`, () => { - let service: ApplauseBarDisplayService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(ApplauseBarDisplayService); - }); - - it(`should be created`, () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.ts b/client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.ts deleted file mode 100644 index a73d8bd57c..0000000000 --- a/client/src/app/site/pages/meetings/pages/interaction/modules/interaction-container/components/applause-bar-display.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable({ - providedIn: `root` -}) -export class ApplauseBarDisplayService { - constructor() {} -} From 56163cf62ff2a47a36f250b2823943e7916d120f Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 13 Sep 2023 14:49:18 +0200 Subject: [PATCH 2/3] Start implementing tests for MeetingSettingsDefinitionService --- client/cli/generate-settings-defaults.ts | 2 +- .../meeting-settings-group-list.component.ts | 2 +- ...eeting-settings-definition.service.spec.ts | 205 +++++++++++++++++- .../meeting-settings-definition.service.ts | 82 +++---- 4 files changed, 244 insertions(+), 47 deletions(-) diff --git a/client/cli/generate-settings-defaults.ts b/client/cli/generate-settings-defaults.ts index 0100020b33..6245fb98a0 100644 --- a/client/cli/generate-settings-defaults.ts +++ b/client/cli/generate-settings-defaults.ts @@ -26,7 +26,7 @@ const FILE_TEMPLATE = dedent` const provider = new MeetingSettingsDefinitionService(); let content = FILE_TEMPLATE + '\n'; - for (const [key, value] of Object.entries(provider.getSettingsMap())) { + for (const [key, value] of Object.entries(provider.settingsMap)) { const defaultValue = meeting[key].default; if (defaultValue !== undefined) { provider.validateDefault(key, defaultValue); diff --git a/client/src/app/site/pages/meetings/pages/meeting-settings/pages/meeting-settings-group-list/components/meeting-settings-group-list/meeting-settings-group-list.component.ts b/client/src/app/site/pages/meetings/pages/meeting-settings/pages/meeting-settings-group-list/components/meeting-settings-group-list/meeting-settings-group-list.component.ts index bd9bf9f2f1..9b63b2bd8c 100644 --- a/client/src/app/site/pages/meetings/pages/meeting-settings/pages/meeting-settings-group-list/components/meeting-settings-group-list/meeting-settings-group-list.component.ts +++ b/client/src/app/site/pages/meetings/pages/meeting-settings/pages/meeting-settings-group-list/components/meeting-settings-group-list/meeting-settings-group-list.component.ts @@ -24,7 +24,7 @@ export class MeetingSettingsGroupListComponent extends BaseMeetingComponent { ) { super(componentServiceCollector, translate); - this.groups = this.meetingSettingsDefinitionProvider.getSettings(); + this.groups = this.meetingSettingsDefinitionProvider.settings; } /** diff --git a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts index 0d48fb545f..36b479f3c2 100644 --- a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts +++ b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts @@ -1,16 +1,211 @@ import { TestBed } from '@angular/core/testing'; +import { meetingSettingsDefaults } from 'src/app/domain/definitions/meeting-settings-defaults'; +import { Settings } from 'src/app/domain/models/meetings/meeting'; +import { Group } from 'src/app/domain/models/users/group'; -import { MeetingSettingsDefinitionService } from './meeting-settings-definition.service'; +import { MeetingSettingsDefinitionService, SettingsMap } from './meeting-settings-definition.service'; +import { meetingSettings, SettingsGroup, SettingsItem, SettingsType } from './meeting-settings-definitions'; -xdescribe(`MeetingSettingsDefinitionService`, () => { +const fakeSettings: SettingsGroup[] = [ + { + label: `Test setting group`, + icon: `test`, + subgroups: [ + { + label: `Test subgroup`, + settings: [ + { + key: `one` as keyof Settings, + label: `Setting one`, + type: `integer` + }, + { + key: [`two` as keyof Settings, `three` as keyof Settings], + label: `Setting two and three`, + type: `daterange` + }, + { + key: `four` as keyof Settings, + label: `Setting four`, + type: `datetime` + }, + { + key: `five` as keyof Settings, + label: `Setting five`, + type: `date` + }, + { + key: `a` as keyof Settings, + label: `Setting a` + }, + { + key: `b` as keyof Settings, + label: `Setting b`, + type: `string` + }, + { + key: `c` as keyof Settings, + label: `Setting c`, + type: `text` + }, + { + key: `d` as keyof Settings, + label: `Setting d`, + type: `markupText` + }, + { + key: `e` as keyof Settings, + label: `Setting e`, + type: `email` + }, + { + key: `bool` as keyof Settings, + label: `Boolean setting`, + type: `boolean` + }, // + { + key: `groups` as keyof Settings, + label: `Group setting`, + type: `groups` + }, + { + key: `translations` as keyof Settings, + label: `Boolean setting`, + type: `translations` + }, + { + key: `ranking` as keyof Settings, + label: `Boolean setting`, + type: `ranking` + }, + { + key: `choice` as keyof Settings, + label: `Boolean setting`, + type: `choice`, + choices: { + a: `A`, + b: `B`, + c: `C` + } + } + ] + } + ] + } +]; +const fakeSettingsMap: { [key: string]: SettingsItem } = fakeSettings + .flatMap(group => group.subgroups.flatMap(subgroup => subgroup.settings)) + .mapToObject(setting => + (Array.isArray(setting.key) ? setting.key : [setting.key]).mapToObject(key => ({ [key]: setting })) + ); +const fakeSettingsDefaults: { [key: string]: any } = { + ...[`one`, `two`, `four`, `five`].mapToObject((prop, index) => ({ [prop]: index + 1 })), + bool: true, + ...[`a`, `b`, `c`, `d`].mapToObject(letter => ({ [letter]: letter })), + e: `e.mail@email.mail`, + groups: [new Group()], + translations: [], + ranking: [], + choice: `b` +}; +const emptyFakeSettingsDefaults: { [key: string]: any } = {}; + +const typeToDefault: { [type in SettingsType]: any } = { + integer: 0, + boolean: false, + groups: [], + translations: [], + ranking: [], + choice: null, + date: null, + datetime: null, + daterange: [null, null], + string: ``, + text: ``, + markupText: ``, + email: `` +}; + +fdescribe(`MeetingSettingsDefinitionService`, () => { let service: MeetingSettingsDefinitionService; + function mockGetters(haveDefaults = true): void { + spyOnProperty(service, `settings`).and.returnValue(fakeSettings); + spyOnProperty(service, `settingsDefaults`).and.returnValue( + haveDefaults ? fakeSettingsDefaults : emptyFakeSettingsDefaults + ); + spyOnProperty(service, `settingsMap`).and.returnValue(fakeSettingsMap as SettingsMap); + } + beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + providers: [MeetingSettingsDefinitionService] + }); service = TestBed.inject(MeetingSettingsDefinitionService); }); - it(`should be created`, () => { - expect(service).toBeTruthy(); + it(`test getters`, () => { + expect(service.settings).toBe(meetingSettings); + expect(service.settingsDefaults).toBe(meetingSettingsDefaults); + expect(meetingSettings.length).toBeGreaterThan(0); + expect(service.settingsMap).toBeTruthy(); + const indices = Array.from({ length: 4 }, () => Math.floor(Math.random() * 100)); + indices[0] = indices[0] % meetingSettings.length; + const values: any[] = [meetingSettings[indices[0]]]; + const properties = [`subgroups`, `settings`, `key`]; + for (let i = 1; i < 4; i++) { + if (Array.isArray(values[i - 1][properties[i - 1]])) { + indices[i] = indices[i] % values[i - 1][properties[i - 1]].length; + } + values.push( + Array.isArray(values[i - 1][properties[i - 1]]) + ? values[i - 1][properties[i - 1]][indices[i]] + : values[i - 1][properties[i - 1]] + ); + } + expect(service.settingsMap[values[3]]).toBe(values[2]); }); + + it(`test normal get methods`, () => { + mockGetters(); + expect(service.getSettingsGroup(`Test setting group`)).toBe(fakeSettings[0]); + expect(service.getSettingsGroup(`test setting group`)).toBe(fakeSettings[0]); + expect(service.getSettingsKeys()).toEqual( + fakeSettings.flatMap(group => + group.subgroups.flatMap(subgroup => subgroup.settings.flatMap(setting => setting.key)) + ) + ); + }); + + for (const haveDefaults of [true, false]) { + for (const setting of fakeSettings[0].subgroups[0].settings) { + it(`test getDefaultValue for ${setting.type ?? `no given type`}${ + haveDefaults ? `` : ` if there's no defaults` + }`, () => { + mockGetters(haveDefaults); + expect(service.getDefaultValue(setting)).toEqual( + haveDefaults + ? setting.type === `daterange` + ? [2, null] + : fakeSettingsDefaults[Array.isArray(setting.key) ? setting.key[0] : setting.key] + : typeToDefault[setting.type ?? `string`] + ); + }); + const keys = Array.isArray(setting.key) ? setting.key : [setting.key]; + for (let i = 0; i < keys.length; i++) { + it(`test getDefaultValue for ${setting.type ?? `no given type`} with settings keys${ + haveDefaults ? `` : ` if there's no defaults` + } ${i + 1}`, () => { + mockGetters(haveDefaults); + expect(service.getDefaultValue(keys[i])).toEqual( + haveDefaults + ? setting.type === `daterange` + ? [2, null] + : fakeSettingsDefaults[Array.isArray(setting.key) ? setting.key[0] : setting.key] + : typeToDefault[setting.type ?? `string`] + ); + }); + } + } + } }); diff --git a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts index fb9cb0c081..a2f564cb70 100644 --- a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts +++ b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts @@ -4,80 +4,61 @@ import { Settings } from 'src/app/domain/models/meetings/meeting'; import { meetingSettingsDefaults } from '../../../../../domain/definitions/meeting-settings-defaults'; import { meetingSettings, SettingsGroup, SettingsItem } from './meeting-settings-definitions'; -type SettingsMap = { [key in keyof Settings]: SettingsItem }; +export type SettingsMap = { [key in keyof Settings]: SettingsItem }; @Injectable({ providedIn: `root` }) export class MeetingSettingsDefinitionService { - private readonly _settingsMap: SettingsMap; + public get settings(): SettingsGroup[] { + return meetingSettings; + } - public constructor() { - this._settingsMap = this.createSettingsMap(); + public get settingsDefaults(): { + [key: string]: any; + } { + return meetingSettingsDefaults; } - public validateDefault(settingKey: keyof Settings, defaultValue: any): void { - const setting = this.settingsMap[settingKey]; - if ( - ((!setting.type || setting.type === `text`) && typeof defaultValue !== `string`) || - (setting.type === `integer` && typeof defaultValue !== `number`) || - (setting.type === `boolean` && typeof defaultValue !== `boolean`) - ) { - throw new Error(`Invalid default for ${setting.key}: ${defaultValue} (${typeof defaultValue})`); - } - if (setting.type === `choice` && setting.choices && !setting.choices.hasOwnProperty(defaultValue)) { - throw new Error( - `Invalid default for ${setting.key}: ${defaultValue} (valid choices: ${Object.keys(setting.choices)})` - ); - } + public get settingsMap(): SettingsMap { + return this._settingsMap; } - public getSettings(): SettingsGroup[] { - return meetingSettings; + private readonly _settingsMap: SettingsMap; + + public constructor() { + this._settingsMap = this.createSettingsMap(); } public getSettingsGroup(name: string): SettingsGroup | undefined { - return meetingSettings.find(group => group.label.toLowerCase() === name); + return this.settings.find(group => group.label.toLowerCase() === name.toLowerCase()); } public getSettingsKeys(): (keyof Settings)[] { return Object.keys(this.settingsMap) as (keyof Settings)[]; } - public getSettingsMap(): { [key in keyof Settings]: SettingsItem } { - return this.settingsMap; - } - public getDefaultValue(setting: keyof Settings | SettingsItem): any { const settingItem = typeof setting === `string` ? this.settingsMap[setting] : setting; return this.getDefaultValueForItem(settingItem) ?? this.getDefaultValueForType(settingItem); } - private getDefaultValueForItem(item: SettingsItem): any { - const isArray = Array.isArray(item.key); - const value = meetingSettingsDefaults[isArray ? item.key[0] : (item.key as keyof Settings)]; - if (item.type === `daterange`) { - return [value ?? null, meetingSettingsDefaults[item.key[1]] ?? null]; - } - return value; - } - public getDefaultValueForType(setting: SettingsItem): any { switch (setting.type) { case `integer`: return 0; case `boolean`: return false; - case `choice`: - return null; case `groups`: case `translations`: case `ranking`: return []; + case `choice`: + case `date`: case `datetime`: return null; case `daterange`: - return [Date.now(), Date.now()]; + return [null, null]; case `string`: case `text`: case `markupText`: @@ -87,8 +68,29 @@ export class MeetingSettingsDefinitionService { } } - private get settingsMap(): SettingsMap { - return this._settingsMap; + public validateDefault(settingKey: keyof Settings, defaultValue: any): void { + const setting = this.settingsMap[settingKey]; + if ( + ((!setting.type || setting.type === `text`) && typeof defaultValue !== `string`) || + (setting.type === `integer` && typeof defaultValue !== `number`) || + (setting.type === `boolean` && typeof defaultValue !== `boolean`) + ) { + throw new Error(`Invalid default for ${setting.key}: ${defaultValue} (${typeof defaultValue})`); + } + if (setting.type === `choice` && setting.choices && !setting.choices.hasOwnProperty(defaultValue)) { + throw new Error( + `Invalid default for ${setting.key}: ${defaultValue} (valid choices: ${Object.keys(setting.choices)})` + ); + } + } + + private getDefaultValueForItem(item: SettingsItem): any { + const isArray = Array.isArray(item.key); + const value = this.settingsDefaults[isArray ? item.key[0] : (item.key as keyof Settings)]; + if (item.type === `daterange`) { + return [value ?? null, this.settingsDefaults[item.key[1]] ?? null]; + } + return value; } private validateSetting(setting: SettingsItem): void { @@ -101,7 +103,7 @@ export class MeetingSettingsDefinitionService { private createSettingsMap(): SettingsMap { const localSettingsMap: any = {}; - for (const group of meetingSettings) { + for (const group of this.settings) { for (const subgroup of group.subgroups) { for (const setting of subgroup.settings) { this.validateSetting(setting); From 17af2b673daf82003cc62c2ccfcee42304ad6425 Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 13 Sep 2023 17:10:46 +0200 Subject: [PATCH 3/3] Finalize MeetingSettingsDefinitionService test --- ...eeting-settings-definition.service.spec.ts | 74 +++++++++++++++---- .../meeting-settings-definition.service.ts | 14 +++- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts index 36b479f3c2..30bdf3ee4c 100644 --- a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts +++ b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.spec.ts @@ -70,51 +70,76 @@ const fakeSettings: SettingsGroup[] = [ }, { key: `translations` as keyof Settings, - label: `Boolean setting`, + label: `Translation setting`, type: `translations` }, { key: `ranking` as keyof Settings, - label: `Boolean setting`, + label: `Ranking setting`, type: `ranking` }, { - key: `choice` as keyof Settings, - label: `Boolean setting`, + key: `static` as keyof Settings, + label: `Static choice setting`, type: `choice`, choices: { a: `A`, b: `B`, c: `C` } + }, + { + key: `dynamic` as keyof Settings, + label: `Dynamic choice setting`, + type: `choice`, + choicesFunc: { + collection: `model`, + idKey: `id`, + labelKey: `stuff` + } } ] } ] } ]; + const fakeSettingsMap: { [key: string]: SettingsItem } = fakeSettings .flatMap(group => group.subgroups.flatMap(subgroup => subgroup.settings)) + .filter(setting => !!setting) .mapToObject(setting => (Array.isArray(setting.key) ? setting.key : [setting.key]).mapToObject(key => ({ [key]: setting })) ); + const fakeSettingsDefaults: { [key: string]: any } = { ...[`one`, `two`, `four`, `five`].mapToObject((prop, index) => ({ [prop]: index + 1 })), bool: true, ...[`a`, `b`, `c`, `d`].mapToObject(letter => ({ [letter]: letter })), e: `e.mail@email.mail`, groups: [new Group()], - translations: [], - ranking: [], - choice: `b` + translations: { a: `b`, c: `d`, e: `f` }, + ranking: [{ id: 1, entry: `a`, allocation: 2 }], + static: `b`, + dynamic: `s` +}; + +const fakeBrokenSettingsDefaults: { [key: string]: any } = { + ...[`one`, `two`, `four`, `five`].mapToObject(letter => ({ [letter]: letter })), + bool: `not a bool`, + ...[`a`, `b`, `c`, `d`].mapToObject((prop, index) => ({ [prop]: index + 1 })), + e: 3, + groups: true, + translations: `abcdefghijklmnopqrstuvwxyz`, + ranking: 123456, + static: [`d`], + dynamic: 4 }; -const emptyFakeSettingsDefaults: { [key: string]: any } = {}; const typeToDefault: { [type in SettingsType]: any } = { integer: 0, boolean: false, groups: [], - translations: [], + translations: {}, ranking: [], choice: null, date: null, @@ -126,14 +151,12 @@ const typeToDefault: { [type in SettingsType]: any } = { email: `` }; -fdescribe(`MeetingSettingsDefinitionService`, () => { +describe(`MeetingSettingsDefinitionService`, () => { let service: MeetingSettingsDefinitionService; - function mockGetters(haveDefaults = true): void { + function mockGetters(settingsDefaults = fakeSettingsDefaults): void { spyOnProperty(service, `settings`).and.returnValue(fakeSettings); - spyOnProperty(service, `settingsDefaults`).and.returnValue( - haveDefaults ? fakeSettingsDefaults : emptyFakeSettingsDefaults - ); + spyOnProperty(service, `settingsDefaults`).and.returnValue(settingsDefaults); spyOnProperty(service, `settingsMap`).and.returnValue(fakeSettingsMap as SettingsMap); } @@ -182,7 +205,7 @@ fdescribe(`MeetingSettingsDefinitionService`, () => { it(`test getDefaultValue for ${setting.type ?? `no given type`}${ haveDefaults ? `` : ` if there's no defaults` }`, () => { - mockGetters(haveDefaults); + mockGetters(haveDefaults ? fakeSettingsDefaults : {}); expect(service.getDefaultValue(setting)).toEqual( haveDefaults ? setting.type === `daterange` @@ -196,7 +219,7 @@ fdescribe(`MeetingSettingsDefinitionService`, () => { it(`test getDefaultValue for ${setting.type ?? `no given type`} with settings keys${ haveDefaults ? `` : ` if there's no defaults` } ${i + 1}`, () => { - mockGetters(haveDefaults); + mockGetters(haveDefaults ? fakeSettingsDefaults : {}); expect(service.getDefaultValue(keys[i])).toEqual( haveDefaults ? setting.type === `daterange` @@ -208,4 +231,23 @@ fdescribe(`MeetingSettingsDefinitionService`, () => { } } } + + for (const type of Object.keys(typeToDefault)) { + const setting = Object.values(fakeSettingsMap).find(setting => setting.type === type); + if (setting) { + it(`test getDefaultValueForType for ${type}`, () => { + mockGetters(); + expect(service.getDefaultValueForType(setting)).toEqual(typeToDefault[type]); + }); + } + const key = Array.isArray(setting.key) ? setting.key[0] : setting.key; + it(`test validateDefault for ${type}`, () => { + mockGetters(); + expect(() => service.validateDefault(key, fakeSettingsDefaults[key])).not.toThrowError(); + }); + it(`test validateDefault for ${type} with broken default`, () => { + mockGetters(fakeBrokenSettingsDefaults); + expect(() => service.validateDefault(key, fakeBrokenSettingsDefaults[key])).toThrowError(); + }); + } }); diff --git a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts index a2f564cb70..c26433208a 100644 --- a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts +++ b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definition.service.ts @@ -49,8 +49,9 @@ export class MeetingSettingsDefinitionService { return 0; case `boolean`: return false; - case `groups`: case `translations`: + return {}; + case `groups`: case `ranking`: return []; case `choice`: @@ -71,8 +72,9 @@ export class MeetingSettingsDefinitionService { public validateDefault(settingKey: keyof Settings, defaultValue: any): void { const setting = this.settingsMap[settingKey]; if ( - ((!setting.type || setting.type === `text`) && typeof defaultValue !== `string`) || - (setting.type === `integer` && typeof defaultValue !== `number`) || + ((!setting.type || [`string`, `text`, `email`, `markupText`].includes(setting.type)) && + typeof defaultValue !== `string`) || + ([`integer`, `date`, `datetime`, `daterange`].includes(setting.type) && typeof defaultValue !== `number`) || (setting.type === `boolean` && typeof defaultValue !== `boolean`) ) { throw new Error(`Invalid default for ${setting.key}: ${defaultValue} (${typeof defaultValue})`); @@ -82,6 +84,12 @@ export class MeetingSettingsDefinitionService { `Invalid default for ${setting.key}: ${defaultValue} (valid choices: ${Object.keys(setting.choices)})` ); } + if ([`ranking`, `groups`].includes(setting.type) && !Array.isArray(defaultValue)) { + throw new Error(`Invalid default for ${setting.key}: ${defaultValue} is not an array`); + } + if (setting.type === `translations` && typeof defaultValue !== `object`) { + throw new Error(`Invalid default for ${setting.key}: ${defaultValue} is not an object`); + } } private getDefaultValueForItem(item: SettingsItem): any {