diff --git a/web/tests/recordingsAPI.spec.js b/web/tests/recordingsAPI.spec.js index 8e954157c..1eb57ebe1 100644 --- a/web/tests/recordingsAPI.spec.js +++ b/web/tests/recordingsAPI.spec.js @@ -110,23 +110,22 @@ describe('recordingsAPI', () => { ).resolves.toBe(false); }); - test('checkRecordingHasDetections returns false when timestamp parsing fails', async () => { + test.each([ + ['start', 'invalid-timestamp', '2026-02-18T05:01:00Z'], + ['end', '2026-02-18T05:00:00Z', 'invalid-timestamp'], + ['both', 'invalid-timestamp', 'invalid-timestamp'] + ])('checkRecordingHasDetections returns false without requesting detections when %s timestamps are invalid', async (_invalid, start_time, end_time) => { const recording = { id: 44, stream: 'front-yard', - start_time: 'invalid-timestamp', - end_time: 'invalid-timestamp' + start_time, + end_time }; - - const parseSpy = jest - .spyOn(recordingsAPI, 'parseRecordingTimestamp') - .mockImplementation(() => { - throw new Error('parse error'); - }); + const errorLog = jest.spyOn(console, 'error').mockImplementation(() => {}); await expect(recordingsAPI.checkRecordingHasDetections(recording)).resolves.toBe(false); - - parseSpy.mockRestore(); + expect(enhancedFetch).not.toHaveBeenCalled(); + expect(errorLog).toHaveBeenCalledWith('Failed to parse recording timestamps'); }); test('checkRecordingHasDetections returns false when enhancedFetch throws an error', async () => { @@ -176,26 +175,24 @@ describe('recordingsAPI', () => { expect(enhancedFetch).not.toHaveBeenCalled(); }); - test('getRecordingDetections returns empty array when timestamp parsing fails', async () => { + test.each([ + ['start', 'invalid-timestamp', '2026-02-18T05:01:00Z'], + ['end', '2026-02-18T05:00:00Z', 'invalid-timestamp'], + ['both', 'invalid-timestamp', 'invalid-timestamp'] + ])('getRecordingDetections returns empty array without requesting detections when %s timestamps are invalid', async (_invalid, start_time, end_time) => { const recording = { id: 89, stream: 'backyard', - start_time: 'invalid-start-timestamp', - end_time: 'invalid-end-timestamp' + start_time, + end_time }; - - const parseSpy = jest - .spyOn(recordingsAPI, 'parseRecordingTimestamp') - .mockImplementation(() => { - throw new Error('parse error'); - }); + const errorLog = jest.spyOn(console, 'error').mockImplementation(() => {}); const result = await recordingsAPI.getRecordingDetections(recording); expect(result).toEqual([]); expect(enhancedFetch).not.toHaveBeenCalled(); - - parseSpy.mockRestore(); + expect(errorLog).toHaveBeenCalledWith('Failed to parse recording timestamps'); }); test('getRecordingDetections returns empty array when enhancedFetch rejects', async () => {