release: next (#315)

Co-authored-by: Sebastian Mateos Nicolajsen <sebastian.m.nicolajsen@gmail.com>
Co-authored-by: Abraham Ugbeshe <abrahamugbeshe@gmail.com>
Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
Sebastian Rindom
2021-07-15 09:37:27 +02:00
co-authored by Sebastian Mateos Nicolajsen Abraham Ugbeshe olivermrbl
parent 44d31b4d83
commit 2585e958de
144 changed files with 2554 additions and 240 deletions
@@ -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)