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

View File

@@ -101,7 +101,7 @@ module.exports = async (connection, data = {}) => {
await manager.save(swap)
const rmaCart = manager.create(Cart, {
const cartWithCustomSo = manager.create(Cart, {
id: "test-cart-rma",
customer_id: "test-customer",
email: "test-customer@email.com",
@@ -109,20 +109,26 @@ module.exports = async (connection, data = {}) => {
billing_address_id: "test-billing-address",
region_id: "test-region",
type: "swap",
custom_shipping_options: [
{
shipping_option_id: "test-option",
price: 0,
},
],
metadata: {
swap_id: "test-swap",
parent_order_id: orderWithSwap.id,
},
})
await manager.save(rmaCart)
await manager.save(cartWithCustomSo)
const swapWithRMAMethod = manager.create(Swap, {
id: "test-swap-rma",
order_id: "order-with-swap",
payment_status: "captured",
fulfillment_status: "fulfilled",
cart_id: "test-cart-rma",
cart_id: cartWithCustomSo.id,
payment: {
id: "test-payment-swap",
amount: 10000,
@@ -144,12 +150,6 @@ module.exports = async (connection, data = {}) => {
cart_id: "test-cart",
},
],
rma_shipping_options: [
{
shipping_option_id: "test-option",
price: 0,
},
],
})
await manager.save(swapWithRMAMethod)

View File

@@ -8,15 +8,15 @@
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {
"@medusajs/medusa": "1.1.41-dev-1633030366783",
"medusa-interfaces": "1.1.23-dev-1633030366783",
"@medusajs/medusa": "1.1.41-dev-1633520747607",
"medusa-interfaces": "1.1.23-dev-1633520747607",
"typeorm": "^0.2.31"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"babel-preset-medusa-package": "1.1.15-dev-1633030366783",
"babel-preset-medusa-package": "1.1.15-dev-1633520747607",
"jest": "^26.6.3"
}
}

View File

@@ -1223,10 +1223,10 @@
"@types/yargs" "^15.0.0"
chalk "^4.0.0"
"@medusajs/medusa-cli@1.1.18-dev-1633030366783":
version "1.1.18-dev-1633030366783"
resolved "http://localhost:4873/@medusajs%2fmedusa-cli/-/medusa-cli-1.1.18-dev-1633030366783.tgz#1112165ea9c03c797cd8d01f1149da989b9bea55"
integrity sha512-EIDxOs9STvFWwXv+8VWetrzABkijGOzcbKJzJ1jeDYjl61uRnELoWg57aeWj6wzKcTjhYRRKDrivMRUiexkHsA==
"@medusajs/medusa-cli@1.1.18-dev-1633520747607":
version "1.1.18-dev-1633520747607"
resolved "http://localhost:4873/@medusajs%2fmedusa-cli/-/medusa-cli-1.1.18-dev-1633520747607.tgz#46a3f73f6aff016f50a8123f47d69c64b7a52037"
integrity sha512-4KLnR6gq8R3sCAhOcYCI5SE+G9vyt2l6RyImvvPw7I03iDiNMc3URwoq2cFwV+V4dSrW59WFIlMJR7ALCTygdA==
dependencies:
"@babel/polyfill" "^7.8.7"
"@babel/runtime" "^7.9.6"
@@ -1244,8 +1244,8 @@
is-valid-path "^0.1.1"
joi-objectid "^3.0.1"
meant "^1.0.1"
medusa-core-utils "1.1.22-dev-1633030366783"
medusa-telemetry "0.0.5-dev-1633030366783"
medusa-core-utils "1.1.22-dev-1633520747607"
medusa-telemetry "0.0.5-dev-1633520747607"
netrc-parser "^3.1.6"
open "^8.0.6"
ora "^5.4.1"
@@ -1259,13 +1259,13 @@
winston "^3.3.3"
yargs "^15.3.1"
"@medusajs/medusa@1.1.41-dev-1633030366783":
version "1.1.41-dev-1633030366783"
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.41-dev-1633030366783.tgz#0beb57e9844c3b85c59bfcde86183a2a625e3a91"
integrity sha512-b1QGscpszVYhDLOea7WhbW0DCgEKBKchHP1nNLj07mWTxE5vOBuAZeUSh1FHNw0jbPhtn9mOaFz2wwIgxPcfqw==
"@medusajs/medusa@1.1.41-dev-1633520747607":
version "1.1.41-dev-1633520747607"
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.41-dev-1633520747607.tgz#82efd5b0bbaaaac76ce740dc9b35fe47c780592f"
integrity sha512-D+1WVpMWDaVki+Ti3rXYAl+3rb3eaX16BZ1RU/bG7FbhFJt8P1a1LXwMMQLV2rG/mUDgs6kDyl2qhYTzZ7X7aA==
dependencies:
"@hapi/joi" "^16.1.8"
"@medusajs/medusa-cli" "1.1.18-dev-1633030366783"
"@medusajs/medusa-cli" "1.1.18-dev-1633520747607"
"@types/lodash" "^4.14.168"
awilix "^4.2.3"
body-parser "^1.19.0"
@@ -1287,8 +1287,8 @@
joi "^17.3.0"
joi-objectid "^3.0.1"
jsonwebtoken "^8.5.1"
medusa-core-utils "1.1.22-dev-1633030366783"
medusa-test-utils "1.1.25-dev-1633030366783"
medusa-core-utils "1.1.22-dev-1633520747607"
medusa-test-utils "1.1.25-dev-1633520747607"
morgan "^1.9.1"
multer "^1.4.2"
passport "^0.4.0"
@@ -1933,10 +1933,10 @@ babel-preset-jest@^26.6.2:
babel-plugin-jest-hoist "^26.6.2"
babel-preset-current-node-syntax "^1.0.0"
babel-preset-medusa-package@1.1.15-dev-1633030366783:
version "1.1.15-dev-1633030366783"
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.15-dev-1633030366783.tgz#00f8aa5ebcb98c9a161a2c12dad55ffac53df88c"
integrity sha512-A/qfZNpIcYFMjAHYqVvavP9uY7ODtKGaQwZyx9quFydxebLSUstHTJ5s9ES1XjqhRYpEy//ixwNBkzggig0F9w==
babel-preset-medusa-package@1.1.15-dev-1633520747607:
version "1.1.15-dev-1633520747607"
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.15-dev-1633520747607.tgz#ac970d565ac9803333bb5fecc7d16c162302c97b"
integrity sha512-XpU4J3xmdk8y2QRrxXFbkCq+9OzqUNeZlPAffiGlFTWYx0VRD4tZS4DWazrA5ub3RfqMFl/cxZA6NBcbJhZ/iQ==
dependencies:
"@babel/plugin-proposal-class-properties" "^7.12.1"
"@babel/plugin-proposal-decorators" "^7.12.1"
@@ -5110,25 +5110,25 @@ media-typer@0.3.0:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
medusa-core-utils@1.1.22-dev-1633030366783:
version "1.1.22-dev-1633030366783"
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.22-dev-1633030366783.tgz#988358df8d8c7350d4fea3c3c00ae9f2e4aaa434"
integrity sha512-WYJ141mu6aYFGO9Vs9lXx+mJWXogrASxWJOIT29bZIFuaqI/LuiZysFn+Y6tzGBHLRdMKwHE+u/Zg1vh1NGfrw==
medusa-core-utils@1.1.22-dev-1633520747607:
version "1.1.22-dev-1633520747607"
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.22-dev-1633520747607.tgz#d18c79e4ba9ee8b373bfc02024e23763f079ab87"
integrity sha512-pP1FdbrXbHqRxzMh2nKX6ByxtCrNSjJzOIJ45k1/Kl41VortD9EYiOpuLGOdodkD1jbuf6aV4x0zNIoWpGyHew==
dependencies:
joi "^17.3.0"
joi-objectid "^3.0.1"
medusa-interfaces@1.1.23-dev-1633030366783:
version "1.1.23-dev-1633030366783"
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.23-dev-1633030366783.tgz#d3cb82493e2bb53ff728e369d38183d964ac2cc9"
integrity sha512-7X3KnKUJHBye7ikmLouvYQCCINHb2DpBy9cOQKpUSwsaKlUMIvxJq2T+AieuwWhiTACwAwTLiWshSILUdbvKcQ==
medusa-interfaces@1.1.23-dev-1633520747607:
version "1.1.23-dev-1633520747607"
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.23-dev-1633520747607.tgz#9487b2979cee9784b219a2117cf7199fbfadceb7"
integrity sha512-jyoc0wemXrZBtJMA6e7FcdnB/7do7j6oyLevCon7A6HibqQkuxLZ7TfWLHGROj4qy8aP8sAvtuXq9gpwkIm3CQ==
dependencies:
medusa-core-utils "1.1.22-dev-1633030366783"
medusa-core-utils "1.1.22-dev-1633520747607"
medusa-telemetry@0.0.5-dev-1633030366783:
version "0.0.5-dev-1633030366783"
resolved "http://localhost:4873/medusa-telemetry/-/medusa-telemetry-0.0.5-dev-1633030366783.tgz#ee9368da672a5f46d323a98b521d49983f6f1e9d"
integrity sha512-BU1XyCWS2iX5lqfxcCRAxOCrtY55eLyH1XoLLPoO8dWKIDn3G0uh4N/WKBPn40cVLbeTRqOoVRYQP6jnuEjn6w==
medusa-telemetry@0.0.5-dev-1633520747607:
version "0.0.5-dev-1633520747607"
resolved "http://localhost:4873/medusa-telemetry/-/medusa-telemetry-0.0.5-dev-1633520747607.tgz#c8d23d5acf744eea8c88102a792b481051f84fb9"
integrity sha512-YX2hKGIANC0Ha9QKkMz5se9wDLJ940VEXwlMMGZzIRHoCoNpmxnsgXQXgeCtC1LKmlcaOaOzMqYyk19fgVCybQ==
dependencies:
axios "^0.21.1"
axios-retry "^3.1.9"
@@ -5140,13 +5140,13 @@ medusa-telemetry@0.0.5-dev-1633030366783:
remove-trailing-slash "^0.1.1"
uuid "^8.3.2"
medusa-test-utils@1.1.25-dev-1633030366783:
version "1.1.25-dev-1633030366783"
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.25-dev-1633030366783.tgz#97b8235e4fbfd5cf16ed91444df1af44d4c45a60"
integrity sha512-9cztZpuTMbn++Zg/06+vlOnAFa7jUAFf7o7i7kXQGXInlJngS0Tw9pq8H0vQ4vz7QRdiOiFPXb11gymLUT64uA==
medusa-test-utils@1.1.25-dev-1633520747607:
version "1.1.25-dev-1633520747607"
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.25-dev-1633520747607.tgz#7c283312d241e012ce9814841ab0fcb0e141245e"
integrity sha512-rW4GRGXlKBoqHeX3AvPWpV9R6AWe5CXEhDcTxxPNk/Nog8E8zBlWDHsff1057RagVIMjd4wkFx4Kz3mgUMgQAg==
dependencies:
"@babel/plugin-transform-classes" "^7.9.5"
medusa-core-utils "1.1.22-dev-1633030366783"
medusa-core-utils "1.1.22-dev-1633520747607"
randomatic "^3.1.1"
merge-descriptors@1.0.1: