Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consertado bug no teste de customer #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("Customer repository test", () => {
it("should throw an error when customer is not found", async () => {
const customerRepository = new CustomerRepository();

expect(async () => {
await expect(async () => {
await customerRepository.find("456ABC");
}).rejects.toThrow("Customer not found");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Customer from "../../../../domain/customer/entity/customer";
import Address from "../../../../domain/customer/value-object/address";
import CustomerRepositoryInterface from "../../../../domain/customer/repository/customer-repository.interface";
import Address from "../../../../domain/customer/value-object/address";
import CustomerModel from "./customer.model";

export default class CustomerRepository implements CustomerRepositoryInterface {
Expand Down Expand Up @@ -37,17 +37,8 @@ export default class CustomerRepository implements CustomerRepositoryInterface {
}

async find(id: string): Promise<Customer> {
let customerModel;
try {
customerModel = await CustomerModel.findOne({
where: {
id,
},
rejectOnEmpty: true,
});
} catch (error) {
throw new Error("Customer not found");
}
const customerModel = await CustomerModel.findOne({ where: { id } });
if (!customerModel) throw new Error('Customer not found');

const customer = new Customer(id, customerModel.name);
const address = new Address(
Expand Down