Merge branch 'main' into dev
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { format } from 'date-fns';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import { CameraManagerEngine } from '../../../src/camera-manager/engine';
|
||||
@@ -540,7 +541,9 @@ describe('FrigateCamera', () => {
|
||||
);
|
||||
|
||||
expect(camera.getEndpoints({ view: 'media', media })?.ui).toEqual({
|
||||
endpoint: 'http://frigate/recording/front_door/2023-01-01/10',
|
||||
endpoint:
|
||||
'http://frigate/recording/front_door/' +
|
||||
format(media.getStartTime(), 'yyyy-MM-dd/HH'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, assert, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
FrigateEventChange,
|
||||
FrigateReviewChange,
|
||||
@@ -117,6 +117,33 @@ describe('FrigateEventWatcher', () => {
|
||||
expect(unsubscribeCallback).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle unsubscribe during pending subscription', async () => {
|
||||
const stateWatcher = new FrigateEventWatcher();
|
||||
const hass = createHASS();
|
||||
|
||||
let resolveSubscription: ((callback: () => Promise<void>) => void) | undefined;
|
||||
const subscriptionPromise = new Promise<() => Promise<void>>((resolve) => {
|
||||
resolveSubscription = resolve;
|
||||
});
|
||||
vi.mocked(hass.connection.subscribeMessage).mockReturnValue(subscriptionPromise);
|
||||
|
||||
const request = {
|
||||
instanceID: 'frigate',
|
||||
callback: vi.fn(),
|
||||
};
|
||||
|
||||
// Start subscription (doesn't complete yet as not awaited).
|
||||
const subscribePromise = stateWatcher.subscribe(hass, request);
|
||||
|
||||
// Unsubscribe while subscription is still pending.
|
||||
await stateWatcher.unsubscribe(request);
|
||||
|
||||
// Complete the subscription.
|
||||
assert(resolveSubscription);
|
||||
resolveSubscription(vi.fn());
|
||||
await subscribePromise;
|
||||
});
|
||||
|
||||
describe('should call handler', () => {
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
|
||||
Reference in New Issue
Block a user