Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/cool-kiwis-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/dashboard": patch
"@medusajs/core-flows": patch
"@medusajs/types": patch
---

fix(core-flows, dashboard, types): improve allocation flows in Admin
9 changes: 9 additions & 0 deletions .changeset/gorgeous-cameras-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@medusajs/fulfillment": patch
"@medusajs/dashboard": patch
"@medusajs/core-flows": patch
"@medusajs/types": patch
"@medusajs/medusa": patch
---

feat(dashboard, core-flows): associate shipping option to type
102 changes: 101 additions & 1 deletion integration-tests/http/__tests__/order/admin/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ jest.setTimeout(300000)

medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
let order, seeder, inventoryItemOverride3, productOverride3, shippingProfile
let order,
seeder,
inventoryItemOverride3,
productOverride3,
shippingProfile,
productOverride4

beforeEach(async () => {
const container = getContainer()
Expand Down Expand Up @@ -836,6 +841,56 @@ medusaIntegrationTestRunner({
)
).data.product

const inventoryItemOverride4 = (
await api.post(
`/admin/inventory-items`,
{ sku: "test-variant-4-no-shipping", requires_shipping: false },
adminHeaders
)
).data.inventory_item

await api.post(
`/admin/inventory-items/${inventoryItemOverride4.id}/location-levels`,
{
location_id: stockChannelOverride.id,
stocked_quantity: 10,
},
adminHeaders
)

productOverride4 = (
await api.post(
"/admin/products",
{
title: `Test override 4`,
shipping_profile_id: shippingProfile.id,
options: [{ title: "size", values: ["large"] }],
variants: [
{
title: "Test variant 4",
sku: "test-variant-4-override",
inventory_items: [
{
inventory_item_id: inventoryItemOverride4.id,
required_quantity: 3,
},
],
prices: [
{
currency_code: "usd",
amount: 100,
},
],
options: {
size: "large",
},
},
],
},
adminHeaders
)
).data.product

shippingProfileOverride = (
await api.post(
`/admin/shipping-profiles`,
Expand Down Expand Up @@ -889,6 +944,7 @@ medusaIntegrationTestRunner({
additionalProducts: [
{ variant_id: productOverride2.variants[0].id, quantity: 1 },
{ variant_id: productOverride3.variants[0].id, quantity: 3 },
{ variant_id: productOverride4.variants[0].id, quantity: 1 },
{
variant_id:
productOverride4WithOverrideShippingProfile.variants[0].id,
Expand Down Expand Up @@ -1024,6 +1080,50 @@ medusaIntegrationTestRunner({
)
})

it("should throw if trying to fulfillment more items than it is reserved when item has required quantity", async () => {
const orderItemId = order.items.find(
(i) => i.variant_id === productOverride4.variants[0].id
).id

let reservation = (
await api.get(
`/admin/reservations?line_item_id=${orderItemId}`,
adminHeaders
)
).data.reservations[0]

expect(reservation.quantity).toBe(3) // one item with required quantity 3

reservation = (
await api.post(
`/admin/reservations/${reservation.id}`,
{
quantity: 2,
},
adminHeaders
)
).data.reservation

expect(reservation.quantity).toBe(2)

const res = await api
.post(
`/admin/orders/${order.id}/fulfillments`,
{
shipping_option_id: seeder.shippingOption.id,
location_id: seeder.stockLocation.id,
items: [{ id: orderItemId, quantity: 1 }], // fulfill 1 orer item which requires 3 inventor items
},
adminHeaders
)
.catch((e) => e)

expect(res.response.status).toBe(400)
expect(res.response.data.message).toBe(
`Quantity to fulfill exceeds the reserved quantity for the item: ${orderItemId}`
)
})

it("should throw if shipping profile of the product doesn't match the shipping profile of the shipping option", async () => {
const orderItemId = order.items.find(
(i) =>
Expand Down
Loading
Loading