fix: more adjustments

add: composite unique constraint for shipping_option_id and cart_id
fix: fetchCartOptions to format custom shipping options like normal shipping options
fix: addShippingMethod should throw when custom shipping options is not empty and no optionId corresponds to custom shipping options
This commit is contained in:
zakariaelas
2021-10-07 14:54:05 +01:00
parent 52be911e50
commit 3d088c351b
8 changed files with 87 additions and 97 deletions
+13 -15
View File
@@ -5,6 +5,7 @@ const {
GiftCard,
Cart,
CustomShippingOption,
ShippingOption,
} = require("@medusajs/medusa")
const setupServer = require("../../../helpers/setup-server")
@@ -466,11 +467,6 @@ describe("/store/carts", () => {
})
cartWithCustomSo = await manager.save(_cart)
await manager.insert(CustomShippingOption, {
id: "orphan-cso",
price: 0,
})
} catch (err) {
console.log(err)
}
@@ -497,8 +493,9 @@ describe("/store/carts", () => {
expect(cartWithShippingMethod.status).toEqual(200)
})
it("given a cart with custom options and a custom option id already belonging to said cart, then it should add a shipping method based on the given custom shipping option", async () => {
const customOptionId = cartWithCustomSo.custom_shipping_options[0].id
it("given a cart with custom options and a shipping option already belonging to said cart, then it should add a shipping method based on the given custom shipping option", async () => {
const shippingOptionId =
cartWithCustomSo.custom_shipping_options[0].shipping_option_id
const api = useApi()
@@ -506,7 +503,7 @@ describe("/store/carts", () => {
.post(
"/store/carts/test-cart-with-cso/shipping-methods",
{
option_id: customOptionId,
option_id: shippingOptionId,
},
{ withCredentials: true }
)
@@ -515,27 +512,28 @@ describe("/store/carts", () => {
expect(
cartWithCustomShippingMethod.data.cart.shipping_methods
).toContainEqual(
expect.objectContaining({ shipping_option_id: "test-option", price: 5 })
expect.objectContaining({
shipping_option_id: shippingOptionId,
price: 5,
})
)
expect(cartWithCustomShippingMethod.status).toEqual(200)
})
it("given a cart with custom options and a custom option id not belonging to said cart, then it should throw a shipping option not found error", async () => {
it("given a cart with custom options and an option id not corresponding to any custom shipping option, then it should throw an invalid error", async () => {
const api = useApi()
try {
await api.post(
"/store/carts/test-cart-with-cso/shipping-methods",
{
option_id: "orphan-cso",
option_id: "orphan-so",
},
{ withCredentials: true }
)
} catch (err) {
expect(err.response.status).toEqual(404)
expect(err.response.data.message).toEqual(
"Shipping Option with orphan-cso was not found"
)
expect(err.response.status).toEqual(400)
expect(err.response.data.message).toEqual("Wrong shipping option")
}
})
@@ -160,7 +160,7 @@ describe("/store/shipping-options", () => {
)
})
it("given a swap cart, when user retrieves its shipping options, then should return a list of custom shipping options", async () => {
it("given a cart with custom shipping options, when user retrieves its shipping options, then should return the list of custom shipping options", async () => {
const api = useApi()
const response = await api
@@ -173,8 +173,9 @@ describe("/store/shipping-options", () => {
expect(response.data.shipping_options).toEqual(
expect.arrayContaining([
expect.objectContaining({
shipping_option_id: "test-option",
price: 0,
id: "test-option",
amount: 0,
name: "test-option",
}),
])
)