Skip to content

Commit

Permalink
fix(core-flows): shipping options for cart (#9343)
Browse files Browse the repository at this point in the history
FIXES: CC-536

Co-authored-by: Frane Polić <[email protected]>
  • Loading branch information
carlos-r-l-rodrigues and fPolic authored Sep 27, 2024
1 parent 74b3385 commit 19bc8d7
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ medusaIntegrationTestRunner({
thumbnail: "test-image.png",
status: "draft",
description: "test-product-description\ntest line 2",
options: [
options: expect.arrayContaining([
expect.objectContaining({
title: "size",
values: expect.arrayContaining([
Expand All @@ -220,7 +220,7 @@ medusaIntegrationTestRunner({
}),
]),
}),
],
]),
images: expect.arrayContaining([
expect.objectContaining({
url: "test-image.png",
Expand All @@ -243,12 +243,12 @@ medusaIntegrationTestRunner({
collection: expect.objectContaining({
id: baseCollection.id,
}),
variants: [
variants: expect.arrayContaining([
expect.objectContaining({
title: "Test variant",
allow_backorder: false,
manage_inventory: true,
prices: [
prices: expect.arrayContaining([
expect.objectContaining({
currency_code: "dkk",
amount: 30,
Expand All @@ -261,21 +261,21 @@ medusaIntegrationTestRunner({
currency_code: "usd",
amount: 100,
}),
],
options: [
]),
options: expect.arrayContaining([
expect.objectContaining({
value: "large",
}),
expect.objectContaining({
value: "green",
}),
],
]),
}),
expect.objectContaining({
title: "Test variant 2",
allow_backorder: false,
manage_inventory: true,
prices: [
prices: expect.arrayContaining([
expect.objectContaining({
currency_code: "dkk",
amount: 50,
Expand All @@ -288,17 +288,17 @@ medusaIntegrationTestRunner({
currency_code: "usd",
amount: 200,
}),
],
options: [
]),
options: expect.arrayContaining([
expect.objectContaining({
value: "small",
}),
expect.objectContaining({
value: "green",
}),
],
]),
}),
],
]),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
Expand All @@ -309,7 +309,7 @@ medusaIntegrationTestRunner({
thumbnail: "test-image.png",
status: "proposed",
description: "test-product-description",
options: [
options: expect.arrayContaining([
expect.objectContaining({
title: "size",
values: expect.arrayContaining([
Expand All @@ -326,7 +326,7 @@ medusaIntegrationTestRunner({
}),
]),
}),
],
]),
images: expect.arrayContaining([
expect.objectContaining({
url: "test-image.png",
Expand All @@ -344,12 +344,12 @@ medusaIntegrationTestRunner({
id: baseType.id,
}),
collection: null,
variants: [
variants: expect.arrayContaining([
expect.objectContaining({
title: "Test variant",
allow_backorder: false,
manage_inventory: true,
prices: [
prices: expect.arrayContaining([
expect.objectContaining({
currency_code: "dkk",
amount: 30,
Expand All @@ -362,17 +362,17 @@ medusaIntegrationTestRunner({
currency_code: "usd",
amount: 100,
}),
],
options: [
]),
options: expect.arrayContaining([
expect.objectContaining({
value: "large",
}),
expect.objectContaining({
value: "green",
}),
],
]),
}),
],
]),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
Expand Down Expand Up @@ -613,7 +613,7 @@ medusaIntegrationTestRunner({
thumbnail: "test-image.png",
status: "draft",
description: "test-product-description",
options: [
options: expect.arrayContaining([
expect.objectContaining({
title: "Size",
values: expect.arrayContaining([
Expand All @@ -628,7 +628,7 @@ medusaIntegrationTestRunner({
}),
]),
}),
],
]),
images: expect.arrayContaining([
expect.objectContaining({
url: "test-image.png",
Expand All @@ -645,7 +645,7 @@ medusaIntegrationTestRunner({
collection: expect.objectContaining({
id: baseCollection.id,
}),
variants: [
variants: expect.arrayContaining([
expect.objectContaining({
title: "Test variant",
sku: "test-sku-2",
Expand Down Expand Up @@ -689,7 +689,7 @@ medusaIntegrationTestRunner({
barcode: "test-barcode-4",
allow_backorder: false,
manage_inventory: true,
prices: [
prices: expect.arrayContaining([
expect.objectContaining({
currency_code: "usd",
amount: 100,
Expand All @@ -703,14 +703,14 @@ medusaIntegrationTestRunner({
currency_code: "dkk",
amount: 30,
}),
],
]),
options: [
expect.objectContaining({
value: "Large",
}),
],
}),
],
]),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
Expand All @@ -723,7 +723,7 @@ medusaIntegrationTestRunner({
status: "draft",
description:
"Hopper Stripes Bedding, available as duvet cover, pillow sham and sheet.\\n100% organic cotton, soft and crisp to the touch. Made in Portugal.",
options: [
options: expect.arrayContaining([
expect.objectContaining({
title: "test-option-1",
values: expect.arrayContaining([
Expand All @@ -740,22 +740,22 @@ medusaIntegrationTestRunner({
}),
]),
}),
],
]),
images: expect.arrayContaining([
expect.objectContaining({
url: "test-image.png",
}),
]),
tags: [],
type: null,
variants: [
variants: expect.arrayContaining([
expect.objectContaining({
title: "Test variant",
sku: "test-sku-1-1",
barcode: "test-barcode-1-1",
allow_backorder: false,
manage_inventory: true,
prices: [
prices: expect.arrayContaining([
expect.objectContaining({
currency_code: "usd",
rules: {
Expand All @@ -767,17 +767,17 @@ medusaIntegrationTestRunner({
currency_code: "usd",
amount: 1.1,
}),
],
options: [
]),
options: expect.arrayContaining([
expect.objectContaining({
value: "option 1 value red",
}),
expect.objectContaining({
value: "option 2 value 1",
}),
],
]),
}),
],
]),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ medusaIntegrationTestRunner({
)

const shippingOptions = resp.data.shipping_options

expect(shippingOptions).toHaveLength(1)
expect(shippingOptions[0]).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MedusaError } from "@medusajs/framework/utils"
import {
WorkflowData,
createWorkflow,
Expand Down Expand Up @@ -74,6 +75,13 @@ export const addShippingMethodToWorkflow = createWorkflow(
(so) => so.id === option.id
)!

if (!shippingOption?.calculated_price) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Shipping option with ID ${shippingOption.id} do not have a price`
)
}

return {
shipping_option_id: shippingOption.id,
amount: shippingOption.calculated_price.calculated_amount,
Expand Down
Loading

0 comments on commit 19bc8d7

Please sign in to comment.