Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions web/tests/recordingsAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading