From 4fe8e9a79f652f3e39608d6683cb17cc08bb8717 Mon Sep 17 00:00:00 2001 From: Mo Date: Fri, 9 Feb 2024 11:39:47 -0600 Subject: [PATCH] fix: allow expired offline subscriptions to receive dashboard emails (#1041) --- .../CreateOfflineSubscriptionToken.spec.ts | 38 ------------------- .../CreateOfflineSubscriptionToken.ts | 14 ------- 2 files changed, 52 deletions(-) diff --git a/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.spec.ts b/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.spec.ts index cb33ab21b..beaa51889 100644 --- a/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.spec.ts +++ b/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.spec.ts @@ -89,42 +89,4 @@ describe('CreateOfflineSubscriptionToken', () => { expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled() expect(domainEventPublisher.publish).not.toHaveBeenCalled() }) - - it('should not create an offline subscription token if email has a cancelled subscription', async () => { - offlineUserSubscriptionRepository.findOneByEmail = jest - .fn() - .mockReturnValue({ cancelled: true, endsAt: 100 } as jest.Mocked) - - expect( - await createUseCase().execute({ - userEmail: 'test@test.com', - }), - ).toEqual({ - success: false, - error: 'subscription-canceled', - }) - - expect(offlineSubscriptionTokenRepository.save).not.toHaveBeenCalled() - expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled() - expect(domainEventPublisher.publish).not.toHaveBeenCalled() - }) - - it('should not create an offline subscription token if email has an outdated subscription', async () => { - offlineUserSubscriptionRepository.findOneByEmail = jest - .fn() - .mockReturnValue({ cancelled: false, endsAt: 2 } as jest.Mocked) - - expect( - await createUseCase().execute({ - userEmail: 'test@test.com', - }), - ).toEqual({ - success: false, - error: 'subscription-expired', - }) - - expect(offlineSubscriptionTokenRepository.save).not.toHaveBeenCalled() - expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled() - expect(domainEventPublisher.publish).not.toHaveBeenCalled() - }) }) diff --git a/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.ts b/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.ts index ecfbfb498..e4a55560a 100644 --- a/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.ts +++ b/packages/auth/src/Domain/UseCase/CreateOfflineSubscriptionToken/CreateOfflineSubscriptionToken.ts @@ -37,20 +37,6 @@ export class CreateOfflineSubscriptionToken implements UseCaseInterface { } } - if (existingSubscription.cancelled) { - return { - success: false, - error: 'subscription-canceled', - } - } - - if (existingSubscription.endsAt < this.timer.getTimestampInMicroseconds()) { - return { - success: false, - error: 'subscription-expired', - } - } - const token = await this.cryptoNode.generateRandomKey(128) const offlineSubscriptionToken = {