test: Improve timezone resilience / cleanliness of tests (#2279)

- Related: https://github.com/dermotduffy/advanced-camera-card/pull/2278
- Reported by @0x464e
This commit is contained in:
Dermot Duffy
2025-12-11 05:33:48 -08:00
committed by GitHub
parent 236f3b7b57
commit f64690335b
6 changed files with 63 additions and 26 deletions
@@ -1,3 +1,4 @@
import { format } from 'date-fns';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { ViewItemManager } from '../../../src/card-controller/view/item-manager';
import { homeAssistantSignPath } from '../../../src/ha/sign-path.js';
@@ -189,7 +190,8 @@ describe('ViewItemManager', () => {
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(createHASS());
const manager = new ViewItemManager(api);
const item = new TestViewMedia({ startTime: new Date('2025-05-03T17:41:00Z') });
const startTime = new Date('2025-05-03T17:41:00Z');
const item = new TestViewMedia({ startTime });
vi.mocked(api.getCameraManager().getMediaDownloadPath).mockResolvedValue({
sign: false,
@@ -197,7 +199,10 @@ describe('ViewItemManager', () => {
});
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('foo', 'camera_id_2025-05-03-17-41-00.mp4');
// Use format() to generate expected filename timestamp (formats in local time)
const expectedFilename = `camera_id_${format(startTime, 'yyyy-MM-dd-HH-mm-ss')}.mp4`;
expect(downloadURL).toBeCalledWith('foo', expectedFilename);
});
it('should generate filename for snapshot', async () => {