Skip to content

Commit

Permalink
test: add tests for Delete method in UserUsecase
Browse files Browse the repository at this point in the history
  • Loading branch information
davidambz committed Jun 3, 2024
1 parent fea2cb5 commit 037a389
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions usecase/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,53 @@ func TestErrorUpdate(t *testing.T) {
})
}
}

func TestDelete(t *testing.T) {
tcases := map[string]struct {
repo *mockInterfaces.MockUserRepository
inputID uniqueEntityId.ID
expectOutput error
}{
"success": {
repo: mockInterfaces.NewMockUserRepository(t),
inputID: uniqueEntityId.NewID(),
expectOutput: nil,
},
}

for name, tcase := range tcases {
t.Run(name, func(t *testing.T) {
tcase.repo.On("Delete", tcase.inputID).Return(tcase.expectOutput)

usecase := NewUserUsecase(tcase.repo, nil, nil)
err := usecase.Delete(tcase.inputID)

assert.Equal(t, tcase.expectOutput, err, "expected error mismatch")
})
}
}

func TestErrorDelete(t *testing.T) {
tcases := map[string]struct {
repo *mockInterfaces.MockUserRepository
inputID uniqueEntityId.ID
expectOutput error
}{
"errorDelete": {
repo: mockInterfaces.NewMockUserRepository(t),
inputID: uniqueEntityId.NewID(),
expectOutput: fmt.Errorf("error on delete user"),
},
}

for name, tcase := range tcases {
t.Run(name, func(t *testing.T) {
tcase.repo.On("Delete", tcase.inputID).Return(tcase.expectOutput)

usecase := NewUserUsecase(tcase.repo, nil, nil)
err := usecase.Delete(tcase.inputID)

assert.Equal(t, tcase.expectOutput, err, "expected error mismatch")
})
}
}

0 comments on commit 037a389

Please sign in to comment.