mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
42 lines
1.6 KiB
TypeScript
42 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: '84c0f8e8-544a-4c7e-9adf-26209303bc1d',
|
|
username: '[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 createUseCase().execute({ userUuid: '1-2-3' })).getValue().analyticsId).toEqual(123)
|
|
})
|
|
|
|
it('should return analytics id for a user by email', async () => {
|
|
expect((await createUseCase().execute({ userEmail: '[email protected]' })).getValue().analyticsId).toEqual(123)
|
|
})
|
|
|
|
it('should throw error if user is missing analytics entity', async () => {
|
|
analyticsEntityRepository.findOneByUserUuid = jest.fn().mockReturnValue(null)
|
|
|
|
const result = await createUseCase().execute({ userUuid: '1-2-3' })
|
|
|
|
expect(result.isFailed()).toEqual(true)
|
|
})
|
|
})
|