fix: allow updating billing address on customer

This commit is contained in:
Sebastian Rindom
2021-07-13 10:41:06 +02:00
parent ddf94ca5be
commit 5a1cbc68b7
8 changed files with 267 additions and 33 deletions
@@ -56,6 +56,98 @@ describe("POST /store/customers/:id", () => {
})
})
describe("successfully updates a customer with billing address id", () => {
let subject
beforeAll(async () => {
subject = await request(
"POST",
`/store/customers/${IdMap.getId("lebron")}`,
{
payload: {
billing_address: "test",
},
clientSession: {
jwt: {
customer_id: IdMap.getId("lebron"),
},
},
}
)
})
afterAll(() => {
jest.clearAllMocks()
})
it("calls CustomerService update", () => {
expect(CustomerServiceMock.update).toHaveBeenCalledTimes(1)
expect(CustomerServiceMock.update).toHaveBeenCalledWith(
IdMap.getId("lebron"),
{
billing_address: "test",
}
)
})
it("status code 200", () => {
expect(subject.status).toEqual(200)
})
})
describe("successfully updates a customer with billing address object", () => {
let subject
beforeAll(async () => {
subject = await request(
"POST",
`/store/customers/${IdMap.getId("lebron")}`,
{
payload: {
billing_address: {
first_name: "Olli",
last_name: "Juhl",
address_1: "Laksegade",
city: "Copenhagen",
country_code: "dk",
postal_code: "2100",
phone: "+1 (222) 333 4444",
},
},
clientSession: {
jwt: {
customer_id: IdMap.getId("lebron"),
},
},
}
)
})
afterAll(() => {
jest.clearAllMocks()
})
it("calls CustomerService update", () => {
expect(CustomerServiceMock.update).toHaveBeenCalledTimes(1)
expect(CustomerServiceMock.update).toHaveBeenCalledWith(
IdMap.getId("lebron"),
{
billing_address: {
first_name: "Olli",
last_name: "Juhl",
address_1: "Laksegade",
city: "Copenhagen",
country_code: "dk",
postal_code: "2100",
phone: "+1 (222) 333 4444",
},
}
)
})
it("status code 200", () => {
expect(subject.status).toEqual(200)
})
})
describe("fails if not authenticated", () => {
let subject
beforeAll(async () => {
@@ -58,7 +58,7 @@ export default (app, container) => {
return app
}
export const defaultRelations = ["shipping_addresses"]
export const defaultRelations = ["shipping_addresses", "billing_address"]
export const defaultFields = [
"id",
@@ -44,6 +44,7 @@ export default async (req, res) => {
const { id } = req.params
const schema = Validator.object().keys({
billing_address: Validator.address().optional(),
first_name: Validator.string().optional(),
last_name: Validator.string().optional(),
password: Validator.string().optional(),