fix: Merge conflicts with master
This commit is contained in:
@@ -292,46 +292,3 @@ Array [
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`/admin/price-lists POST /admin/price-lists/:id/prices/batch Adds a batch of new prices where a MA record have a \`region_id\` instead of \`currency_code\` 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"amount": 70,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "ma_test_4",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list_id": "pl_with_some_ma",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
Object {
|
||||
"amount": 100,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "eur",
|
||||
"deleted_at": null,
|
||||
"id": Any<String>,
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list_id": "pl_with_some_ma",
|
||||
"region_id": "region-pl",
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
Object {
|
||||
"amount": 200,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": Any<String>,
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list_id": "pl_with_some_ma",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -859,45 +859,47 @@ describe("/admin/price-lists", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.price_list.prices.length).toEqual(3) // initially this PL has 1 MA record
|
||||
expect(response.data.price_list.prices).toMatchSnapshot([
|
||||
{
|
||||
id: "ma_test_4",
|
||||
currency_code: "usd",
|
||||
amount: 70,
|
||||
price_list_id: "pl_with_some_ma",
|
||||
variant_id: "test-variant",
|
||||
region_id: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
},
|
||||
{
|
||||
id: expect.any(String),
|
||||
currency_code: "eur",
|
||||
amount: 100,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: "pl_with_some_ma",
|
||||
variant_id: "test-variant",
|
||||
region_id: "region-pl",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
},
|
||||
{
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: "pl_with_some_ma",
|
||||
variant_id: "test-variant",
|
||||
region_id: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
},
|
||||
])
|
||||
expect(response.data.price_list.prices).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "ma_test_4",
|
||||
currency_code: "usd",
|
||||
amount: 70,
|
||||
price_list_id: "pl_with_some_ma",
|
||||
variant_id: "test-variant",
|
||||
region_id: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: "pl_with_some_ma",
|
||||
variant_id: "test-variant",
|
||||
region_id: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
currency_code: "eur",
|
||||
amount: 100,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: "pl_with_some_ma",
|
||||
variant_id: "test-variant",
|
||||
region_id: "region-pl",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const path = require("path")
|
||||
import { ReturnReason, ShippingMethod } from "@medusajs/medusa"
|
||||
import { createReturnableOrder } from "../claims"
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
@@ -10,6 +11,12 @@ const adminSeeder = require("../../helpers/admin-seeder")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const authHeader = {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
|
||||
describe("/admin/returns", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
@@ -51,26 +58,20 @@ describe("/admin/returns", () => {
|
||||
const api = useApi()
|
||||
|
||||
// create a swap
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/orders/test-order/swaps",
|
||||
{
|
||||
custom_shipping_options: [{ option_id: "test-option", price: 0 }],
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
const response = await api.post(
|
||||
"/admin/orders/test-order/swaps",
|
||||
{
|
||||
custom_shipping_options: [{ option_id: "test-option", price: 0 }],
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e))
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const sid = response.data.order.swaps[0].id
|
||||
const manager = dbConnection.manager
|
||||
@@ -87,76 +88,52 @@ describe("/admin/returns", () => {
|
||||
await manager.save(sm)
|
||||
|
||||
// fulfill the swap
|
||||
const fulRes = await api
|
||||
.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/fulfillments`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e))
|
||||
const fulRes = await api.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/fulfillments`,
|
||||
{},
|
||||
authHeader
|
||||
)
|
||||
|
||||
// ship the swap
|
||||
await api
|
||||
.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/shipments`,
|
||||
{
|
||||
fulfillment_id: fulRes.data.order.swaps[0].fulfillments[0].id,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e))
|
||||
await api.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/shipments`,
|
||||
{
|
||||
fulfillment_id: fulRes.data.order.swaps[0].fulfillments[0].id,
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const swapItemId = fulRes.data.order.swaps[0].additional_items[0].id
|
||||
|
||||
// request a return
|
||||
const returnRes = await api
|
||||
.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
const returnRes = await api.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const returnId = returnRes.data.order.returns[0].id
|
||||
|
||||
const receiveRes = await api
|
||||
.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
const receiveRes = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
expect(receiveRes.status).toEqual(200)
|
||||
})
|
||||
@@ -190,11 +167,7 @@ describe("/admin/returns", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
authHeader
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
@@ -214,52 +187,96 @@ describe("/admin/returns", () => {
|
||||
const claimItemId = fulRes.data.order.claims[0].additional_items[0].id
|
||||
|
||||
// request a return
|
||||
const returnRes = await api
|
||||
.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
],
|
||||
return_shipping: {
|
||||
option_id: "test-option",
|
||||
price: 0,
|
||||
const returnRes = await api.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
],
|
||||
return_shipping: {
|
||||
option_id: "test-option",
|
||||
price: 0,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const returnId = returnRes.data.order.returns[0].id
|
||||
|
||||
const receiveRes = await api
|
||||
.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
const receiveRes = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
expect(receiveRes.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/returns/:id/receive", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
return await db.teardown()
|
||||
})
|
||||
|
||||
it("should receive a return partially", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const order = await createReturnableOrder(dbConnection)
|
||||
const itemId = "test-item"
|
||||
|
||||
// create a return
|
||||
const response = await api.post(
|
||||
`/admin/orders/${order.id}/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: itemId,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const returnId = response.data.order.returns[0].id
|
||||
|
||||
// receive a return
|
||||
const receiveRes = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: itemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const receivedReturn = receiveRes.data.return
|
||||
|
||||
expect(receivedReturn.items.length).toEqual(1)
|
||||
const receivedItem = receivedReturn.items[0]
|
||||
|
||||
expect(receivedItem.requested_quantity).toEqual(2)
|
||||
expect(receivedItem.received_quantity).toEqual(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -301,7 +301,7 @@ describe("/admin/swaps", () => {
|
||||
|
||||
// ********* CREATE SWAP *********
|
||||
const createSwap = await api.post(
|
||||
`/admin/orders/${completedOrder.data.data.id}/swaps`,
|
||||
`/admin/orders/${completedOrder.data.data.id}/swaps?fields=returnable_items`,
|
||||
{
|
||||
return_items: [
|
||||
{
|
||||
@@ -318,6 +318,13 @@ describe("/admin/swaps", () => {
|
||||
}
|
||||
)
|
||||
|
||||
expect(createSwap.data.order.returnable_items).toHaveLength(1)
|
||||
expect(createSwap.data.order.returnable_items[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "line-item",
|
||||
})
|
||||
)
|
||||
|
||||
let swap = createSwap.data.order.swaps[0]
|
||||
|
||||
// ********* PREPARE SWAP CART *********
|
||||
@@ -349,7 +356,7 @@ describe("/admin/swaps", () => {
|
||||
{}
|
||||
)
|
||||
|
||||
// ********* VALIDATE *********
|
||||
// ********* VALIDATE *********
|
||||
expect(swap.data.swap.difference_due).toBe(swapCart.data.cart.total)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user