forked from rhuandantas/fiap-tech-challenge-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rhuandantas:main' into main
- Loading branch information
Showing
10 changed files
with
141 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package usecase | |
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"errors" | ||
"fiap-tech-challenge-api/internal/core/domain" | ||
mock_repo "fiap-tech-challenge-api/test/mock/repository" | ||
|
@@ -25,21 +26,27 @@ var _ = Describe("cadastra cliente use case testes", func() { | |
}) | ||
|
||
Context("cadastra cliente", func() { | ||
clienteDTO := &domain.Cliente{ | ||
Id: 1, | ||
clienteDTO := &domain.ClienteRequest{ | ||
Nome: "Mock", | ||
Cpf: "20815919018", | ||
Email: "[email protected]", | ||
} | ||
dto := &domain.Cliente{ | ||
Nome: sql.NullString{String: "Mock"}, | ||
Cpf: sql.NullString{String: "20815919018"}, | ||
Email: sql.NullString{String: "[email protected]"}, | ||
} | ||
It("cadastra cliente com sucesso", func() { | ||
repo.EXPECT().Insere(ctx, clienteDTO).Return(clienteDTO, nil) | ||
repo.EXPECT().PesquisaPorCPF(gomock.Any(), gomock.Any()).Return(nil, nil) | ||
repo.EXPECT().Insere(ctx, gomock.Any()).Return(dto, nil) | ||
cli, err := cadastraCliente.Cadastra(ctx, clienteDTO) | ||
|
||
gomega.Expect(err).To(gomega.BeNil()) | ||
gomega.Expect(cli).ToNot(gomega.BeNil()) | ||
}) | ||
It("falha ao cadastrar cliente", func() { | ||
repo.EXPECT().Insere(ctx, clienteDTO).Return(nil, errors.New("mock error")) | ||
repo.EXPECT().PesquisaPorCPF(gomock.Any(), gomock.Any()).Return(nil, nil) | ||
repo.EXPECT().Insere(ctx, gomock.Any()).Return(nil, errors.New("mock error")) | ||
cli, err := cadastraCliente.Cadastra(ctx, clienteDTO) | ||
|
||
gomega.Expect(err.Error()).To(gomega.Equal("mock error")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package usecase | |
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fiap-tech-challenge-api/internal/core/domain" | ||
mock_repo "fiap-tech-challenge-api/test/mock/repository" | ||
|
||
|
@@ -24,21 +25,25 @@ var _ = Describe("pesquisa cliente use case testes", func() { | |
}) | ||
|
||
Context("pesquisa cliente", func() { | ||
clienteDTO := &domain.Cliente{ | ||
Id: 1, | ||
clienteDTO := &domain.ClienteRequest{ | ||
Nome: "Mock", | ||
Cpf: "20815919018", | ||
Email: "[email protected]", | ||
} | ||
dto := &domain.Cliente{ | ||
Nome: sql.NullString{String: "Mock"}, | ||
Cpf: sql.NullString{String: "20815919018"}, | ||
Email: sql.NullString{String: "[email protected]"}, | ||
} | ||
It("pesquisa por cpf com sucesso", func() { | ||
repo.EXPECT().PesquisaPorCPF(ctx, clienteDTO).Return(clienteDTO, nil) | ||
repo.EXPECT().PesquisaPorCPF(gomock.Any(), gomock.Any()).Return(dto, nil) | ||
cli, err := pesquisaPorCpf.PesquisaPorCPF(ctx, clienteDTO) | ||
|
||
gomega.Expect(err).To(gomega.BeNil()) | ||
gomega.Expect(cli).ToNot(gomega.BeNil()) | ||
}) | ||
It("pesquisa por id com sucesso", func() { | ||
repo.EXPECT().PesquisaPorId(ctx, gomock.Any()).Return(clienteDTO, nil) | ||
repo.EXPECT().PesquisaPorId(ctx, gomock.Any()).Return(dto, nil) | ||
cli, err := pesquisaPorCpf.PesquisaPorID(ctx, 1) | ||
|
||
gomega.Expect(err).To(gomega.BeNil()) | ||
|
Oops, something went wrong.