chore(order): Paid Total and Refunded Total (#7373)

This commit is contained in:
Carlos R. L. Rodrigues
2024-05-20 15:48:57 -03:00
committed by GitHub
parent 025536e2a5
commit f57dc98c7a
24 changed files with 340 additions and 175 deletions
@@ -196,9 +196,99 @@ moduleIntegrationTestRunner({
const createdOrder = await service.create(input)
const serializedOrder = JSON.parse(JSON.stringify(createdOrder))
expect(serializedOrder).toEqual(expectation)
})
it("should create an order, shipping method and items. Including taxes and adjustments associated with them and add new transactions", async function () {
const inpCopy = JSON.parse(JSON.stringify(input))
inpCopy.transactions.push({
amount: 10,
currency_code: "USD",
})
const created = await service.create(inpCopy)
const refund = await service.addTransactions([
{
order_id: created.id,
amount: -20,
currency_code: "USD",
},
])
const serializedOrder = JSON.parse(
JSON.stringify(
await service.retrieve(created.id, {
select: ["id", "summary"],
})
)
)
expect(serializedOrder.summary).toEqual(
expect.objectContaining({
paid_total: 68,
refunded_total: 20,
})
)
await service.softDeleteTransactions(refund[0].id)
const serializedOrder2 = JSON.parse(
JSON.stringify(
await service.retrieve(created.id, {
select: ["id", "summary"],
})
)
)
expect(serializedOrder2.summary).toEqual(
expect.objectContaining({
paid_total: 68,
refunded_total: 0,
})
)
await service.addTransactions([
{
order_id: created.id,
amount: -50,
currency_code: "USD",
},
])
const serializedOrder3 = JSON.parse(
JSON.stringify(
await service.retrieve(created.id, {
select: ["id", "summary"],
})
)
)
expect(serializedOrder3.summary).toEqual(
expect.objectContaining({
paid_total: 68,
refunded_total: 50,
})
)
await service.restoreTransactions(refund[0].id)
const serializedOrder4 = JSON.parse(
JSON.stringify(
await service.retrieve(created.id, {
select: ["id", "summary"],
})
)
)
expect(serializedOrder4.summary).toEqual(
expect.objectContaining({
paid_total: 68,
refunded_total: 70,
})
)
})
it("should transform requested fields and relations to match the db schema and return the order", async function () {
const createdOrder = await service.create(input)
const getOrder = await service.retrieve(createdOrder.id, {