Merge pull request #309 from medusajs/fix/segment-return-reasons
fix(medusa-plugin-segment): sends return reasons on Order Refunded event
This commit is contained in:
@@ -134,6 +134,68 @@ describe("SegmentService", () => {
|
||||
})
|
||||
})
|
||||
|
||||
it("successfully adds return reason and note on buildOrder", async () => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
const order = orderFactory()
|
||||
order.items = order.items.map((i) => {
|
||||
i.note = "testing 1234"
|
||||
i.reason = {
|
||||
value: "test_reason",
|
||||
id: "rr_test",
|
||||
}
|
||||
return i
|
||||
})
|
||||
const segmentOrder = await segmentService.buildOrder(order)
|
||||
|
||||
expect(segmentOrder).toEqual({
|
||||
checkout_id: "cart_13",
|
||||
coupon: undefined,
|
||||
currency: "DKK",
|
||||
discount: 0,
|
||||
email: "test@example.com",
|
||||
order_id: "12355",
|
||||
payment_provider: "",
|
||||
products: [
|
||||
{
|
||||
category: "Collection",
|
||||
name: "Test",
|
||||
price: 4.47,
|
||||
product_id: "prod_123",
|
||||
quantity: 2,
|
||||
reporting_revenue: 8.94,
|
||||
sku: "",
|
||||
subtitle: "Subtitle",
|
||||
type: "Type",
|
||||
variant: "TEST",
|
||||
reason_id: "rr_test",
|
||||
reason_value: "test_reason",
|
||||
note: "testing 1234",
|
||||
},
|
||||
],
|
||||
region_id: "reg_123",
|
||||
reporting_discount: 0,
|
||||
reporting_revenue: 123.99,
|
||||
reporting_shipping: 123.99,
|
||||
reporting_subtotal: 22,
|
||||
reporting_tax: 0,
|
||||
reporting_total: 123.99,
|
||||
revenue: 123.99,
|
||||
shipping: 123.99,
|
||||
shipping_city: undefined,
|
||||
shipping_country: "DK",
|
||||
shipping_methods: [
|
||||
{
|
||||
name: "standard",
|
||||
price: 12399,
|
||||
},
|
||||
],
|
||||
subtotal: 22,
|
||||
tax: 0,
|
||||
total: 123.99,
|
||||
})
|
||||
})
|
||||
|
||||
it("successfully builds order with zero decimal currency", async () => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ class SegmentService extends BaseService {
|
||||
{ relations: ["collection", "type"] }
|
||||
)
|
||||
|
||||
return {
|
||||
const toReturn = {
|
||||
name,
|
||||
variant,
|
||||
price: this.rounded_(
|
||||
@@ -155,6 +155,19 @@ class SegmentService extends BaseService {
|
||||
sku,
|
||||
quantity: item.quantity,
|
||||
}
|
||||
|
||||
// If we are building a refund order include details about
|
||||
// the reason for return
|
||||
if (item.reason) {
|
||||
toReturn.reason_id = item.reason.id
|
||||
toReturn.reason_value = item.reason.value
|
||||
}
|
||||
|
||||
if (item.note) {
|
||||
toReturn.note = item.note
|
||||
}
|
||||
|
||||
return toReturn
|
||||
})
|
||||
),
|
||||
}
|
||||
|
||||
@@ -163,7 +163,9 @@ class OrderSubscriber {
|
||||
],
|
||||
})
|
||||
|
||||
const ret = await this.returnService_.retrieve(return_id)
|
||||
const ret = await this.returnService_.retrieve(return_id, {
|
||||
relations: ["items", "items.reason"],
|
||||
})
|
||||
|
||||
const shipping = []
|
||||
if (ret.shipping_method && ret.shipping_method.price) {
|
||||
@@ -185,7 +187,17 @@ class OrderSubscriber {
|
||||
const toBuildFrom = {
|
||||
...order,
|
||||
shipping_methods: shipping,
|
||||
items: ret.items.map((i) => merged.find((l) => l.id === i.item_id)),
|
||||
items: ret.items.map((i) => {
|
||||
const li = merged.find((l) => l.id === i.item_id)
|
||||
if (i.reason) {
|
||||
li.reason = i.reason
|
||||
}
|
||||
|
||||
if (i.note) {
|
||||
li.note = i.note
|
||||
}
|
||||
return li
|
||||
}),
|
||||
}
|
||||
|
||||
const orderData = await segmentService.buildOrder(toBuildFrom)
|
||||
|
||||
@@ -879,6 +879,18 @@
|
||||
exec-sh "^0.3.2"
|
||||
minimist "^1.2.0"
|
||||
|
||||
"@hapi/hoek@^9.0.0":
|
||||
version "9.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.2.0.tgz#f3933a44e365864f4dad5db94158106d511e8131"
|
||||
integrity sha512-sqKVVVOe5ivCaXDWivIJYVSaEgdQK9ul7a4Kity5Iw7u9+wBAPbX1RMSnLLmp7O4Vzj0WOWwMAJsTL00xwaNug==
|
||||
|
||||
"@hapi/topo@^5.0.0":
|
||||
version "5.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012"
|
||||
integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==
|
||||
dependencies:
|
||||
"@hapi/hoek" "^9.0.0"
|
||||
|
||||
"@istanbuljs/load-nyc-config@^1.0.0":
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
|
||||
@@ -1071,6 +1083,23 @@
|
||||
component-type "^1.2.1"
|
||||
join-component "^1.1.0"
|
||||
|
||||
"@sideway/address@^4.1.0":
|
||||
version "4.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.2.tgz#811b84333a335739d3969cfc434736268170cad1"
|
||||
integrity sha512-idTz8ibqWFrPU8kMirL0CoPH/A29XOzzAzpyN3zQ4kAWnzmNfFmRaoMNN6VI8ske5M73HZyhIaW4OuSFIdM4oA==
|
||||
dependencies:
|
||||
"@hapi/hoek" "^9.0.0"
|
||||
|
||||
"@sideway/formula@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@sideway/formula/-/formula-3.0.0.tgz#fe158aee32e6bd5de85044be615bc08478a0a13c"
|
||||
integrity sha512-vHe7wZ4NOXVfkoRb8T5otiENVlT7a3IAiw7H5M2+GO+9CDgcVUUsX1zalAztCmwyOr2RUTGJdgB+ZvSVqmdHmg==
|
||||
|
||||
"@sideway/pinpoint@^2.0.0":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df"
|
||||
integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==
|
||||
|
||||
"@sinonjs/commons@^1.7.0":
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.0.tgz#c8d68821a854c555bba172f3b06959a0039b236d"
|
||||
@@ -2997,6 +3026,11 @@ is-number@^3.0.0:
|
||||
dependencies:
|
||||
kind-of "^3.0.2"
|
||||
|
||||
is-number@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-number/-/is-number-4.0.0.tgz#0026e37f5454d73e356dfe6564699867c6a7f0ff"
|
||||
integrity sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==
|
||||
|
||||
is-number@^7.0.0:
|
||||
version "7.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
|
||||
@@ -3487,6 +3521,22 @@ jest@^25.5.2:
|
||||
import-local "^3.0.2"
|
||||
jest-cli "^25.5.4"
|
||||
|
||||
joi-objectid@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/joi-objectid/-/joi-objectid-3.0.1.tgz#63ace7860f8e1a993a28d40c40ffd8eff01a3668"
|
||||
integrity sha512-V/3hbTlGpvJ03Me6DJbdBI08hBTasFOmipsauOsxOSnsF1blxV537WTl1zPwbfcKle4AK0Ma4OPnzMH4LlvTpQ==
|
||||
|
||||
joi@^17.3.0:
|
||||
version "17.4.0"
|
||||
resolved "https://registry.yarnpkg.com/joi/-/joi-17.4.0.tgz#b5c2277c8519e016316e49ababd41a1908d9ef20"
|
||||
integrity sha512-F4WiW2xaV6wc1jxete70Rw4V/VuMd6IN+a5ilZsxG4uYtUXWu2kq9W5P2dz30e7Gmw8RCbY/u/uk+dMPma9tAg==
|
||||
dependencies:
|
||||
"@hapi/hoek" "^9.0.0"
|
||||
"@hapi/topo" "^5.0.0"
|
||||
"@sideway/address" "^4.1.0"
|
||||
"@sideway/formula" "^3.0.0"
|
||||
"@sideway/pinpoint" "^2.0.0"
|
||||
|
||||
join-component@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/join-component/-/join-component-1.1.0.tgz#b8417b750661a392bee2c2537c68b2a9d4977cd5"
|
||||
@@ -3726,6 +3776,11 @@ map-visit@^1.0.0:
|
||||
dependencies:
|
||||
object-visit "^1.0.0"
|
||||
|
||||
math-random@^1.0.1:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.4.tgz#5dd6943c938548267016d4e34f057583080c514c"
|
||||
integrity sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==
|
||||
|
||||
md5@^2.2.1:
|
||||
version "2.2.1"
|
||||
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
|
||||
@@ -3740,6 +3795,23 @@ 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.16:
|
||||
version "1.1.16"
|
||||
resolved "https://registry.yarnpkg.com/medusa-core-utils/-/medusa-core-utils-1.1.16.tgz#e7002d861aebf81dec7bd0654615eefbd55cb530"
|
||||
integrity sha512-O176mtAILLbwahxJu2dAOZRnz9AzrX6Oa1NDhrtbBvaPuaFZlhxiajwZkP3KM58bGZ9feKfJ4mVuY2Mtsgj3YA==
|
||||
dependencies:
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
|
||||
medusa-test-utils@^1.1.19:
|
||||
version "1.1.19"
|
||||
resolved "https://registry.yarnpkg.com/medusa-test-utils/-/medusa-test-utils-1.1.19.tgz#f765b6ba39e0bfe6301423a9b39d4e7e3b1ed32b"
|
||||
integrity sha512-GkGWOUQsrNTm7tv2P7fG9f651+C05cLpy+nuPPSouIAkxpS0mDqeD1VSrHjFnpz1BPUsjwJGWFFAH5Jd8X5yvQ==
|
||||
dependencies:
|
||||
"@babel/plugin-transform-classes" "^7.9.5"
|
||||
medusa-core-utils "^1.1.16"
|
||||
randomatic "^3.1.1"
|
||||
|
||||
merge-descriptors@1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
|
||||
@@ -4290,6 +4362,15 @@ qs@~6.5.2:
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
||||
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
|
||||
|
||||
randomatic@^3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed"
|
||||
integrity sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw==
|
||||
dependencies:
|
||||
is-number "^4.0.0"
|
||||
kind-of "^6.0.0"
|
||||
math-random "^1.0.1"
|
||||
|
||||
range-parser@~1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
|
||||
|
||||
Reference in New Issue
Block a user