feat: Add shipping method to cart (#6661)

This commit is contained in:
Oli Juhl
2024-03-12 17:52:48 +01:00
committed by GitHub
parent c3c4f49fc2
commit f0c8142635
18 changed files with 491 additions and 23 deletions
@@ -1,4 +1,5 @@
import {
addShippingMethodToWorkflow,
addToCartWorkflow,
createCartWorkflow,
createPaymentCollectionForCartWorkflow,
@@ -15,6 +16,7 @@ import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import {
ICartModuleService,
ICustomerModuleService,
IFulfillmentModuleService,
IPaymentModuleService,
IPricingModuleService,
IProductModuleService,
@@ -40,6 +42,7 @@ medusaIntegrationTestRunner({
let productModule: IProductModuleService
let pricingModule: IPricingModuleService
let paymentModule: IPaymentModuleService
let fulfillmentModule: IFulfillmentModuleService
let remoteLink, remoteQuery
let defaultRegion
@@ -57,6 +60,9 @@ medusaIntegrationTestRunner({
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
fulfillmentModule = appContainer.resolve(
ModuleRegistrationName.FULFILLMENT
)
remoteLink = appContainer.resolve("remoteLink")
remoteQuery = appContainer.resolve("remoteQuery")
})
@@ -978,6 +984,99 @@ medusaIntegrationTestRunner({
})
})
})
describe("AddShippingMethodToCartWorkflow", () => {
it("should add shipping method to cart", async () => {
let cart = await cartModuleService.create({
currency_code: "usd",
})
const shippingProfile =
await fulfillmentModule.createShippingProfiles({
name: "Test",
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
name: "Test",
type: "test-type",
})
const serviceZone = await fulfillmentModule.createServiceZones({
name: "Test",
fulfillment_set_id: fulfillmentSet.id,
geo_zones: [
{
type: "country",
country_code: "us",
},
],
})
const shippingOption = await fulfillmentModule.createShippingOptions({
name: "Test shipping option",
service_zone_id: serviceZone.id,
shipping_profile_id: shippingProfile.id,
provider_id: "manual_test-provider",
price_type: "flat",
type: {
label: "Test type",
description: "Test description",
code: "test-code",
},
})
const priceSet = await pricingModule.create({
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})
await remoteLink.create([
{
[Modules.FULFILLMENT]: {
shipping_option_id: shippingOption.id,
},
[Modules.PRICING]: {
price_set_id: priceSet.id,
},
},
])
cart = await cartModuleService.retrieve(cart.id, {
select: ["id", "region_id", "currency_code"],
})
await addShippingMethodToWorkflow(appContainer).run({
input: {
options: [
{
id: shippingOption.id,
},
],
cart_id: cart.id,
currency_code: cart.currency_code,
},
})
cart = await cartModuleService.retrieve(cart.id, {
relations: ["shipping_methods"],
})
expect(cart).toEqual(
expect.objectContaining({
id: cart.id,
currency_code: "usd",
shipping_methods: expect.arrayContaining([
expect.objectContaining({
amount: 3000,
name: "Test shipping option",
}),
]),
})
)
})
})
})
},
})