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 { AnalyticsEntity } from '../../Entity/AnalyticsEntity'
|
|
import { AnalyticsEntityRepositoryInterface } from '../../Entity/AnalyticsEntityRepositoryInterface'
|
|
|
|
import { GetUserAnalyticsId } from './GetUserAnalyticsId'
|
|
|
|
describe('GetUserAnalyticsId', () => {
|
|
let analyticsEntityRepository: AnalyticsEntityRepositoryInterface
|
|
let analyticsEntity: AnalyticsEntity
|
|
|
|
const createUseCase = () => new GetUserAnalyticsId(analyticsEntityRepository)
|
|
|
|
beforeEach(() => {
|
|
analyticsEntity = {
|
|
id: 123,
|
|
userUuid: '1-2-3',
|
|
userEmail: '[email protected]',
|
|
} as jest.Mocked<AnalyticsEntity>
|
|
|
|
analyticsEntityRepository = {} as jest.Mocked<AnalyticsEntityRepositoryInterface>
|
|
analyticsEntityRepository.findOneByUserUuid = jest.fn().mockReturnValue(analyticsEntity)
|
|
analyticsEntityRepository.findOneByUserEmail = jest.fn().mockReturnValue(analyticsEntity)
|
|
})
|
|
|
|
it('should return analytics id for a user by uuid', async () => {
|
|
expect(await (await createUseCase().execute({ userUuid: '1-2-3' })).analyticsId).toEqual(123)
|
|
})
|
|
|
|
it('should return analytics id for a user by email', async () => {
|
|
expect(await (await createUseCase().execute({ userEmail: '[email protected]' })).analyticsId).toEqual(123)
|
|
})
|
|
|
|
it('should throw error if user is missing analytics entity', async () => {
|
|
analyticsEntityRepository.findOneByUserUuid = jest.fn().mockReturnValue(null)
|
|
let error = null
|
|
|
|
try {
|
|
await createUseCase().execute({ userUuid: '1-2-3' })
|
|
} catch (caughtError) {
|
|
error = caughtError
|
|
}
|
|
|
|
expect(error).not.toBeNull()
|
|
})
|
|
})
|