From ebb7c0aa5390f1dd3caef7ec3e2c6d44c9530904 Mon Sep 17 00:00:00 2001 From: Derek Wene Date: Sat, 20 Nov 2021 04:50:28 -0600 Subject: [PATCH] Fix: admin api create customer (#826) --- .../api/__tests__/admin/customer.js | 49 +++++++++++++++++++ .../routes/admin/customers/create-customer.ts | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/integration-tests/api/__tests__/admin/customer.js b/integration-tests/api/__tests__/admin/customer.js index 36f5b0a168..8661c1780c 100644 --- a/integration-tests/api/__tests__/admin/customer.js +++ b/integration-tests/api/__tests__/admin/customer.js @@ -132,6 +132,55 @@ describe("/admin/customers", () => { }) }) + describe("POST /admin/customers", () => { + beforeEach(async () => { + try { + await adminSeeder(dbConnection) + } catch (err) { + console.log(err) + throw err + } + }) + + afterEach(async () => { + const db = useDb() + await db.teardown() + }) + + it("Correctly creates customer", async () => { + const api = useApi() + const response = await api + .post( + "/admin/customers", + { + first_name: "newf", + last_name: "newl", + email: "new@email.com", + password: "newpassword", + metadata: { foo: "bar" }, + }, + { + headers: { + Authorization: "Bearer test_token", + }, + } + ) + .catch((err) => { + console.log(err) + }) + + expect(response.status).toEqual(201) + expect(response.data.customer).toEqual( + expect.objectContaining({ + first_name: "newf", + last_name: "newl", + email: "new@email.com", + metadata: { foo: "bar" }, + }) + ) + }) + }) + describe("POST /admin/customers/:id", () => { beforeEach(async () => { try { diff --git a/packages/medusa/src/api/routes/admin/customers/create-customer.ts b/packages/medusa/src/api/routes/admin/customers/create-customer.ts index 34ee33283c..a54476b38e 100644 --- a/packages/medusa/src/api/routes/admin/customers/create-customer.ts +++ b/packages/medusa/src/api/routes/admin/customers/create-customer.ts @@ -27,7 +27,7 @@ import { validator } from "../../../../utils/validator" * $ref: "#/components/schemas/customer" */ export default async (req, res) => { - const validated = await validator(AdminPostCustomersReq, req.bodyn) + const validated = await validator(AdminPostCustomersReq, req.body) const customerService: CustomerService = req.scope.resolve("customerService") const customer = await customerService.create(validated)