fix(core-flows): refresh payment collections upon shipping changes (#10673)
* fix(core-flows): refresh payment collections upon shipping changes * chore: fix spec
This commit is contained in:
1 parent
3efd25d06d
commit
5d1098ceb9
4 files changed
+120
-47
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(core-flows): refresh payment collections upon shipping changes
|
||||||
@@ -302,7 +302,7 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("POST /store/carts/:id/line-items", () => {
|
describe("POST /store/carts/:id/line-items", () => {
|
||||||
let shippingOption
|
let shippingOption, shippingOptionExpensive
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const stockLocation = (
|
const stockLocation = (
|
||||||
@@ -358,25 +358,63 @@ medusaIntegrationTestRunner({
|
|||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const shippingOptionPayload = {
|
||||||
|
name: `Shipping`,
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
prices: [
|
||||||
|
{ currency_code: "usd", amount: 1000 },
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 0,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "item_total",
|
||||||
|
operator: "gt",
|
||||||
|
value: 5000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "enabled_in_store",
|
||||||
|
value: '"true"',
|
||||||
|
operator: "eq",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
attribute: "is_return",
|
||||||
|
value: "false",
|
||||||
|
operator: "eq",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
shippingOption = (
|
shippingOption = (
|
||||||
|
await api.post(
|
||||||
|
`/admin/shipping-options`,
|
||||||
|
shippingOptionPayload,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.shipping_option
|
||||||
|
|
||||||
|
shippingOptionExpensive = (
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/shipping-options`,
|
`/admin/shipping-options`,
|
||||||
{
|
{
|
||||||
name: `Shipping`,
|
...shippingOptionPayload,
|
||||||
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",
|
|
||||||
},
|
|
||||||
prices: [
|
prices: [
|
||||||
{ currency_code: "usd", amount: 1000 },
|
{ currency_code: "usd", amount: 10000 },
|
||||||
{
|
{
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
amount: 0,
|
amount: 5000,
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
attribute: "item_total",
|
attribute: "item_total",
|
||||||
@@ -386,18 +424,6 @@ medusaIntegrationTestRunner({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
attribute: "enabled_in_store",
|
|
||||||
value: '"true"',
|
|
||||||
operator: "eq",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attribute: "is_return",
|
|
||||||
value: "false",
|
|
||||||
operator: "eq",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -555,6 +581,61 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should update payment collection upon changing shipping option", async () => {
|
||||||
|
await api.post(
|
||||||
|
`/store/carts/${cart.id}/shipping-methods`,
|
||||||
|
{ option_id: shippingOption.id },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/store/payment-collections`,
|
||||||
|
{ cart_id: cart.id },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const cartAfterCollection = (
|
||||||
|
await api.get(`/store/carts/${cart.id}`, storeHeaders)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
expect(cartAfterCollection).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cart.id,
|
||||||
|
shipping_methods: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
shipping_option_id: shippingOption.id,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
payment_collection: expect.objectContaining({
|
||||||
|
amount: 2398,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
let cartAfterExpensiveShipping = (
|
||||||
|
await api.post(
|
||||||
|
`/store/carts/${cart.id}/shipping-methods`,
|
||||||
|
{ option_id: shippingOptionExpensive.id },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
expect(cartAfterExpensiveShipping).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cartAfterExpensiveShipping.id,
|
||||||
|
shipping_methods: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
shipping_option_id: shippingOptionExpensive.id,
|
||||||
|
amount: 5000,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
payment_collection: expect.objectContaining({
|
||||||
|
amount: 6398,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should add item to cart with tax lines multiple times", async () => {
|
it("should add item to cart with tax lines multiple times", async () => {
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ import { validateAndReturnShippingMethodsDataStep } from "../steps/validate-ship
|
|||||||
import { validateCartShippingOptionsPriceStep } from "../steps/validate-shipping-options-price"
|
import { validateCartShippingOptionsPriceStep } from "../steps/validate-shipping-options-price"
|
||||||
import { cartFieldsForRefreshSteps } from "../utils/fields"
|
import { cartFieldsForRefreshSteps } from "../utils/fields"
|
||||||
import { listShippingOptionsForCartWithPricingWorkflow } from "./list-shipping-options-for-cart-with-pricing"
|
import { listShippingOptionsForCartWithPricingWorkflow } from "./list-shipping-options-for-cart-with-pricing"
|
||||||
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
import { refreshCartItemsWorkflow } from "./refresh-cart-items"
|
||||||
import { updateTaxLinesWorkflow } from "./update-tax-lines"
|
|
||||||
|
|
||||||
export interface AddShippingMethodToCartWorkflowInput {
|
export interface AddShippingMethodToCartWorkflowInput {
|
||||||
cart_id: string
|
cart_id: string
|
||||||
@@ -132,9 +131,9 @@ export const addShippingMethodToCartWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const currentShippingMethods = transform({ cart }, ({ cart }) => {
|
const currentShippingMethods = transform({ cart }, ({ cart }) =>
|
||||||
return cart.shipping_methods.map((sm) => sm.id)
|
cart.shipping_methods.map((sm) => sm.id)
|
||||||
})
|
)
|
||||||
|
|
||||||
parallelize(
|
parallelize(
|
||||||
removeShippingMethodFromCartStep({
|
removeShippingMethodFromCartStep({
|
||||||
@@ -149,16 +148,8 @@ export const addShippingMethodToCartWorkflow = createWorkflow(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
updateTaxLinesWorkflow.runAsStep({
|
refreshCartItemsWorkflow.runAsStep({
|
||||||
input: {
|
input: { cart_id: cart.id },
|
||||||
cart_id: input.cart_id,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
updateCartPromotionsWorkflow.runAsStep({
|
|
||||||
input: {
|
|
||||||
cart_id: input.cart_id,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -28,16 +28,15 @@ export const defaultStoreCartFields = [
|
|||||||
"original_shipping_subtotal",
|
"original_shipping_subtotal",
|
||||||
"original_shipping_total",
|
"original_shipping_total",
|
||||||
"metadata",
|
"metadata",
|
||||||
|
"sales_channel_id",
|
||||||
"promotions.id",
|
"promotions.id",
|
||||||
"promotions.code",
|
"promotions.code",
|
||||||
"promotions.is_automatic",
|
"promotions.is_automatic",
|
||||||
"promotions.application_method.value",
|
"promotions.application_method.value",
|
||||||
"promotions.application_method.type",
|
"promotions.application_method.type",
|
||||||
"promotions.application_method.currency_code",
|
"promotions.application_method.currency_code",
|
||||||
"items",
|
|
||||||
"items.thumbnail",
|
|
||||||
"region",
|
|
||||||
"items.id",
|
"items.id",
|
||||||
|
"items.thumbnail",
|
||||||
"items.product",
|
"items.product",
|
||||||
"items.product.id",
|
"items.product.id",
|
||||||
"items.variant",
|
"items.variant",
|
||||||
@@ -118,10 +117,7 @@ export const defaultStoreCartFields = [
|
|||||||
"region.currency_code",
|
"region.currency_code",
|
||||||
"region.automatic_taxes",
|
"region.automatic_taxes",
|
||||||
"*region.countries",
|
"*region.countries",
|
||||||
"sales_channel_id",
|
"*payment_collection",
|
||||||
|
|
||||||
"payment_collection.id",
|
|
||||||
"payment_collection.amount",
|
|
||||||
"*payment_collection.payment_sessions",
|
"*payment_collection.payment_sessions",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user