diff --git a/apps/server/src/utils/__tests__/coerceType.test.ts b/apps/server/src/utils/__tests__/coerceType.test.ts index 8b37a0d25..b56ddfdad 100644 --- a/apps/server/src/utils/__tests__/coerceType.test.ts +++ b/apps/server/src/utils/__tests__/coerceType.test.ts @@ -18,6 +18,13 @@ describe('parses a colour string that is', () => { it('not a string', () => { expect(() => coerceColour(5)).toThrowError(Error('Invalid colour value received')); }); + it('undefinde and null are not valid', () => { + expect(() => coerceColour(null)).toThrowError(Error('Invalid colour value received')); + expect(() => coerceColour(undefined)).toThrowError(Error('Invalid colour value received')); + }); + it('empty string is allowed', () => { + expect(coerceColour('')).toBe(''); + }); }); describe('match a string to an enum that is', () => { diff --git a/apps/server/src/utils/coerceType.ts b/apps/server/src/utils/coerceType.ts index 6a5730061..0f64c910f 100644 --- a/apps/server/src/utils/coerceType.ts +++ b/apps/server/src/utils/coerceType.ts @@ -90,7 +90,12 @@ export function coerceColour(value: unknown): string { if (!isColourHex(lowerCaseValue)) { throw new Error('Invalid hex colour received'); } - } else if (!(lowerCaseValue in cssColours)) { + return lowerCaseValue; + } + if (lowerCaseValue === '') { + return lowerCaseValue; // None colour the same as the UI 'Ø' button + } + if (!(lowerCaseValue in cssColours)) { throw new Error('Invalid colour name received'); } return lowerCaseValue;