mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import 'reflect-metadata'
|
|
|
|
import { SubscriptionName } from '@standardnotes/common'
|
|
import { SubscriptionReactivatedEvent } from '@standardnotes/domain-events'
|
|
|
|
import { SubscriptionReactivatedEventHandler } from './SubscriptionReactivatedEventHandler'
|
|
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
|
|
import { AnalyticsStoreInterface } from '../Analytics/AnalyticsStoreInterface'
|
|
import { Period } from '../Time/Period'
|
|
|
|
describe('SubscriptionReactivatedEventHandler', () => {
|
|
let event: SubscriptionReactivatedEvent
|
|
let getUserAnalyticsId: GetUserAnalyticsId
|
|
let analyticsStore: AnalyticsStoreInterface
|
|
|
|
const createHandler = () => new SubscriptionReactivatedEventHandler(analyticsStore, getUserAnalyticsId)
|
|
|
|
beforeEach(() => {
|
|
event = {} as jest.Mocked<SubscriptionReactivatedEvent>
|
|
event.createdAt = new Date(1)
|
|
event.payload = {
|
|
previousSubscriptionId: 1,
|
|
currentSubscriptionId: 2,
|
|
userEmail: '[email protected]',
|
|
subscriptionName: SubscriptionName.PlusPlan,
|
|
subscriptionExpiresAt: 5,
|
|
discountCode: 'exit-20',
|
|
}
|
|
|
|
getUserAnalyticsId = {} as jest.Mocked<GetUserAnalyticsId>
|
|
getUserAnalyticsId.execute = jest.fn().mockReturnValue({ analyticsId: 3 })
|
|
|
|
analyticsStore = {} as jest.Mocked<AnalyticsStoreInterface>
|
|
analyticsStore.markActivity = jest.fn()
|
|
})
|
|
|
|
it('should mark subscription reactivated activity for analytics', async () => {
|
|
await createHandler().handle(event)
|
|
|
|
expect(analyticsStore.markActivity).toHaveBeenCalledWith(['subscription-reactivated'], 3, [
|
|
Period.Today,
|
|
Period.ThisWeek,
|
|
Period.ThisMonth,
|
|
])
|
|
})
|
|
})
|