diff --git a/.changeset/tidy-schools-wash.md b/.changeset/tidy-schools-wash.md new file mode 100644 index 00000000..6efe8ab1 --- /dev/null +++ b/.changeset/tidy-schools-wash.md @@ -0,0 +1,5 @@ +--- +"@sebspark/pubsub": minor +--- + +Add methods for closing and deleting a subscription. diff --git a/packages/pubsub/src/lib/subscriber.spec.ts b/packages/pubsub/src/lib/subscriber.spec.ts index 153b6f1b..03a00668 100644 --- a/packages/pubsub/src/lib/subscriber.spec.ts +++ b/packages/pubsub/src/lib/subscriber.spec.ts @@ -131,4 +131,32 @@ describe('subscriber', () => { expect(topicMock.createSubscription).toHaveBeenCalled() }) }) + + describe('close', () => { + it('closes a subscription', async () => { + const subscriber = createSubscriber({ + projectId: 'test', + }) + + subscriptionMock.close = vi.fn() + + await subscriber.topic('example').close('example-subscription') + + expect(subscriptionMock.close).toHaveBeenCalled() + }) + }) + + describe('delete', () => { + it('deletes a subscription', async () => { + const subscriber = createSubscriber({ + projectId: 'test', + }) + + subscriptionMock.delete = vi.fn() + + await subscriber.topic('example').delete('example-subscription') + + expect(subscriptionMock.delete).toHaveBeenCalled() + }) + }) }) diff --git a/packages/pubsub/src/lib/subscriber.ts b/packages/pubsub/src/lib/subscriber.ts index 9255a03e..733187b0 100644 --- a/packages/pubsub/src/lib/subscriber.ts +++ b/packages/pubsub/src/lib/subscriber.ts @@ -95,6 +95,14 @@ export const createSubscriber = >( return subscription }, + close: async (subscriptionName: string) => { + const subscription = _topic.subscription(subscriptionName) + await subscription.close() + }, + delete: async (subscriptionName: string) => { + const subscription = _topic.subscription(subscriptionName) + await subscription.delete() + }, } }, }