Skip to content

Commit

Permalink
test: ensure return Result failure if email already registered
Browse files Browse the repository at this point in the history
  • Loading branch information
Christiangsn committed Mar 8, 2023
1 parent a4e7531 commit 5c3c7d9
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Result } from '@domain/shared/core'

import { SignupUseCases } from '@application/useCases/user/signup/signUpUseCases'
import { type IUserRepositoryContract } from '@domain/contracts/repositories/userRepository.contract'
import { OS } from '@domain/user'
import { type OS, UserAggregate } from '@domain/user'
import { mock, type MockProxy } from 'jest-mock-extended'

export interface IFakerDTO {
Expand All @@ -18,7 +19,7 @@ export interface IFakerDTO {
}

describe('SignUpUseCase', () => {
const fakeDTO = (props: IFakerDTO) => {
const fakeDTO = (props?: IFakerDTO) => {
return {
acceptedTerms: props?.acceptedTerms ?? true,
email: props?.email ?? 'johnjoe@example.com',
Expand All @@ -45,10 +46,22 @@ describe('SignUpUseCase', () => {
expect(signupUseCases).toBeDefined()
})

it('Shoudl return fails if not accept the terms', async () => {
it('Should return fails if not accept the terms', async () => {
const fakerDTO = fakeDTO({ acceptedTerms: false })
const result = await signupUseCases.execute(fakerDTO)
expect(result.isFailure).toBe(true)
expect(result.isSuccess).toBe(false)
expect(result.error).toBe('Terms should be accepted')
})

it('Shpuld fails if user already exists for provided email', async () => {
jest.spyOn(userRepository, 'exist').mockResolvedValueOnce(true)
const fakerDTO = fakeDTO()
const result = await signupUseCases.execute(fakerDTO)

expect(userRepository.exist).toHaveBeenCalledWith({ email: fakerDTO.email })
expect(userRepository.exist).toHaveBeenCalledTimes(1)
expect(result.isFailure).toBe(true)
expect(result.isSuccess).toBe(false)
})
})

0 comments on commit 5c3c7d9

Please sign in to comment.