fix: make it possible to update order shipping address (#668)
This commit is contained in:
1 parent
45b344fbe1
commit
e0fa06fe96
3 files changed
+93
-7
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`/admin/orders POST /admin/orders/:id updates a shipping adress 1`] = `
|
||||||
|
Object {
|
||||||
|
"address_1": "Some Street",
|
||||||
|
"address_2": "",
|
||||||
|
"city": "losangeles",
|
||||||
|
"company": null,
|
||||||
|
"country_code": "us",
|
||||||
|
"created_at": Any<String>,
|
||||||
|
"customer_id": null,
|
||||||
|
"deleted_at": null,
|
||||||
|
"first_name": "lebron",
|
||||||
|
"id": Any<String>,
|
||||||
|
"last_name": null,
|
||||||
|
"metadata": null,
|
||||||
|
"phone": null,
|
||||||
|
"postal_code": "1235",
|
||||||
|
"province": "",
|
||||||
|
"updated_at": Any<String>,
|
||||||
|
}
|
||||||
|
`;
|
||||||
@@ -74,6 +74,63 @@ describe("/admin/orders", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("POST /admin/orders/:id", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
try {
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
|
await orderSeeder(dbConnection)
|
||||||
|
} catch (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const db = useDb()
|
||||||
|
await db.teardown()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("updates a shipping adress", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(
|
||||||
|
"/admin/orders/test-order",
|
||||||
|
{
|
||||||
|
email: "test@test.com",
|
||||||
|
shipping_address: {
|
||||||
|
address_1: "Some Street",
|
||||||
|
address_2: "",
|
||||||
|
province: "",
|
||||||
|
postal_code: "1235",
|
||||||
|
city: "losangeles",
|
||||||
|
country_code: "us",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err.response.data)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.order.shipping_address).toMatchSnapshot({
|
||||||
|
id: expect.any(String),
|
||||||
|
address_1: "Some Street",
|
||||||
|
address_2: "",
|
||||||
|
province: "",
|
||||||
|
postal_code: "1235",
|
||||||
|
city: "losangeles",
|
||||||
|
country_code: "us",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("GET /admin/orders", () => {
|
describe("GET /admin/orders", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -784,7 +784,7 @@ class OrderService extends BaseService {
|
|||||||
|
|
||||||
await addrRepo.save({ ...addr, ...address })
|
await addrRepo.save({ ...addr, ...address })
|
||||||
} else {
|
} else {
|
||||||
const created = await addrRepo.create({ ...address })
|
const created = addrRepo.create({ ...address })
|
||||||
await addrRepo.save(created)
|
await addrRepo.save(created)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -877,26 +877,33 @@ class OrderService extends BaseService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { ...rest } = update
|
const {
|
||||||
|
metadata,
|
||||||
|
shipping_address,
|
||||||
|
billing_address,
|
||||||
|
no_notification,
|
||||||
|
items,
|
||||||
|
...rest
|
||||||
|
} = update
|
||||||
|
|
||||||
if ("metadata" in update) {
|
if ("metadata" in update) {
|
||||||
order.metadata = this.setMetadata_(order, update.metadata)
|
order.metadata = this.setMetadata_(order, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("shipping_address" in update) {
|
if ("shipping_address" in update) {
|
||||||
await this.updateShippingAddress_(order, update.shipping_address)
|
await this.updateShippingAddress_(order, shipping_address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("billing_address" in update) {
|
if ("billing_address" in update) {
|
||||||
await this.updateBillingAddress_(order, update.billing_address)
|
await this.updateBillingAddress_(order, billing_address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("no_notification" in update) {
|
if ("no_notification" in update) {
|
||||||
order.no_notification = update.no_notification
|
order.no_notification = no_notification
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("items" in update) {
|
if ("items" in update) {
|
||||||
for (const item of update.items) {
|
for (const item of items) {
|
||||||
await this.lineItemService_.withTransaction(manager).create({
|
await this.lineItemService_.withTransaction(manager).create({
|
||||||
...item,
|
...item,
|
||||||
order_id: orderId,
|
order_id: orderId,
|
||||||
|
|||||||
Reference in new issue
Block a user