From 2a32609b7458c12f047d3f9ba45d426fdc784d58 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Mon, 27 Jun 2022 10:56:12 +0200 Subject: [PATCH] fix(medusa): Normalizes email before saving customer (#1719) --- integration-tests/api/__tests__/store/customer.js | 15 +++++++++++++++ packages/medusa/src/services/customer.ts | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/integration-tests/api/__tests__/store/customer.js b/integration-tests/api/__tests__/store/customer.js index 3bdf830daf..a3e8fdbdd4 100644 --- a/integration-tests/api/__tests__/store/customer.js +++ b/integration-tests/api/__tests__/store/customer.js @@ -58,6 +58,21 @@ describe("/store/customers", () => { expect(response.data.customer).not.toHaveProperty("password_hash") }) + it("normalizes email", async () => { + const api = useApi() + + const response = await api.post("/store/customers", { + first_name: "James", + last_name: "Bond", + email: "James@Bond.com", + password: "test", + }) + + expect(response.status).toEqual(200) + expect(response.data.customer).not.toHaveProperty("password_hash") + expect(response.data.customer.email).toEqual("james@bond.com") + }) + it("responds 422 on duplicate", async () => { const api = useApi() diff --git a/packages/medusa/src/services/customer.ts b/packages/medusa/src/services/customer.ts index ee7c801424..aa5991c15d 100644 --- a/packages/medusa/src/services/customer.ts +++ b/packages/medusa/src/services/customer.ts @@ -258,6 +258,7 @@ class CustomerService extends TransactionBaseService { this.customerRepository_ ) + customer.email = customer.email.toLowerCase() const { email, password } = customer const existing = await this.retrieveByEmail(email).catch(() => undefined) @@ -289,7 +290,7 @@ class CustomerService extends TransactionBaseService { delete customer.password } - const created = await customerRepository.create(customer) + const created = customerRepository.create(customer) const result = await customerRepository.save(created) await this.eventBusService_ .withTransaction(manager)