chore(core-flows): adjust inventory when return is received (#8222)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { CreateOrderDTO, IOrderModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -132,7 +132,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
billing_address: expect.objectContaining({
|
||||
id: expect.stringContaining("ordaddr_"),
|
||||
}),
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.stringContaining("ordli_"),
|
||||
quantity: 1,
|
||||
@@ -174,7 +174,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
version: 1,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
shipping_methods: [
|
||||
expect.objectContaining({
|
||||
id: expect.stringContaining("ordsm_"),
|
||||
|
||||
@@ -104,6 +104,9 @@ moduleIntegrationTestRunner({
|
||||
|
||||
it("should claim an item and add two new items to the order", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
// Fullfilment
|
||||
await service.registerFulfillment({
|
||||
|
||||
@@ -127,6 +127,9 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
it("should change an order by adding actions to it", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
await service.addOrderAction([
|
||||
{
|
||||
@@ -219,123 +222,131 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
],
|
||||
relations: ["items", "shipping_methods", "transactions"],
|
||||
})
|
||||
|
||||
const serializedFinalOrder = JSON.parse(JSON.stringify(finalOrder))
|
||||
|
||||
const serializedCreatedOrder = JSON.parse(JSON.stringify(createdOrder))
|
||||
expect(serializedCreatedOrder.items).toEqual([
|
||||
expect.objectContaining({
|
||||
title: "Item 1",
|
||||
unit_price: 8,
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect(serializedCreatedOrder.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
title: "Item 1",
|
||||
unit_price: 8,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
compare_at_unit_price: null,
|
||||
unit_price: 5,
|
||||
quantity: 2,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
compare_at_unit_price: null,
|
||||
unit_price: 5,
|
||||
quantity: 2,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
])
|
||||
])
|
||||
)
|
||||
|
||||
expect(serializedFinalOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
version: 1,
|
||||
})
|
||||
)
|
||||
expect(serializedFinalOrder.items).toEqual([
|
||||
expect.objectContaining({
|
||||
title: "Item 1",
|
||||
subtitle: "Subtitle 1",
|
||||
thumbnail: "thumbnail1.jpg",
|
||||
variant_id: "variant1",
|
||||
product_id: "product1",
|
||||
product_title: "Product 1",
|
||||
product_description: "Description 1",
|
||||
product_subtitle: "Product Subtitle 1",
|
||||
product_type: "Type 1",
|
||||
product_collection: "Collection 1",
|
||||
product_handle: "handle1",
|
||||
variant_sku: "SKU1",
|
||||
variant_barcode: "Barcode1",
|
||||
variant_title: "Variant 1",
|
||||
variant_option_values: { size: "Large", color: "Red" },
|
||||
requires_shipping: true,
|
||||
is_discountable: true,
|
||||
is_tax_inclusive: true,
|
||||
compare_at_unit_price: 10,
|
||||
unit_price: 8,
|
||||
quantity: 2,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect(serializedFinalOrder.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
title: "Item 1",
|
||||
subtitle: "Subtitle 1",
|
||||
thumbnail: "thumbnail1.jpg",
|
||||
variant_id: "variant1",
|
||||
product_id: "product1",
|
||||
product_title: "Product 1",
|
||||
product_description: "Description 1",
|
||||
product_subtitle: "Product Subtitle 1",
|
||||
product_type: "Type 1",
|
||||
product_collection: "Collection 1",
|
||||
product_handle: "handle1",
|
||||
variant_sku: "SKU1",
|
||||
variant_barcode: "Barcode1",
|
||||
variant_title: "Variant 1",
|
||||
variant_option_values: { size: "Large", color: "Red" },
|
||||
requires_shipping: true,
|
||||
is_discountable: true,
|
||||
is_tax_inclusive: true,
|
||||
compare_at_unit_price: 10,
|
||||
unit_price: 8,
|
||||
quantity: 2,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 2,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
compare_at_unit_price: null,
|
||||
unit_price: 5,
|
||||
quantity: 5,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
compare_at_unit_price: null,
|
||||
unit_price: 5,
|
||||
quantity: 5,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 5,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 1,
|
||||
shipped_quantity: 1,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 1,
|
||||
written_off_quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 1,
|
||||
shipped_quantity: 1,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 1,
|
||||
written_off_quantity: 1,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
])
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should create an order change, add actions to it, confirm the changes, revert all the changes and restore the changes again.", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
const orderChange = await service.createOrderChange({
|
||||
order_id: createdOrder.id,
|
||||
@@ -439,45 +450,47 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
expect(serializedModifiedOrder.shipping_methods).toHaveLength(1)
|
||||
expect(serializedModifiedOrder.shipping_methods[0].amount).toEqual(10)
|
||||
|
||||
expect(serializedModifiedOrder.items).toEqual([
|
||||
expect.objectContaining({
|
||||
quantity: 2,
|
||||
detail: expect.objectContaining({
|
||||
version: 2,
|
||||
expect(serializedModifiedOrder.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 2,
|
||||
detail: expect.objectContaining({
|
||||
version: 2,
|
||||
quantity: 2,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
unit_price: 5,
|
||||
quantity: 5,
|
||||
detail: expect.objectContaining({
|
||||
version: 2,
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
unit_price: 5,
|
||||
quantity: 5,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 2,
|
||||
quantity: 5,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 2,
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 1,
|
||||
shipped_quantity: 1,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 1,
|
||||
written_off_quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 2,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 1,
|
||||
shipped_quantity: 1,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 1,
|
||||
written_off_quantity: 1,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
])
|
||||
])
|
||||
)
|
||||
|
||||
// Revert Last Changes
|
||||
await service.revertLastVersion(createdOrder.id)
|
||||
@@ -504,50 +517,55 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
expect(serializedRevertedOrder.shipping_methods).toHaveLength(1)
|
||||
expect(serializedRevertedOrder.shipping_methods[0].amount).toEqual(10)
|
||||
|
||||
expect(serializedRevertedOrder.items).toEqual([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
unit_price: 8,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect(serializedRevertedOrder.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
unit_price: 8,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 1,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
unit_price: 5,
|
||||
quantity: 2,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect.objectContaining({
|
||||
title: "Item 2",
|
||||
unit_price: 5,
|
||||
quantity: 2,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 2,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
expect.objectContaining({
|
||||
title: "Item 3",
|
||||
unit_price: 30,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
detail: expect.objectContaining({
|
||||
version: 1,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 0,
|
||||
shipped_quantity: 0,
|
||||
return_requested_quantity: 0,
|
||||
return_received_quantity: 0,
|
||||
return_dismissed_quantity: 0,
|
||||
written_off_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
])
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should create order change, cancel and reject them.", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
const orderChange = await service.createOrderChange({
|
||||
order_id: createdOrder.id,
|
||||
|
||||
@@ -104,6 +104,9 @@ moduleIntegrationTestRunner({
|
||||
|
||||
it("should exchange an item and add two new items to the order", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
// Fullfilment
|
||||
await service.registerFulfillment({
|
||||
|
||||
@@ -104,6 +104,9 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
it("should create an order, fulfill, ship and return the items", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
// Fullfilment
|
||||
await service.registerFulfillment({
|
||||
@@ -135,7 +138,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
expect(serializedOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
@@ -160,7 +163,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
shipped_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
@@ -195,7 +198,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
expect(serializedOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
@@ -220,7 +223,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
shipped_quantity: 1,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
@@ -290,7 +293,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
expect(serializedOrder.shipping_methods).toHaveLength(3)
|
||||
expect(serializedOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
@@ -318,7 +321,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
return_requested_quantity: 1,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
@@ -443,7 +446,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
expect(serializedOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
@@ -474,13 +477,16 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
return_received_quantity: 1,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create an order, fulfill, return the items and cancel some item return", async function () {
|
||||
const createdOrder = await service.createOrders(input)
|
||||
createdOrder.items = createdOrder.items!.sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
|
||||
await service.registerFulfillment({
|
||||
order_id: createdOrder.id,
|
||||
@@ -553,7 +559,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
expect(serializedOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
@@ -578,7 +584,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
return_requested_quantity: 1,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
@@ -628,7 +634,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
expect(serializedOrder.shipping_methods).toHaveLength(2)
|
||||
expect(serializedOrder).toEqual(
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
quantity: 1,
|
||||
detail: expect.objectContaining({
|
||||
@@ -659,7 +665,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
return_received_quantity: 0,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user