fix: adjustments based on feedback

rename RMAShippingOption to CustomShippingOption
update models and relations
update unit and integration tests
update services
This commit is contained in:
zakariaelas
2021-10-06 14:17:36 +01:00
parent db83448d18
commit 52be911e50
29 changed files with 467 additions and 604 deletions

View File

@@ -4,7 +4,7 @@ const {
Order,
LineItem,
ProductVariant,
RMAShippingOption,
CustomShippingOption,
} = require("@medusajs/medusa")
const setupServer = require("../../../helpers/setup-server")
@@ -1277,7 +1277,7 @@ describe("/admin/orders", () => {
expect(response.status).toEqual(200)
})
it("creates a swap with rma shipping options", async () => {
it("creates a swap with custom shipping options", async () => {
const api = useApi()
const response = await api.post(
@@ -1290,7 +1290,7 @@ describe("/admin/orders", () => {
},
],
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
rma_shipping_options: [{ option_id: "test-option", price: 0 }],
custom_shipping_options: [{ option_id: "test-option", price: 0 }],
},
{
headers: {
@@ -1302,17 +1302,19 @@ describe("/admin/orders", () => {
const swap = response.data.order.swaps[0]
const manager = dbConnection.manager
const rma = await manager.findOne(RMAShippingOption, {
const customOptions = await manager.find(CustomShippingOption, {
shipping_option_id: "test-option",
swap_id: swap.id,
})
expect(response.status).toEqual(200)
expect(rma).toEqual(
expect.objectContaining({
shipping_option_id: "test-option",
price: 0,
})
expect(customOptions).toEqual(
expect.arrayContaining([
expect.objectContaining({
shipping_option_id: "test-option",
price: 0,
cart_id: swap.cart_id,
}),
])
)
})

View File

@@ -3,8 +3,8 @@ const {
Region,
LineItem,
GiftCard,
RMAShippingOption,
Cart,
CustomShippingOption,
} = require("@medusajs/medusa")
const setupServer = require("../../../helpers/setup-server")
@@ -145,7 +145,6 @@ describe("/store/carts", () => {
discounts: [{ code: "CREATED" }],
})
} catch (error) {
console.log(error.response)
expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual(
"Discount has been used maximum allowed times"
@@ -440,29 +439,41 @@ describe("/store/carts", () => {
})
describe("POST /store/carts/:id/shipping-methods", () => {
let cartWithCustomSo
beforeEach(async () => {
await cartSeeder(dbConnection)
const manager = dbConnection.manager
try {
await cartSeeder(dbConnection)
const manager = dbConnection.manager
await manager.insert(Cart, {
id: "test-cart-rma",
customer_id: "some-customer",
email: "some-customer@email.com",
shipping_address: {
id: "test-shipping-address",
first_name: "lebron",
country_code: "us",
},
region_id: "test-region",
currency_code: "usd",
type: "swap",
})
const _cart = await manager.create(Cart, {
id: "test-cart-with-cso",
customer_id: "some-customer",
email: "some-customer@email.com",
shipping_address: {
id: "test-shipping-address",
first_name: "lebron",
country_code: "us",
},
custom_shipping_options: [
{
shipping_option_id: "test-option",
price: 5,
},
],
region_id: "test-region",
currency_code: "usd",
type: "swap",
})
await manager.insert(RMAShippingOption, {
id: "test-rmaso",
shipping_option_id: "test-option",
price: 5,
})
cartWithCustomSo = await manager.save(_cart)
await manager.insert(CustomShippingOption, {
id: "orphan-cso",
price: 0,
})
} catch (err) {
console.log(err)
}
})
afterEach(async () => {
@@ -486,25 +497,46 @@ describe("/store/carts", () => {
expect(cartWithShippingMethod.status).toEqual(200)
})
it("adds a rma shipping method to cart", async () => {
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
const api = useApi()
const cartWithRMAShippingMethod = await api
const cartWithCustomShippingMethod = await api
.post(
"/store/carts/test-cart-rma/shipping-methods",
"/store/carts/test-cart-with-cso/shipping-methods",
{
option_id: "test-rmaso",
option_id: customOptionId,
},
{ withCredentials: true }
)
.catch((err) => err.response)
expect(
cartWithRMAShippingMethod.data.cart.shipping_methods
cartWithCustomShippingMethod.data.cart.shipping_methods
).toContainEqual(
expect.objectContaining({ shipping_option_id: "test-option", price: 5 })
)
expect(cartWithRMAShippingMethod.status).toEqual(200)
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 () => {
const api = useApi()
try {
await api.post(
"/store/carts/test-cart-with-cso/shipping-methods",
{
option_id: "orphan-cso",
},
{ withCredentials: true }
)
} catch (err) {
expect(err.response.status).toEqual(404)
expect(err.response.data.message).toEqual(
"Shipping Option with orphan-cso was not found"
)
}
})
it("adds a giftcard to cart, but ensures discount only applied to discountable items", async () => {

View File

@@ -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 RMA shipping options", async () => {
it("given a swap cart, when user retrieves its shipping options, then should return a list of custom shipping options", async () => {
const api = useApi()
const response = await api