feat(medusa): Cart and totals computational optimizations (#2475)
This commit is contained in:
1 parent
755ba90c05
commit
d2b1848e52
29 files changed
+3005
-666
No files matched your search
@@ -1866,25 +1866,28 @@ describe("/admin/products", () => {
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
|
||||
expect(insertedVariant.prices).toEqual([
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
variant_id: insertedVariant.id,
|
||||
region_id: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
variant_id: insertedVariant.id,
|
||||
region_id: "test-region",
|
||||
}),
|
||||
])
|
||||
expect(insertedVariant.prices).toHaveLength(2)
|
||||
expect(insertedVariant.prices).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
variant_id: insertedVariant.id,
|
||||
region_id: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
variant_id: insertedVariant.id,
|
||||
region_id: "test-region",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -66,7 +66,9 @@ describe("/store/carts", () => {
|
||||
tax_rate: 0,
|
||||
})
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id='region' WHERE iso_2 = 'us'`
|
||||
`UPDATE "country"
|
||||
SET region_id='region'
|
||||
WHERE iso_2 = 'us'`
|
||||
)
|
||||
})
|
||||
|
||||
@@ -88,9 +90,12 @@ describe("/store/carts", () => {
|
||||
const api = useApi()
|
||||
|
||||
await dbConnection.manager.query(
|
||||
`UPDATE "country" SET region_id=null WHERE iso_2 = 'us'`
|
||||
`UPDATE "country"
|
||||
SET region_id=null
|
||||
WHERE iso_2 = 'us'`
|
||||
)
|
||||
await dbConnection.manager.query(`DELETE from region`)
|
||||
await dbConnection.manager.query(`DELETE
|
||||
from region`)
|
||||
|
||||
try {
|
||||
await api.post("/store/carts")
|
||||
@@ -1679,7 +1684,9 @@ describe("/store/carts", () => {
|
||||
const manager = dbConnection.manager
|
||||
const api = useApi()
|
||||
await manager.query(
|
||||
`UPDATE "cart" SET completed_at=current_timestamp WHERE id = 'test-cart-2'`
|
||||
`UPDATE "cart"
|
||||
SET completed_at=current_timestamp
|
||||
WHERE id = 'test-cart-2'`
|
||||
)
|
||||
try {
|
||||
await api.post(`/store/carts/test-cart-2/complete-cart`)
|
||||
@@ -1982,7 +1989,8 @@ describe("/store/carts", () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
await dbConnection.manager.query(
|
||||
`INSERT INTO "cart_discounts" (cart_id, discount_id) VALUES ('test-cart', 'free-shipping')`
|
||||
`INSERT INTO "cart_discounts" (cart_id, discount_id)
|
||||
VALUES ('test-cart', 'free-shipping')`
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
-30
@@ -432,7 +432,6 @@ Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<Date>,
|
||||
"description": "",
|
||||
"discount_total": 0,
|
||||
"fulfilled_quantity": 2,
|
||||
"has_shipping": null,
|
||||
"id": Any<String>,
|
||||
@@ -440,13 +439,10 @@ Object {
|
||||
"is_return": false,
|
||||
"metadata": null,
|
||||
"order_id": Any<String>,
|
||||
"original_tax_total": 400,
|
||||
"original_total": 2400,
|
||||
"quantity": 2,
|
||||
"returned_quantity": 1,
|
||||
"shipped_quantity": 2,
|
||||
"should_merge": true,
|
||||
"subtotal": 2000,
|
||||
"swap_id": null,
|
||||
"tax_lines": Array [
|
||||
Object {
|
||||
@@ -460,10 +456,8 @@ Object {
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
],
|
||||
"tax_total": 400,
|
||||
"thumbnail": "",
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"total": 2400,
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"variant": Object {
|
||||
@@ -774,7 +768,6 @@ Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<Date>,
|
||||
"description": "",
|
||||
"discount_total": 0,
|
||||
"fulfilled_quantity": null,
|
||||
"has_shipping": null,
|
||||
"id": "test-item",
|
||||
@@ -782,14 +775,11 @@ Object {
|
||||
"is_return": false,
|
||||
"metadata": null,
|
||||
"order_id": Any<String>,
|
||||
"original_tax_total": 400,
|
||||
"original_total": 2400,
|
||||
"price": "10.00 USD",
|
||||
"quantity": 2,
|
||||
"returned_quantity": null,
|
||||
"shipped_quantity": null,
|
||||
"should_merge": true,
|
||||
"subtotal": 2000,
|
||||
"swap_id": null,
|
||||
"tax_lines": Array [
|
||||
Object {
|
||||
@@ -803,10 +793,8 @@ Object {
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
],
|
||||
"tax_total": 400,
|
||||
"thumbnail": null,
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"total": 2400,
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"variant": Object {
|
||||
@@ -1003,7 +991,6 @@ Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<Date>,
|
||||
"description": "",
|
||||
"discount_total": 0,
|
||||
"discounted_price": "12.00 USD",
|
||||
"fulfilled_quantity": 2,
|
||||
"has_shipping": null,
|
||||
@@ -1012,14 +999,11 @@ Object {
|
||||
"is_return": false,
|
||||
"metadata": null,
|
||||
"order_id": Any<String>,
|
||||
"original_tax_total": 400,
|
||||
"original_total": 2400,
|
||||
"price": "12.00 USD",
|
||||
"quantity": 2,
|
||||
"returned_quantity": null,
|
||||
"shipped_quantity": 2,
|
||||
"should_merge": true,
|
||||
"subtotal": 2000,
|
||||
"swap_id": null,
|
||||
"tax_lines": Array [
|
||||
Object {
|
||||
@@ -1033,10 +1017,8 @@ Object {
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
],
|
||||
"tax_total": 400,
|
||||
"thumbnail": null,
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"total": 2400,
|
||||
"totals": Object {
|
||||
"discount_total": 0,
|
||||
"original_tax_total": 400,
|
||||
@@ -1276,7 +1258,6 @@ Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<Date>,
|
||||
"description": "",
|
||||
"discount_total": 0,
|
||||
"fulfilled_quantity": 2,
|
||||
"has_shipping": null,
|
||||
"id": "test-item",
|
||||
@@ -1284,13 +1265,10 @@ Object {
|
||||
"is_return": false,
|
||||
"metadata": null,
|
||||
"order_id": Any<String>,
|
||||
"original_tax_total": 400,
|
||||
"original_total": 2400,
|
||||
"quantity": 2,
|
||||
"returned_quantity": null,
|
||||
"shipped_quantity": 2,
|
||||
"should_merge": true,
|
||||
"subtotal": 2000,
|
||||
"swap_id": null,
|
||||
"tax_lines": Array [
|
||||
Object {
|
||||
@@ -1304,10 +1282,8 @@ Object {
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
],
|
||||
"tax_total": 400,
|
||||
"thumbnail": "",
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"total": 2400,
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"variant": Object {
|
||||
@@ -1603,7 +1579,6 @@ Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<Date>,
|
||||
"description": "",
|
||||
"discount_total": 0,
|
||||
"fulfilled_quantity": 2,
|
||||
"has_shipping": null,
|
||||
"id": Any<String>,
|
||||
@@ -1611,13 +1586,10 @@ Object {
|
||||
"is_return": false,
|
||||
"metadata": null,
|
||||
"order_id": Any<String>,
|
||||
"original_tax_total": 400,
|
||||
"original_total": 2400,
|
||||
"quantity": 2,
|
||||
"returned_quantity": null,
|
||||
"shipped_quantity": 2,
|
||||
"should_merge": true,
|
||||
"subtotal": 2000,
|
||||
"swap_id": null,
|
||||
"tax_lines": Array [
|
||||
Object {
|
||||
@@ -1631,10 +1603,8 @@ Object {
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
],
|
||||
"tax_total": 400,
|
||||
"thumbnail": "",
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"total": 2400,
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"variant": Object {
|
||||
|
||||
Reference in new issue
Block a user