forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-flows,framework,medusa): list shipping options pass in cart…
… as pricing context (medusajs#10374) * feat(core-flows,framework,medusa): list shipping options pass in cart as pricing context * chore: add test for shipping options returning free shipping
- Loading branch information
Showing
12 changed files
with
283 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@medusajs/core-flows": patch | ||
"@medusajs/framework": patch | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat(core-flows,framework,medusa): list shipping options pass in cart as pricing context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,17 @@ medusaIntegrationTestRunner({ | |
region_id: region.id, | ||
amount: 1100, | ||
}, | ||
{ | ||
region_id: region.id, | ||
amount: 0, | ||
rules: [ | ||
{ | ||
operator: "gt", | ||
attribute: "total", | ||
value: 2000, | ||
}, | ||
], | ||
}, | ||
{ | ||
region_id: regionTwo.id, | ||
amount: 500, | ||
|
@@ -266,6 +277,83 @@ medusaIntegrationTestRunner({ | |
}) | ||
) | ||
}) | ||
|
||
it("should return prices based on cart total", async () => { | ||
cart = ( | ||
await api.post( | ||
`/store/carts`, | ||
{ | ||
region_id: region.id, | ||
sales_channel_id: salesChannel.id, | ||
currency_code: "usd", | ||
email: "[email protected]", | ||
items: [ | ||
{ | ||
variant_id: product.variants[0].id, | ||
// Adding a quantity of 100 to emulate total being greater than 2000 | ||
quantity: 100, | ||
}, | ||
], | ||
}, | ||
storeHeaders | ||
) | ||
).data.cart | ||
|
||
const resp = await api.get( | ||
`/store/shipping-options?cart_id=${cart.id}`, | ||
storeHeaders | ||
) | ||
|
||
const shippingOptions = resp.data.shipping_options | ||
|
||
expect(shippingOptions).toHaveLength(1) | ||
expect(shippingOptions[0]).toEqual( | ||
expect.objectContaining({ | ||
id: shippingOption.id, | ||
name: "Test shipping option", | ||
// Free shipping due to cart total being greater than 2000 | ||
amount: 0, | ||
price_type: "flat", | ||
}) | ||
) | ||
}) | ||
|
||
it("should throw when required fields of a cart are not present", async () => { | ||
cart = ( | ||
await api.post( | ||
`/store/carts`, | ||
{ | ||
region_id: region.id, | ||
currency_code: "usd", | ||
sales_channel_id: null, | ||
email: "[email protected]", | ||
items: [], | ||
}, | ||
storeHeaders | ||
) | ||
).data.cart | ||
|
||
const { response } = await api | ||
.get(`/store/shipping-options?cart_id=${cart.id}`, storeHeaders) | ||
.catch((e) => e) | ||
|
||
expect(response.data).toEqual({ | ||
type: "invalid_data", | ||
message: | ||
"Field(s) are required to have value to continue - sales_channel_id", | ||
}) | ||
}) | ||
|
||
it("should throw error when cart_id is not passed as a parameter", async () => { | ||
const { response } = await api | ||
.get(`/store/shipping-options`, storeHeaders) | ||
.catch((e) => e) | ||
|
||
expect(response.data).toEqual({ | ||
type: "invalid_data", | ||
message: "Invalid request: Field 'cart_id' is required", | ||
}) | ||
}) | ||
}) | ||
}) | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.