feat(core-flows,types,cart): add credit lines to cart (#11419)

* feat(core-flows,types,cart): add credit lines to cart

* chore: fix specs

* chore: credit lines hook

* chore: update types

* chore: added credit line totals

* chore: add totals fields to query config

* chore: add complete cart hook

* chore: add credit lines creation to order

* chore: pr ready for review

* chore: fix tests

* Apply suggestions from code review

* chore: fix types

* chore: adjust summary calculations with new totals
This commit is contained in:
Riqwan Thamir
2025-02-24 14:34:36 +01:00
committed by GitHub
parent be566ca6fb
commit fb2e86484a
27 changed files with 802 additions and 58 deletions

View File

@@ -2,9 +2,11 @@ import {
addShippingMethodToCartWorkflow,
addToCartWorkflow,
completeCartWorkflow,
createCartCreditLinesWorkflow,
createCartWorkflow,
createPaymentCollectionForCartWorkflow,
createPaymentSessionsWorkflow,
deleteCartCreditLinesWorkflow,
deleteLineItemsStepId,
deleteLineItemsWorkflow,
findOrCreateCustomerStepId,
@@ -3348,6 +3350,108 @@ medusaIntegrationTestRunner({
})
})
})
describe("createCartCreditLinesWorkflow", () => {
it("should create credit lines for a cart", async () => {
const cart = await cartModuleService.createCarts({
currency_code: "dkk",
region_id: defaultRegion.id,
shipping_address: {
metadata: {
testing_tax: true,
},
},
items: [
{
quantity: 1,
unit_price: 5000,
title: "Test item",
},
],
})
const { result: creditLines } =
await createCartCreditLinesWorkflow.run({
input: [
{
cart_id: cart.id,
amount: 1000,
reference: "test",
reference_id: "test",
metadata: {
test: "metadata",
},
},
],
container: appContainer,
})
expect(creditLines).toEqual([
expect.objectContaining({
cart_id: cart.id,
reference: "test",
reference_id: "test",
amount: 1000,
metadata: {
test: "metadata",
},
}),
])
})
})
describe("deleteCartCreditLinesWorkflow", () => {
it("should delete credit lines from a cart", async () => {
const cart = await cartModuleService.createCarts({
currency_code: "dkk",
region_id: defaultRegion.id,
shipping_address: {
metadata: {
testing_tax: true,
},
},
items: [
{
quantity: 1,
unit_price: 5000,
title: "Test item",
},
],
})
const {
result: [creditLine],
} = await createCartCreditLinesWorkflow.run({
input: [
{
cart_id: cart.id,
amount: 1000,
reference: "test",
reference_id: "test",
metadata: {
test: "metadata",
},
},
],
container: appContainer,
})
const { result } = await deleteCartCreditLinesWorkflow.run({
input: { id: [creditLine.id] },
container: appContainer,
})
const { data: creditLines } = await query.graph({
entity: "credit_line",
filters: {
id: creditLine.id,
},
fields: ["id"],
})
expect(creditLines).toEqual([])
})
})
})
},
})