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:
@@ -302,7 +302,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/line-items", () => {
|
||||
let shippingOption
|
||||
let shippingOption, shippingOptionExpensive
|
||||
|
||||
beforeEach(async () => {
|
||||
const stockLocation = (
|
||||
@@ -358,25 +358,63 @@ medusaIntegrationTestRunner({
|
||||
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 = (
|
||||
await api.post(
|
||||
`/admin/shipping-options`,
|
||||
shippingOptionPayload,
|
||||
adminHeaders
|
||||
)
|
||||
).data.shipping_option
|
||||
|
||||
shippingOptionExpensive = (
|
||||
await api.post(
|
||||
`/admin/shipping-options`,
|
||||
{
|
||||
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",
|
||||
},
|
||||
...shippingOptionPayload,
|
||||
prices: [
|
||||
{ currency_code: "usd", amount: 1000 },
|
||||
{ currency_code: "usd", amount: 10000 },
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 0,
|
||||
amount: 5000,
|
||||
rules: [
|
||||
{
|
||||
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
|
||||
)
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user