diff --git a/src/infrastructure/customer/repository/sequelize/customer.repository.spec.ts b/src/infrastructure/customer/repository/sequelize/customer.repository.spec.ts index 0957be9..c436d83 100644 --- a/src/infrastructure/customer/repository/sequelize/customer.repository.spec.ts +++ b/src/infrastructure/customer/repository/sequelize/customer.repository.spec.ts @@ -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"); }); diff --git a/src/infrastructure/customer/repository/sequelize/customer.repository.ts b/src/infrastructure/customer/repository/sequelize/customer.repository.ts index dd6fc7c..8e99b73 100644 --- a/src/infrastructure/customer/repository/sequelize/customer.repository.ts +++ b/src/infrastructure/customer/repository/sequelize/customer.repository.ts @@ -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 { @@ -37,17 +37,8 @@ export default class CustomerRepository implements CustomerRepositoryInterface { } async find(id: string): Promise { - 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(