feat(core-flows,dashboard,types,medusa): delete shipping methods when all inbound/outbound items are deleted (#9106)
* feat(core-flows,dashboard,types,medusa): delete shipping methods when all inbound/outbound items are deleted * chore: fix specs
This commit is contained in:
1 parent
e9280fb254
commit
24704f420a
17 files changed
+594
-64
No files matched your search
@@ -838,6 +838,8 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("with only outbound items", () => {
|
||||
let orderResult
|
||||
|
||||
beforeEach(async () => {
|
||||
await api.post(
|
||||
`/admin/orders/${order.id}/fulfillments`,
|
||||
@@ -906,7 +908,7 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
await api.post(
|
||||
const { data } = await api.post(
|
||||
`/admin/claims/${claimId}/outbound/items`,
|
||||
{
|
||||
items: [
|
||||
@@ -965,7 +967,7 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
let orderResult = (
|
||||
orderResult = (
|
||||
await api.get(`/admin/orders/${order.id}`, adminHeaders)
|
||||
).data.order
|
||||
|
||||
@@ -1040,9 +1042,55 @@ medusaIntegrationTestRunner({
|
||||
|
||||
expect(orderResult.fulfillment_status).toEqual("shipped")
|
||||
})
|
||||
|
||||
it("should remove outbound shipping method when outbound items are completely removed", async () => {
|
||||
orderResult = (
|
||||
await api.get(`/admin/orders/${order.id}/preview`, adminHeaders)
|
||||
).data.order
|
||||
|
||||
const claimItems = orderResult.items.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find((action) => action.action === "ITEM_ADD")
|
||||
)
|
||||
|
||||
const claimShippingMethods = orderResult.shipping_methods.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find((action) => action.action === "SHIPPING_ADD")
|
||||
)
|
||||
|
||||
expect(claimItems).toHaveLength(1)
|
||||
expect(claimShippingMethods).toHaveLength(1)
|
||||
|
||||
await api.delete(
|
||||
`/admin/claims/${claimId}/outbound/items/${claimItems[0].actions[0].id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
orderResult = (
|
||||
await api.get(`/admin/orders/${order.id}/preview`, adminHeaders)
|
||||
).data.order
|
||||
|
||||
const updatedClaimItems = orderResult.items.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find((action) => action.action === "ITEM_ADD")
|
||||
)
|
||||
|
||||
const updatedClaimShippingMethods =
|
||||
orderResult.shipping_methods.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find(
|
||||
(action) => action.action === "SHIPPING_ADD"
|
||||
)
|
||||
)
|
||||
|
||||
expect(updatedClaimItems).toHaveLength(0)
|
||||
expect(updatedClaimShippingMethods).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with only inbound items", () => {
|
||||
let orderResult
|
||||
|
||||
beforeEach(async () => {
|
||||
await api.post(
|
||||
`/admin/orders/${order.id}/fulfillments`,
|
||||
@@ -1072,7 +1120,7 @@ medusaIntegrationTestRunner({
|
||||
claimId = baseClaim.id
|
||||
item = order.items[0]
|
||||
|
||||
let result = await api.post(
|
||||
await api.post(
|
||||
`/admin/claims/${claimId}/inbound/items`,
|
||||
{
|
||||
items: [
|
||||
@@ -1091,7 +1139,9 @@ medusaIntegrationTestRunner({
|
||||
{ shipping_option_id: returnShippingOption.id },
|
||||
adminHeaders
|
||||
)
|
||||
})
|
||||
|
||||
it("test inbound only", async () => {
|
||||
// Claim Items
|
||||
await api.post(
|
||||
`/admin/claims/${claimId}/claim-items`,
|
||||
@@ -1109,20 +1159,18 @@ medusaIntegrationTestRunner({
|
||||
|
||||
await api.post(`/admin/claims/${claimId}/request`, {}, adminHeaders)
|
||||
|
||||
result = (
|
||||
const claims = (
|
||||
await api.get(
|
||||
`/admin/claims?fields=*claim_items,*additional_items`,
|
||||
adminHeaders
|
||||
)
|
||||
).data.claims
|
||||
|
||||
expect(result).toHaveLength(1)
|
||||
expect(result[0].additional_items).toHaveLength(0)
|
||||
expect(result[0].claim_items).toHaveLength(1)
|
||||
expect(result[0].canceled_at).toBeNull()
|
||||
})
|
||||
expect(claims).toHaveLength(1)
|
||||
expect(claims[0].additional_items).toHaveLength(0)
|
||||
expect(claims[0].claim_items).toHaveLength(1)
|
||||
expect(claims[0].canceled_at).toBeNull()
|
||||
|
||||
it("test inbound only", async () => {
|
||||
const orderCheck = (
|
||||
await api.get(`/admin/orders/${order.id}`, adminHeaders)
|
||||
).data.order
|
||||
@@ -1137,6 +1185,49 @@ medusaIntegrationTestRunner({
|
||||
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
|
||||
it("should remove inbound shipping method when inbound items are completely removed", async () => {
|
||||
orderResult = (
|
||||
await api.get(`/admin/orders/${order.id}/preview`, adminHeaders)
|
||||
).data.order
|
||||
|
||||
const returnItems = orderResult.items.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find((action) => action.action === "RETURN_ITEM")
|
||||
)
|
||||
const returnShippingMethods = orderResult.shipping_methods.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find((action) => action.action === "SHIPPING_ADD")
|
||||
)
|
||||
|
||||
expect(returnItems).toHaveLength(1)
|
||||
expect(returnShippingMethods).toHaveLength(1)
|
||||
|
||||
await api.delete(
|
||||
`/admin/claims/${claimId}/inbound/items/${returnItems[0].actions[0].id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
orderResult = (
|
||||
await api.get(`/admin/orders/${order.id}/preview`, adminHeaders)
|
||||
).data.order
|
||||
|
||||
const updatedReturnItems = orderResult.items.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find((action) => action.action === "RETURN_ITEM")
|
||||
)
|
||||
|
||||
const updatedReturnShippingMethods =
|
||||
orderResult.shipping_methods.filter(
|
||||
(item) =>
|
||||
!!item.actions?.find(
|
||||
(action) => action.action === "SHIPPING_ADD"
|
||||
)
|
||||
)
|
||||
|
||||
expect(updatedReturnItems).toHaveLength(0)
|
||||
expect(updatedReturnShippingMethods).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user