Add expand to /admin/customers/:id (#1070)
* fix: 1055 add expand to /admin/customers/:id * fix tests * fix tests
This commit is contained in:
committed by
olivermrbl
parent
1e4cc2fc80
commit
7c31acb064
@@ -0,0 +1,72 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/customers GET /admin/customers/:id fetches a customer 1`] = `
|
||||
Object {
|
||||
"billing_address_id": "test-address",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"email": "test1@email.com",
|
||||
"first_name": null,
|
||||
"has_account": false,
|
||||
"id": Any<String>,
|
||||
"last_name": null,
|
||||
"metadata": null,
|
||||
"orders": Array [],
|
||||
"phone": null,
|
||||
"shipping_addresses": Array [
|
||||
Object {
|
||||
"address_1": null,
|
||||
"address_2": null,
|
||||
"city": null,
|
||||
"company": null,
|
||||
"country_code": null,
|
||||
"created_at": Any<String>,
|
||||
"customer_id": "test-customer-1",
|
||||
"deleted_at": null,
|
||||
"first_name": "Lebron",
|
||||
"id": "test-address",
|
||||
"last_name": "James",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": null,
|
||||
"province": null,
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/customers GET /admin/customers/:id fetches a customer with expand query 1`] = `
|
||||
Object {
|
||||
"billing_address": Object {
|
||||
"address_1": null,
|
||||
"address_2": null,
|
||||
"city": null,
|
||||
"company": null,
|
||||
"country_code": null,
|
||||
"created_at": Any<String>,
|
||||
"customer_id": "test-customer-1",
|
||||
"deleted_at": null,
|
||||
"first_name": "Lebron",
|
||||
"id": "test-address",
|
||||
"last_name": "James",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": null,
|
||||
"province": null,
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"billing_address_id": "test-address",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"email": "test1@email.com",
|
||||
"first_name": null,
|
||||
"has_account": false,
|
||||
"id": "test-customer-1",
|
||||
"last_name": null,
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
@@ -229,4 +229,75 @@ describe("/admin/customers", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/customers/:id", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await customerSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("fetches a customer", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/customers/test-customer-1", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.customer).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
shipping_addresses: [
|
||||
{
|
||||
id: "test-address",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
})
|
||||
|
||||
it("fetches a customer with expand query", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/customers/test-customer-1?expand=billing_address", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.customer).toMatchSnapshot({
|
||||
id: "test-customer-1",
|
||||
billing_address: {
|
||||
id: "test-address",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user