Fix: admin api create customer (#826)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user