Skip to content

Commit

Permalink
fix: allow expired offline subscriptions to receive dashboard emails (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz authored Feb 9, 2024
1 parent f975dd9 commit 4fe8e9a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<OfflineUserSubscription>)

expect(
await createUseCase().execute({
userEmail: '[email protected]',
}),
).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<OfflineUserSubscription>)

expect(
await createUseCase().execute({
userEmail: '[email protected]',
}),
).toEqual({
success: false,
error: 'subscription-expired',
})

expect(offlineSubscriptionTokenRepository.save).not.toHaveBeenCalled()
expect(domainEventFactory.createEmailRequestedEvent).not.toHaveBeenCalled()
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 4fe8e9a

Please sign in to comment.