feat(medusa): Payment Collection endpoints (#2525)
This commit is contained in:
@@ -22,7 +22,7 @@ const {
|
||||
} = require("../../factories")
|
||||
const { OrderEditItemChangeType, OrderEdit } = require("@medusajs/medusa")
|
||||
|
||||
jest.setTimeout(50000)
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
@@ -869,23 +869,82 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/order-edits", () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
const product1 = await simpleProductFactory(dbConnection)
|
||||
const product2 = await simpleProductFactory(dbConnection)
|
||||
|
||||
const { id, order_id } = await simpleOrderEditFactory(dbConnection, {
|
||||
const order = await simpleOrderFactory(dbConnection, {
|
||||
id: IdMap.getId("order-test-2"),
|
||||
email: "test@testson.com",
|
||||
tax_rate: null,
|
||||
fulfillment_status: "fulfilled",
|
||||
payment_status: "captured",
|
||||
region: {
|
||||
id: "test-region",
|
||||
name: "Test region",
|
||||
tax_rate: 0,
|
||||
},
|
||||
line_items: [
|
||||
{
|
||||
id: "lineItemId1",
|
||||
variant_id: product2.variants[0].id,
|
||||
quantity: 1,
|
||||
fulfilled_quantity: 1,
|
||||
shipped_quantity: 1,
|
||||
unit_price: 1000,
|
||||
tax_lines: [
|
||||
{
|
||||
rate: 10,
|
||||
code: "code1",
|
||||
name: "code1",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
shipping_methods: [
|
||||
{
|
||||
shipping_option: {
|
||||
name: "random",
|
||||
region_id: "test-region",
|
||||
},
|
||||
price: 10,
|
||||
tax_lines: [
|
||||
{
|
||||
rate: 0,
|
||||
code: "code1",
|
||||
name: "code1",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const { id } = await simpleOrderEditFactory(dbConnection, {
|
||||
created_by: "admin_user",
|
||||
order_id: order.id,
|
||||
})
|
||||
|
||||
const noChangesEdit = await simpleOrderEditFactory(dbConnection, {
|
||||
created_by: "admin_user",
|
||||
})
|
||||
|
||||
await simpleLineItemFactory(dbConnection, {
|
||||
order_id: order_id,
|
||||
const lineItemAdded = await simpleLineItemFactory(dbConnection, {
|
||||
order_id: null,
|
||||
order_edit_id: id,
|
||||
variant_id: product1.variants[0].id,
|
||||
unit_price: 2000,
|
||||
quantity: 1,
|
||||
tax_lines: [
|
||||
{
|
||||
rate: 0,
|
||||
code: "code1",
|
||||
name: "code1",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await simpleOrderItemChangeFactory(dbConnection, {
|
||||
order_edit_id: id,
|
||||
type: "item_add",
|
||||
type: OrderEditItemChangeType.ITEM_ADD,
|
||||
line_item_id: lineItemAdded.id,
|
||||
})
|
||||
|
||||
orderEditId = id
|
||||
@@ -900,6 +959,28 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/order-edits", () => {
|
||||
it("requests order edit", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const result = await api.post(
|
||||
`/admin/order-edits/${orderEditId}/request`,
|
||||
{
|
||||
payment_collection_description: "Payment collection description",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(result.status).toEqual(200)
|
||||
expect(result.data.order_edit).toEqual(
|
||||
expect.objectContaining({
|
||||
id: orderEditId,
|
||||
requested_at: expect.any(String),
|
||||
requested_by: "admin_user",
|
||||
status: "requested",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("creates payment collection if difference_due > 0", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const result = await api.post(
|
||||
`/admin/order-edits/${orderEditId}/request`,
|
||||
{},
|
||||
@@ -913,6 +994,7 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/order-edits", () => {
|
||||
requested_at: expect.any(String),
|
||||
requested_by: "admin_user",
|
||||
status: "requested",
|
||||
payment_collection_id: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
@@ -934,6 +1016,7 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/order-edits", () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("requests order edit", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -2635,7 +2718,6 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/order-edits", () => {
|
||||
const lineItemId2Discount = IdMap.getId("line-item-2-discount")
|
||||
|
||||
beforeEach(async () => {
|
||||
const api = useApi()
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
product = await simpleProductFactory(dbConnection, {
|
||||
@@ -2646,7 +2728,7 @@ describe("[MEDUSA_FF_ORDER_EDITING] /admin/order-edits", () => {
|
||||
id: prodId2,
|
||||
})
|
||||
|
||||
const reagion = await simpleRegionFactory(dbConnection, {
|
||||
const region = await simpleRegionFactory(dbConnection, {
|
||||
id: "test-region",
|
||||
name: "Test region",
|
||||
tax_rate: 12.5,
|
||||
|
||||
Reference in New Issue
Block a user