mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
import 'reflect-metadata'
|
|
import { UserRegisteredEvent } from '@standardnotes/domain-events'
|
|
import { Logger } from 'winston'
|
|
|
|
import { UserRegisteredEventHandler } from './UserRegisteredEventHandler'
|
|
import { AxiosInstance } from 'axios'
|
|
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
|
|
import { AnalyticsStoreInterface } from '@standardnotes/analytics'
|
|
import { ProtocolVersion } from '@standardnotes/common'
|
|
|
|
describe('UserRegisteredEventHandler', () => {
|
|
let httpClient: AxiosInstance
|
|
const userServerRegistrationUrl = 'https://user-server/registration'
|
|
const userServerAuthKey = 'auth-key'
|
|
let event: UserRegisteredEvent
|
|
let getUserAnalyticsId: GetUserAnalyticsId
|
|
let analyticsStore: AnalyticsStoreInterface
|
|
let logger: Logger
|
|
|
|
const createHandler = () =>
|
|
new UserRegisteredEventHandler(
|
|
httpClient,
|
|
userServerRegistrationUrl,
|
|
userServerAuthKey,
|
|
getUserAnalyticsId,
|
|
analyticsStore,
|
|
logger,
|
|
)
|
|
|
|
beforeEach(() => {
|
|
httpClient = {} as jest.Mocked<AxiosInstance>
|
|
httpClient.request = jest.fn()
|
|
|
|
event = {} as jest.Mocked<UserRegisteredEvent>
|
|
event.createdAt = new Date(1)
|
|
event.payload = {
|
|
userUuid: '1-2-3',
|
|
email: '[email protected]',
|
|
protocolVersion: ProtocolVersion.V004,
|
|
}
|
|
|
|
getUserAnalyticsId = {} as jest.Mocked<GetUserAnalyticsId>
|
|
getUserAnalyticsId.execute = jest.fn().mockReturnValue({ analyticsId: 3 })
|
|
|
|
analyticsStore = {} as jest.Mocked<AnalyticsStoreInterface>
|
|
analyticsStore.markActivity = jest.fn()
|
|
|
|
logger = {} as jest.Mocked<Logger>
|
|
logger.debug = jest.fn()
|
|
})
|
|
|
|
it('should send a request to the user management server about a registration', async () => {
|
|
await createHandler().handle(event)
|
|
|
|
expect(httpClient.request).toHaveBeenCalledWith({
|
|
method: 'POST',
|
|
url: 'https://user-server/registration',
|
|
headers: {
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: {
|
|
key: 'auth-key',
|
|
user: {
|
|
created_at: new Date(1),
|
|
email: '[email protected]',
|
|
},
|
|
},
|
|
validateStatus: expect.any(Function),
|
|
})
|
|
})
|
|
|
|
it('should not send a request to the user management server about a registration if url is not defined', async () => {
|
|
const handler = new UserRegisteredEventHandler(
|
|
httpClient,
|
|
'',
|
|
userServerAuthKey,
|
|
getUserAnalyticsId,
|
|
analyticsStore,
|
|
logger,
|
|
)
|
|
await handler.handle(event)
|
|
|
|
expect(httpClient.request).not.toHaveBeenCalled()
|
|
})
|
|
})
|