fix(medusa): Normalizes email before saving customer (#1719)
This commit is contained in:
@@ -58,6 +58,21 @@ describe("/store/customers", () => {
|
|||||||
expect(response.data.customer).not.toHaveProperty("password_hash")
|
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 () => {
|
it("responds 422 on duplicate", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ class CustomerService extends TransactionBaseService<CustomerService> {
|
|||||||
this.customerRepository_
|
this.customerRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
|
customer.email = customer.email.toLowerCase()
|
||||||
const { email, password } = customer
|
const { email, password } = customer
|
||||||
|
|
||||||
const existing = await this.retrieveByEmail(email).catch(() => undefined)
|
const existing = await this.retrieveByEmail(email).catch(() => undefined)
|
||||||
@@ -289,7 +290,7 @@ class CustomerService extends TransactionBaseService<CustomerService> {
|
|||||||
delete customer.password
|
delete customer.password
|
||||||
}
|
}
|
||||||
|
|
||||||
const created = await customerRepository.create(customer)
|
const created = customerRepository.create(customer)
|
||||||
const result = await customerRepository.save(created)
|
const result = await customerRepository.save(created)
|
||||||
await this.eventBusService_
|
await this.eventBusService_
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
|
|||||||
Reference in New Issue
Block a user