fix(core-flows): fixes duplicate fulfillment issue (#8581)
what: - fixes a bug where fulfilling an outbound item was throwing an error due to the entire order being processed for fulfillment RESOLVES CC-298
This commit is contained in:
@@ -247,18 +247,14 @@ medusaIntegrationTestRunner({
|
|||||||
).data.fulfillment_set
|
).data.fulfillment_set
|
||||||
|
|
||||||
inventoryItem = (
|
inventoryItem = (
|
||||||
await api.post(
|
await api.get(`/admin/inventory-items?sku=test-variant`, adminHeaders)
|
||||||
`/admin/inventory-items`,
|
).data.inventory_items[0]
|
||||||
{ sku: "inv-1234" },
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
).data.inventory_item
|
|
||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/inventory-items/${inventoryItem.id}/location-levels`,
|
`/admin/inventory-items/${inventoryItem.id}/location-levels`,
|
||||||
{
|
{
|
||||||
location_id: location.id,
|
location_id: location.id,
|
||||||
stocked_quantity: 2,
|
stocked_quantity: 10,
|
||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -271,7 +267,7 @@ medusaIntegrationTestRunner({
|
|||||||
`/admin/inventory-items/${inventoryItemExtra.id}/location-levels`,
|
`/admin/inventory-items/${inventoryItemExtra.id}/location-levels`,
|
||||||
{
|
{
|
||||||
location_id: location.id,
|
location_id: location.id,
|
||||||
stocked_quantity: 4,
|
stocked_quantity: 10,
|
||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -438,7 +434,9 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Claims lifecycle", () => {
|
describe("Claims lifecycle", () => {
|
||||||
it("Full flow with 2 orders", async () => {
|
let claimId
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
let r2 = await api.post(
|
let r2 = await api.post(
|
||||||
"/admin/claims",
|
"/admin/claims",
|
||||||
{
|
{
|
||||||
@@ -513,7 +511,7 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
await api.post(`/admin/claims/${claimId2}/request`, {}, adminHeaders)
|
await api.post(`/admin/claims/${claimId2}/request`, {}, adminHeaders)
|
||||||
|
|
||||||
const claimId = baseClaim.id
|
claimId = baseClaim.id
|
||||||
const item = order.items[0]
|
const item = order.items[0]
|
||||||
|
|
||||||
let result = await api.post(
|
let result = await api.post(
|
||||||
@@ -629,16 +627,38 @@ medusaIntegrationTestRunner({
|
|||||||
).data
|
).data
|
||||||
|
|
||||||
expect(reservationsResponse.reservations).toHaveLength(1)
|
expect(reservationsResponse.reservations).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should complete flow with fulfilled items successfully", async () => {
|
||||||
|
const fulfillOrder = (
|
||||||
|
await api.get(`/admin/orders/${order.id}`, adminHeaders)
|
||||||
|
).data.order
|
||||||
|
|
||||||
|
const fulfillableItem = fulfillOrder.items.find(
|
||||||
|
(item) => item.detail.fulfilled_quantity === 0
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/orders/${order.id}/fulfillments`,
|
||||||
|
{
|
||||||
|
location_id: location.id,
|
||||||
|
items: [{ id: fulfillableItem.id, quantity: 1 }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should go through cancel flow successfully", async () => {
|
||||||
await api.post(`/admin/claims/${claimId}/cancel`, {}, adminHeaders)
|
await api.post(`/admin/claims/${claimId}/cancel`, {}, adminHeaders)
|
||||||
|
|
||||||
result = (
|
const [claim] = (
|
||||||
await api.get(
|
await api.get(
|
||||||
`/admin/claims?fields=*claim_items,*additional_items`,
|
`/admin/claims?fields=*claim_items,*additional_items`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
).data.claims
|
).data.claims
|
||||||
expect(result[0].canceled_at).toBeDefined()
|
|
||||||
|
expect(claim.canceled_at).toBeDefined()
|
||||||
|
|
||||||
const reservationsResponseAfterCanceling = (
|
const reservationsResponseAfterCanceling = (
|
||||||
await api.get(
|
await api.get(
|
||||||
|
|||||||
@@ -297,7 +297,13 @@ export const createOrderFulfillmentWorkflow = createWorkflow(
|
|||||||
const fulfillment = createFulfillmentWorkflow.runAsStep(fulfillmentData)
|
const fulfillment = createFulfillmentWorkflow.runAsStep(fulfillmentData)
|
||||||
|
|
||||||
const registerOrderFulfillmentData = transform(
|
const registerOrderFulfillmentData = transform(
|
||||||
{ order, fulfillment, input, inputItemsMap, itemsList: input.items_list },
|
{
|
||||||
|
order,
|
||||||
|
fulfillment,
|
||||||
|
input,
|
||||||
|
inputItemsMap,
|
||||||
|
itemsList: input.items ?? input.items_list,
|
||||||
|
},
|
||||||
prepareRegisterOrderFulfillmentData
|
prepareRegisterOrderFulfillmentData
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ function prepareRegisterShipmentData({
|
|||||||
reference: Modules.FULFILLMENT,
|
reference: Modules.FULFILLMENT,
|
||||||
reference_id: fulfillment.id,
|
reference_id: fulfillment.id,
|
||||||
created_by: input.created_by,
|
created_by: input.created_by,
|
||||||
items: order.items!.map((i) => {
|
items: (input.items ?? order.items)!.map((i) => {
|
||||||
return {
|
return {
|
||||||
id: i.id,
|
id: i.id,
|
||||||
quantity: i.quantity,
|
quantity: i.quantity,
|
||||||
|
|||||||
Reference in New Issue
Block a user