Skip to content

Commit

Permalink
test: ensure save user if a sucess data in request
Browse files Browse the repository at this point in the history
  • Loading branch information
Christiangsn committed Mar 8, 2023
1 parent 5c3c7d9 commit ceccad0
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/@application/useCases/user/signup/signupUseCase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Result } from '@domain/shared/core'

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

export interface IFakerDTO {
Expand Down Expand Up @@ -63,5 +62,17 @@ describe('SignUpUseCase', () => {
expect(userRepository.exist).toHaveBeenCalledTimes(1)
expect(result.isFailure).toBe(true)
expect(result.isSuccess).toBe(false)
expect(result.error).toBe('User already exist for provided email')
})

it('Should save user with success', async () => {
jest.spyOn(userRepository, 'save').mockResolvedValueOnce()

const fakerDTO = fakeDTO()
const result = await signupUseCases.execute(fakerDTO)

expect(userRepository.save).toHaveBeenCalledTimes(1)
expect(result.isFailure).toBe(false)
expect(result.isSuccess).toBe(true)
})
})

0 comments on commit ceccad0

Please sign in to comment.