Fix: admin api create customer (#826)
This commit is contained in:
1 parent
f162b4a2a1
commit
ebb7c0aa53
2 files changed
+50
-1
No files matched your search
@@ -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", () => {
|
describe("POST /admin/customers/:id", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { validator } from "../../../../utils/validator"
|
|||||||
* $ref: "#/components/schemas/customer"
|
* $ref: "#/components/schemas/customer"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
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 customerService: CustomerService = req.scope.resolve("customerService")
|
||||||
const customer = await customerService.create(validated)
|
const customer = await customerService.create(validated)
|
||||||
|
|||||||
Reference in new issue
Block a user