mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-18 13:44:12 +00:00
temp: handle inconsistent errors from server
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
// evaluating the library, we re-export to make it easy to detach
|
||||
export { deepmerge } from 'deepmerge-ts';
|
||||
@@ -0,0 +1,30 @@
|
||||
import { EndAction, TimerType } from 'ontime-types';
|
||||
import { expect } from 'vitest';
|
||||
|
||||
import { validateEndAction, validateTimerType } from './validateEvent';
|
||||
|
||||
describe('validateEndAction()', () => {
|
||||
it('recognises a string representation of an action', () => {
|
||||
const endAction = validateEndAction('load-next');
|
||||
expect(endAction).toBe(EndAction.LoadNext);
|
||||
});
|
||||
it('returns fallback otherwise', () => {
|
||||
const emptyAction = validateEndAction('', EndAction.Stop);
|
||||
const invalidAction = validateEndAction('this-does-not-exist', EndAction.PlayNext);
|
||||
expect(emptyAction).toBe(EndAction.Stop);
|
||||
expect(invalidAction).toBe(EndAction.PlayNext);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateTimerType()', () => {
|
||||
it('recognises a string representation of an action', () => {
|
||||
const timerType = validateTimerType('time-to-end');
|
||||
expect(timerType).toBe(TimerType.TimeToEnd);
|
||||
});
|
||||
it('returns fallback otherwise', () => {
|
||||
const emptyType = validateTimerType('', TimerType.Clock);
|
||||
const invalidType = validateTimerType('this-does-not-exist', TimerType.CountDown);
|
||||
expect(emptyType).toBe(TimerType.Clock);
|
||||
expect(invalidType).toBe(TimerType.CountDown);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { EndAction, TimerType } from 'ontime-types';
|
||||
|
||||
export function validateEndAction(maybeAction: unknown, fallback = EndAction.None) {
|
||||
if (typeof maybeAction !== 'string') {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const isAction = Object.values(EndAction).includes(maybeAction as EndAction);
|
||||
if (isAction) {
|
||||
return maybeAction as EndAction;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function validateTimerType(maybeTimerType: unknown, fallback = TimerType.CountDown) {
|
||||
if (typeof maybeTimerType !== 'string') {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const isTimerType = Object.values(TimerType).includes(maybeTimerType as TimerType);
|
||||
if (isTimerType) {
|
||||
return maybeTimerType as TimerType;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user