From 8575d95422a081a220329d842014dab771b1a16a Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Tue, 19 Mar 2024 13:21:31 -0500 Subject: [PATCH] Add a test for refresh channel --- src/useSubscription/utilities/refresh.spec.ts | 18 ++++++++++++++++++ src/useSubscription/utilities/refresh.ts | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/useSubscription/utilities/refresh.spec.ts diff --git a/src/useSubscription/utilities/refresh.spec.ts b/src/useSubscription/utilities/refresh.spec.ts new file mode 100644 index 0000000..7172740 --- /dev/null +++ b/src/useSubscription/utilities/refresh.spec.ts @@ -0,0 +1,18 @@ +import { expect, test, vi } from 'vitest' +import { SubscriptionManager } from '@/useSubscription/models' +import { useSubscription } from '@/useSubscription/useSubscription' +import { refreshChannel } from '@/useSubscription/utilities/refresh' + +test('channel refreshes only when channel is active', async () => { + const action = vi.fn() + const manager = new SubscriptionManager() + const subscription = useSubscription(action, [], { manager }) + + refreshChannel(action, [], { manager }) + + subscription.unsubscribe() + + refreshChannel(action, [], { manager }) + + expect(action).toBeCalledTimes(2) +}) \ No newline at end of file diff --git a/src/useSubscription/utilities/refresh.ts b/src/useSubscription/utilities/refresh.ts index 4537bc3..e6ddeb9 100644 --- a/src/useSubscription/utilities/refresh.ts +++ b/src/useSubscription/utilities/refresh.ts @@ -3,7 +3,6 @@ import { Action, ActionArguments } from '@/useSubscription/types/action' import { RefreshChannelOptions } from '@/useSubscription/types/channels' import { defaultSubscriptionManager } from '@/useSubscription/useSubscription' - export function refreshChannel( action: T, args: ActionArguments,