Skip to content

Commit

Permalink
fix(core-flows): Listing return shipping options (#10432)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Dec 4, 2024
1 parent 3d5ca15 commit ff46637
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 1 deletion.
154 changes: 154 additions & 0 deletions integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,160 @@ medusaIntegrationTestRunner({
])
})

it("should exclude return shipping options for cart by default", async () => {
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})

const location = await stockLocationModule.createStockLocations({
name: "Europe",
})

let cart = await cartModuleService.createCarts({
currency_code: "usd",
region_id: region.id,
sales_channel_id: salesChannel.id,
shipping_address: {
city: "CPH",
province: "Sjaelland",
country_code: "dk",
},
})

const shippingProfile =
await fulfillmentModule.createShippingProfiles({
name: "Test",
type: "default",
})

const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
{
name: "Test",
geo_zones: [
{
type: "country",
country_code: "dk",
},
],
},
],
})

const shippingOption = await fulfillmentModule.createShippingOptions([
{
name: "Return shipping option",
service_zone_id: fulfillmentSet.service_zones[0].id,
shipping_profile_id: shippingProfile.id,
provider_id: "manual_test-provider",
rules: [
{
operator: RuleOperator.EQ,
attribute: "is_return",
value: "true",
},
],
price_type: "flat",
type: {
label: "Test type",
description: "Test description",
code: "test-code",
},
},
{
name: "Test shipping option",
service_zone_id: fulfillmentSet.service_zones[0].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.createPriceSets({
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})

const priceSetTwo = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})

await remoteLink.create([
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannel.id,
},
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.FULFILLMENT]: {
shipping_option_id: shippingOption.find(
(o) => o.name === "Test shipping option"
)?.id,
},
[Modules.PRICING]: {
price_set_id: priceSet.id,
},
},
{
[Modules.FULFILLMENT]: {
shipping_option_id: shippingOption.find(
(o) => o.name === "Return shipping option"
)?.id,
},
[Modules.PRICING]: {
price_set_id: priceSetTwo.id,
},
},
])

cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id"],
relations: ["shipping_address"],
})

const { result } = await listShippingOptionsForCartWorkflow(
appContainer
).run({
input: {
cart_id: cart.id,
},
})

expect(result.length).toEqual(1)
expect(result).toEqual([
expect.objectContaining({
name: "Test shipping option",
}),
])
})

it("should list no shipping options for cart, if sales channel is not associated with location", async () => {
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
})
)

const isReturn = transform({ input }, ({ input }) => !!input.is_return)

const shippingOptions = useRemoteQueryStep({
entry_point: "shipping_options",
fields: [
Expand Down Expand Up @@ -128,7 +130,7 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
],
variables: {
context: {
is_return: !!input.is_return,
is_return: isReturn,
enabled_in_store: "true",
},
filters: {
Expand Down

0 comments on commit ff46637

Please sign in to comment.