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:
@@ -1,3 +1,4 @@
|
||||
import { createCartCreditLinesWorkflow } from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
Modules,
|
||||
@@ -1101,6 +1102,19 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should successfully complete cart", async () => {
|
||||
createCartCreditLinesWorkflow.run({
|
||||
input: [
|
||||
{
|
||||
cart_id: cart.id,
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
reference: "test",
|
||||
reference_id: "test",
|
||||
},
|
||||
],
|
||||
container: appContainer,
|
||||
})
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cart.id}/complete`,
|
||||
{},
|
||||
@@ -1112,6 +1126,13 @@ medusaIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
credit_lines: [
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
reference: "test",
|
||||
reference_id: "test",
|
||||
}),
|
||||
],
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
unit_price: 1500,
|
||||
@@ -1463,8 +1484,6 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should complete a cart with inventory item shared between variants", async () => {
|
||||
console.log(cart)
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cart.id}/complete`,
|
||||
{},
|
||||
|
||||
@@ -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([])
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user