fix(utils,medusa,order,cart): fix totals when promotions are included (#9014)

* fix(utils): fix totals when promotions are included

* chore: update totals calc

* chore: ignore taxes when taxable amount is 0

* chore: use subtotals everywhere

* chore: fix shipping totals + tests
This commit is contained in:
Riqwan Thamir
2024-09-10 10:59:22 +02:00
committed by GitHub
parent 3244067ee4
commit afd0921326
12 changed files with 378 additions and 359 deletions

View File

@@ -2053,16 +2053,17 @@ medusaIntegrationTestRunner({
type: "order",
order: expect.objectContaining({
id: expect.any(String),
total: 94.764,
total: 95.4,
subtotal: 100,
tax_total: 5.364,
tax_total: 5.4,
discount_total: 10.6,
discount_tax_total: 0.636,
original_total: 95.4,
discount_subtotal: 10,
discount_tax_total: 0.6,
original_total: 106,
original_tax_total: 6,
item_total: 94.764,
item_total: 95.4,
item_subtotal: 100,
item_tax_total: 5.364,
item_tax_total: 5.4,
original_item_total: 106,
original_item_subtotal: 100,
original_item_tax_total: 6,
@@ -2078,12 +2079,13 @@ medusaIntegrationTestRunner({
product_id: product.id,
unit_price: 100,
quantity: 1,
tax_total: 5.364,
total: 94.764,
tax_total: 5.4,
total: 95.4,
subtotal: 100,
original_total: 106,
discount_total: 10.6,
discount_tax_total: 0.636,
discount_subtotal: 10,
discount_tax_total: 0.6,
original_tax_total: 6,
tax_lines: [
expect.objectContaining({
@@ -2140,7 +2142,7 @@ medusaIntegrationTestRunner({
payment_collections: [
expect.objectContaining({
currency_code: "usd",
amount: 94.764,
amount: 95.4,
status: "authorized",
}),
],

View File

@@ -1,18 +1,5 @@
import {
ICartModuleService,
IFulfillmentModuleService,
IInventoryService,
IOrderModuleService,
IPaymentModuleService,
IPricingModuleService,
IProductModuleService,
IRegionModuleService,
IStockLocationService,
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
ModuleRegistrationName,
} from "@medusajs/utils"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
@@ -27,29 +14,10 @@ medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
let appContainer
let cartModuleService: ICartModuleService
let regionModuleService: IRegionModuleService
let productModule: IProductModuleService
let paymentModule: IPaymentModuleService
let pricingModule: IPricingModuleService
let inventoryModule: IInventoryService
let stockLocationModule: IStockLocationService
let fulfillmentModule: IFulfillmentModuleService
let orderModule: IOrderModuleService
let remoteLink, remoteQuery
beforeAll(async () => {
appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION)
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
inventoryModule = appContainer.resolve(ModuleRegistrationName.INVENTORY)
fulfillmentModule = appContainer.resolve(
ModuleRegistrationName.FULFILLMENT
)
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
remoteQuery = appContainer.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
orderModule = appContainer.resolve(ModuleRegistrationName.ORDER)
})
@@ -144,12 +112,12 @@ medusaIntegrationTestRunner({
summary: expect.objectContaining({
// TODO: add all summary fields
}),
total: 59.79,
total: 59.9,
subtotal: 60,
tax_total: 0.89,
tax_total: 0.9,
discount_total: 1.1,
discount_tax_total: 0.11,
original_total: 60.9,
discount_tax_total: 0.1,
original_total: 61,
original_tax_total: 1,
item_total: 50,
item_subtotal: 50,
@@ -157,16 +125,16 @@ medusaIntegrationTestRunner({
original_item_total: 50,
original_item_subtotal: 50,
original_item_tax_total: 0,
shipping_total: 9.79,
shipping_total: 9.9,
shipping_subtotal: 10,
shipping_tax_total: 0.89,
shipping_tax_total: 0.9,
original_shipping_tax_total: 1,
original_shipping_subtotal: 10,
original_shipping_total: 11,
created_at: expect.any(String),
updated_at: expect.any(String),
raw_total: {
value: "59.789999999999999995",
value: "59.899999999999999995",
precision: 20,
},
raw_subtotal: {
@@ -294,6 +262,7 @@ medusaIntegrationTestRunner({
original_total: 50,
discount_total: 5e-18,
discount_tax_total: 0,
discount_subtotal: 5e-18,
tax_total: 0,
original_tax_total: 0,
refundable_total: 50,
@@ -320,6 +289,10 @@ medusaIntegrationTestRunner({
value: "5e-18",
precision: 20,
},
raw_discount_subtotal: {
precision: 20,
value: "5e-18",
},
raw_discount_tax_total: {
value: "0",
precision: 20,
@@ -432,10 +405,10 @@ medusaIntegrationTestRunner({
deleted_at: null,
shipping_method_id: expect.any(String),
rate: 10,
total: 0.89,
total: 0.9,
subtotal: 1,
raw_total: {
value: "0.89",
value: "0.9",
precision: 20,
},
raw_subtotal: {
@@ -474,18 +447,18 @@ medusaIntegrationTestRunner({
]),
amount: 10,
subtotal: 10,
total: 9.79,
total: 9.9,
original_total: 11,
discount_total: 1.1,
discount_tax_total: 0.11,
tax_total: 0.89,
discount_tax_total: 0.1,
tax_total: 0.9,
original_tax_total: 1,
raw_subtotal: {
value: "10",
precision: 20,
},
raw_total: {
value: "9.79",
value: "9.9",
precision: 20,
},
raw_original_total: {
@@ -497,11 +470,11 @@ medusaIntegrationTestRunner({
precision: 20,
},
raw_discount_tax_total: {
value: "0.11",
value: "0.1",
precision: 20,
},
raw_tax_total: {
value: "0.89",
value: "0.9",
precision: 20,
},
raw_original_tax_total: {