Skip to content

Commit

Permalink
None colour from API (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-Arc authored Jun 12, 2024
1 parent b1838a5 commit 9e63261
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions apps/server/src/utils/__tests__/coerceType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/utils/coerceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9e63261

Please sign in to comment.