feat(medusa): Create fulfillment with location (#2931)

* remove duplicate key from oas

* changeset

* initial suggestion for adding locations to fulfillments

* update migration

* re-add functionality for removing entire reservations

* fix tests

* add location when adjusting reserved inventory of a line_item

* add changest

* handle multiple reservations for a product in the same channel

* confirm inventory in stock location previous to creating the fulfillment

* fix tests after updating create-fulfillment to confirm inventory prior to creating fulfillment

* remove bugged code

* initial validation

* initial changes for review

* chekcpoint

* update validate inventory at location

* redo some unwanted changes

* typing

* update snapshots

* redo change for eslintrc

* add eslint disable

* re-order methods in interface

* assert no_notification

* iterate one time less

* add test for validation of correct inventory adjustments in case of no inventory service installation

* ensure correct adjustments for order cancellations

* remove comment

* fix tests

* fix but with coalescing

* remove location id from confirm inventory

* don't throw when adjusting reservations for a line item without reservations

* move reservation adjustments to the api

* add multiplication for updating a reservation quantity

* move inventory adjustments from the service layer to the api

* delete reservation if quantity is adjusted to 0

* rename updateReservation to updateReservationItem

* update dto fields

* reference the correct fields

* update with transaction

* add jsdocs

* force boolean cast

* context-ize cancel and create fulfillment transaction methods

* undo notification cast

* update with changes

* refactor withTransaction to variable

* use maps

* fix service mocks
This commit is contained in:
Philip Korsholm
2023-01-09 14:44:34 +01:00
committed by GitHub
parent 28bec599ae
commit 16716f5a4f
16 changed files with 546 additions and 86 deletions

View File

@@ -5,6 +5,7 @@ const {
LineItem,
CustomShippingOption,
ShippingMethod,
Fulfillment,
} = require("@medusajs/medusa")
const idMap = require("medusa-test-utils/src/id-map").default
@@ -203,6 +204,83 @@ describe("/admin/orders", () => {
})
await manager.save(li2)
const order3 = manager.create(Order, {
id: "test-order-not-payed-with-fulfillment",
customer_id: "test-customer",
email: "test@email.com",
fulfillment_status: "not_fulfilled",
payment_status: "awaiting",
billing_address: {
id: "test-billing-address",
first_name: "lebron",
},
shipping_address: {
id: "test-shipping-address",
first_name: "lebron",
country_code: "us",
},
region_id: "test-region",
currency_code: "usd",
tax_rate: 0,
discounts: [
{
id: "test-discount",
code: "TEST134",
is_dynamic: false,
rule: {
id: "test-rule",
description: "Test Discount",
type: "percentage",
value: 10,
allocation: "total",
},
is_disabled: false,
regions: [
{
id: "test-region",
},
],
},
],
payments: [
{
id: "test-payment",
amount: 10000,
currency_code: "usd",
amount_refunded: 0,
provider_id: "test-pay",
data: {},
},
],
items: [],
})
await manager.save(order3)
const li3 = manager.create(LineItem, {
id: "test-item-ful",
fulfilled_quantity: 1,
returned_quantity: 0,
title: "Line Item",
description: "Line Item Desc",
thumbnail: "https://test.js/1234",
unit_price: 8000,
quantity: 2,
variant_id: "test-variant",
order_id: "test-order-not-payed-with-fulfillment",
})
await manager.save(li3)
const ful1 = manager.create(Fulfillment, {
id: "ful-1",
order_id: "test-order-not-payed-with-fulfillment",
provider_id: "test-ful",
items: [{ item_id: "test-item-ful", quantity: 1 }],
data: {},
})
await manager.save(ful1)
})
afterEach(async () => {
@@ -229,6 +307,34 @@ describe("/admin/orders", () => {
expect(secondInventoryRes.data.variant.inventory_quantity).toEqual(2)
})
it("cancels a fulfillment and then an order and increments inventory_quantity correctly", async () => {
const api = useApi()
const initialInventoryRes = await api.get("/store/variants/test-variant")
expect(initialInventoryRes.data.variant.inventory_quantity).toEqual(1)
const cancelRes = await api.post(
`/admin/orders/test-order-not-payed-with-fulfillment/fulfillments/ful-1/cancel`,
{},
adminReqConfig
)
expect(cancelRes.status).toEqual(200)
const response = await api.post(
`/admin/orders/test-order-not-payed-with-fulfillment/cancel`,
{},
adminReqConfig
)
expect(response.status).toEqual(200)
const secondInventoryRes = await api.get("/store/variants/test-variant")
expect(secondInventoryRes.data.variant.inventory_quantity).toEqual(3)
})
it("cancels an order but does not increment inventory_quantity of unmanaged variant", async () => {
const api = useApi()
const manager = dbConnection.manager