From 66cd1decdec5879b50e3f5c103c74eaef6d949ff Mon Sep 17 00:00:00 2001 From: Alex Christoffer Rasmussen Date: Sun, 11 May 2025 18:29:18 +0200 Subject: [PATCH] assert non null and update test (#1604) --- .../src/services/__tests__/timerUtils.test.ts | 4 ++++ apps/server/src/services/timerUtils.ts | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/server/src/services/__tests__/timerUtils.test.ts b/apps/server/src/services/__tests__/timerUtils.test.ts index ec74c1898..75372164e 100644 --- a/apps/server/src/services/__tests__/timerUtils.test.ts +++ b/apps/server/src/services/__tests__/timerUtils.test.ts @@ -737,6 +737,7 @@ describe('getRuntimeOffset()', () => { }, runtime: { actualStart: 150, + plannedStart: 100, }, } as RuntimeState; @@ -760,6 +761,7 @@ describe('getRuntimeOffset()', () => { }, runtime: { actualStart: 150, + plannedStart: 100, }, } as RuntimeState; @@ -784,6 +786,7 @@ describe('getRuntimeOffset()', () => { }, runtime: { actualStart: 100, + plannedStart: 100, }, } as RuntimeState; @@ -809,6 +812,7 @@ describe('getRuntimeOffset()', () => { }, runtime: { actualStart: 100, + plannedStart: 100, }, } as RuntimeState; diff --git a/apps/server/src/services/timerUtils.ts b/apps/server/src/services/timerUtils.ts index 16d189efa..3cca39718 100644 --- a/apps/server/src/services/timerUtils.ts +++ b/apps/server/src/services/timerUtils.ts @@ -122,19 +122,18 @@ export function getRuntimeOffset(state: RuntimeState): { absoluteOffset: number; return { absoluteOffset: 0, relativeOffset: 0 }; } - // eslint-disable-next-line no-unused-labels -- dev code path - DEV: { - // we know current exists as long as eventNow exists - if (state.timer.current === null) { - throw new Error('timerUtils.calculate: current must be set'); - } - } - const { clock } = state; const { countToEnd, timeStart } = state.eventNow; const { addedTime, current, startedAt } = state.timer; const { actualStart, plannedStart } = state.runtime; + // eslint-disable-next-line no-unused-labels -- dev code path + DEV: { + // we know current exists as long as eventNow exists + if (current === null) throw new Error('timerUtils.getRuntimeOffset: state.timer.current must be set'); + if (plannedStart === null) throw new Error('timerUtils.getRuntimeOffset: state.runtime.plannedStart must be set'); + } + // if we havent started, but the timer is armed // the offset is the difference to the schedule if (startedAt === null) {