chore(tests): add integration test of canceling order with many items (#4776)
What - Adds an integration test to check if canceling an order with many items succeeds. Related to #4763
This commit is contained in:
1 parent
9766758e19
commit
819d27e774
1 file changed
+81
-3
@@ -8,11 +8,10 @@ const { setPort, useApi } = require("../../../../environment-helpers/use-api")
|
|||||||
|
|
||||||
const adminSeeder = require("../../../../helpers/admin-seeder")
|
const adminSeeder = require("../../../../helpers/admin-seeder")
|
||||||
const {
|
const {
|
||||||
|
simpleLineItemFactory,
|
||||||
|
simpleSalesChannelFactory,
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleCustomerFactory,
|
simpleCustomerFactory,
|
||||||
} = require("../../../../factories")
|
|
||||||
const { simpleSalesChannelFactory } = require("../../../../factories")
|
|
||||||
const {
|
|
||||||
simpleOrderFactory,
|
simpleOrderFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
simpleCartFactory,
|
simpleCartFactory,
|
||||||
@@ -160,6 +159,85 @@ describe("/store/carts", () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("canceling an order", () => {
|
||||||
|
it("should cancel an order with many items", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const stockLocation = await stockLocationService.create({
|
||||||
|
name: "test-location",
|
||||||
|
})
|
||||||
|
await salesChannelLocationService.associateLocation(
|
||||||
|
"test-channel",
|
||||||
|
stockLocation.id
|
||||||
|
)
|
||||||
|
const inventoryItem = await inventoryService.createInventoryItem({
|
||||||
|
sku: "cancel-me",
|
||||||
|
})
|
||||||
|
await inventoryService.createInventoryLevel({
|
||||||
|
inventory_item_id: inventoryItem.id,
|
||||||
|
location_id: stockLocation.id,
|
||||||
|
stocked_quantity: 100,
|
||||||
|
})
|
||||||
|
|
||||||
|
const customer = await simpleCustomerFactory(dbConnection, {})
|
||||||
|
|
||||||
|
const cart = await simpleCartFactory(dbConnection, {
|
||||||
|
email: "testme@email.com",
|
||||||
|
region: regionId,
|
||||||
|
line_items: items,
|
||||||
|
sales_channel_id: "test-channel",
|
||||||
|
shipping_address: {},
|
||||||
|
shipping_methods: [
|
||||||
|
{
|
||||||
|
shipping_option: {
|
||||||
|
region_id: regionId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const items = []
|
||||||
|
for (let i = 0; i < 13; i++) {
|
||||||
|
const product = await simpleProductFactory(dbConnection, {})
|
||||||
|
await prodVarInventoryService.attachInventoryItem(
|
||||||
|
product.variants[0].id,
|
||||||
|
inventoryItem.id
|
||||||
|
)
|
||||||
|
const lineItem = await simpleLineItemFactory(dbConnection, {
|
||||||
|
cart_id: cart.id,
|
||||||
|
fulfilled_quantity: 0,
|
||||||
|
returned_quantity: 0,
|
||||||
|
title: "Line Item",
|
||||||
|
description: "Line Item Desc",
|
||||||
|
thumbnail: "https://test.js/1234",
|
||||||
|
unit_price: 8000,
|
||||||
|
quantity: 1,
|
||||||
|
variant_id: product.variants[0].id,
|
||||||
|
})
|
||||||
|
items.push(lineItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
await appContainer
|
||||||
|
.resolve("cartService")
|
||||||
|
.update(cart.id, { customer_id: customer.id })
|
||||||
|
|
||||||
|
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||||
|
|
||||||
|
const completeRes = await api.post(`/store/carts/${cart.id}/complete`)
|
||||||
|
|
||||||
|
const orderId = completeRes.data.data.id
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(`/admin/orders/${orderId}/cancel`, {}, adminHeaders)
|
||||||
|
.catch((e) => {
|
||||||
|
console.log(e.response.data)
|
||||||
|
throw e
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("swaps", () => {
|
describe("swaps", () => {
|
||||||
it("adjusts reservations on successful swap", async () => {
|
it("adjusts reservations on successful swap", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|||||||
Reference in new issue
Block a user