Feat: use price selection strategy (#1165)
* init * add query params * added buld id validation to repo * admin done * updated price reqs * initial price selection strategy * update customer seeder * format models * price selection strategy * price selection testing * update price selection tests * update price selection strategy * remove console.warn * update price seleciton strategy * use price selection strategy in "get-product" * price selection strategy integration testing * update integration tests * update price selection strat * remove console.log * fix unit tests * update product snapshot integration tests * fix failing unit tests * update variant test snapshots * update variant test snapshots * fix failing unit tests * update product snapshot integration tests * intial implementation of PriceList * add price selection strategy test to list-products * add price selection to list products * add price selection strategy to getRegionPrice * add price selection strategy to get variant * update product snapshot test * store testing of price selection * variant services * update cart service * update product tests * update test * unit testing with price selection strategy * integration tests for price lists * update sort prices for consistent results * update snapshot * update product snapshot with product ids * this time pipelines work * swap tests * redo ordering * updated admin/product integration tests * update updateVariantPrices method * remove comment from error handler * add integration test for batch deleting prices associated with price list * named ids * run with verbose * add console.log * sort products in integration test * remove verbose flag * make update to prices through variant service limited to default prices * update store/products.js snapshot * update comment * add todo * lift existing price calculations to variant level * remove unused import * add api unit tests and update product integration tests to validate that prices from Price List are ignored * fix product test * update integration tests * pre merge commit * requested changes * cascade * ensure delete variant cascades to MoneyAmount * fetch variants correctly * use find options * add pricelist to relevant seeders * update integration tests * update price selection with "includeDiscountPrices" * use transaction with price selection strategy * add await to prevent store test errors * remove verbose * addresses PR feedback * removed unused endpoint * remove unused repository from constructor * remove from constructor argument * update mock * update unit tests * fix failing store integration tests * remove medusajs ressource * re add env.template * price selection strategy methods * fix integration tests * update unit tests * remove commented out code * update jsdoc * update price selection strategy parameter * update snapshots * integration tests cleanup * pr feedback * update integration tests * pr feedback * price selection unit tests * add calculated price type to results * cleanup include discount prices and price selection configs * refactor price selection params to a separate file * update tests and refactor price selection seeder * remove prices from variant update * rename result * pr feedback * remove unused import * create getRegionPriceContext * remove from params in search * remove unused import Co-authored-by: Kasper <kasper@medusajs.com> Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
This commit is contained in:
co-authored by
Kasper
Kasper Fabricius Kristensen
parent
491b6eba2d
commit
e2423020c0
@@ -1,10 +1,11 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/store/variants /test-variant 1`] = `
|
||||
exports[`/store/variants GET /store/variants /test-variant 1`] = `
|
||||
Object {
|
||||
"variant": Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode",
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean",
|
||||
@@ -30,6 +31,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
@@ -39,6 +41,7 @@ Object {
|
||||
"id": "test-price",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
@@ -57,71 +60,99 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/store/variants includes default relations 1`] = `
|
||||
exports[`/store/variants GET /store/variants advanced pricing /test-variant with currency code 1`] = `
|
||||
Object {
|
||||
"variants": Array [
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-variant",
|
||||
"inventory_quantity": 10,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"variant": Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode",
|
||||
"calculated_price": 80,
|
||||
"calculated_price_type": "sale",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-variant",
|
||||
"inventory_quantity": 10,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": "test-variant-option",
|
||||
"metadata": null,
|
||||
"option_id": "test-option",
|
||||
"updated_at": Any<String>,
|
||||
"value": "Default variant",
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": 100,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
Object {
|
||||
"amount": 80,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price-discount",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": "test-variant-option",
|
||||
"metadata": null,
|
||||
"option_id": "test-option",
|
||||
"description": "Winter sale for VIP customers.",
|
||||
"ends_at": null,
|
||||
"id": "pl",
|
||||
"name": "VIP winter sale",
|
||||
"starts_at": null,
|
||||
"status": "active",
|
||||
"type": "sale",
|
||||
"updated_at": Any<String>,
|
||||
"value": "Default variant",
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"product": Any<Object>,
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku",
|
||||
"title": "Test variant",
|
||||
"upc": "test-upc",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"price_list_id": "pl",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"product": Any<Object>,
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku",
|
||||
"title": "Test variant",
|
||||
"upc": "test-upc",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/store/variants lists by title 1`] = `
|
||||
exports[`/store/variants GET /store/variants advanced pricing lists by title 1`] = `
|
||||
Object {
|
||||
"variants": Array [
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": null,
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": null,
|
||||
@@ -147,6 +178,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
@@ -156,6 +188,7 @@ Object {
|
||||
"id": Any<String>,
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
@@ -174,3 +207,151 @@ Object {
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/store/variants GET /store/variants advanced pricing sets additional prices correctly when querying a variant 1`] = `
|
||||
Object {
|
||||
"variant": Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode",
|
||||
"calculated_price": 80,
|
||||
"calculated_price_type": "sale",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-variant",
|
||||
"inventory_quantity": 10,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": "test-variant-option",
|
||||
"metadata": null,
|
||||
"option_id": "test-option",
|
||||
"updated_at": Any<String>,
|
||||
"value": "Default variant",
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": 100,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
Object {
|
||||
"amount": 80,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price-discount",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "Winter sale for VIP customers.",
|
||||
"ends_at": null,
|
||||
"id": "pl",
|
||||
"name": "VIP winter sale",
|
||||
"starts_at": null,
|
||||
"status": "active",
|
||||
"type": "sale",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"price_list_id": "pl",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"product": Any<Object>,
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku",
|
||||
"title": "Test variant",
|
||||
"upc": "test-upc",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/store/variants GET /store/variants includes default relations 1`] = `
|
||||
Object {
|
||||
"variants": Array [
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode",
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-variant",
|
||||
"inventory_quantity": 10,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": "test-variant-option",
|
||||
"metadata": null,
|
||||
"option_id": "test-option",
|
||||
"updated_at": Any<String>,
|
||||
"value": "Default variant",
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"product": Any<Object>,
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku",
|
||||
"title": "Test variant",
|
||||
"upc": "test-upc",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -102,7 +102,7 @@ Object {
|
||||
],
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"status": "published",
|
||||
"subtitle": null,
|
||||
"tags": Array [
|
||||
Object {
|
||||
@@ -130,6 +130,7 @@ Object {
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode",
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean",
|
||||
@@ -155,6 +156,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
@@ -164,11 +166,37 @@ Object {
|
||||
"id": "test-price",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
Object {
|
||||
"amount": 80,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price-discount",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "Winter sale for VIP customers.",
|
||||
"ends_at": null,
|
||||
"id": "pl",
|
||||
"name": "VIP winter sale",
|
||||
"starts_at": null,
|
||||
"status": "active",
|
||||
"type": "sale",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"price_list_id": "pl",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku",
|
||||
@@ -181,6 +209,7 @@ Object {
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": null,
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean2",
|
||||
@@ -206,6 +235,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
@@ -215,11 +245,37 @@ Object {
|
||||
"id": "test-price2",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant_2",
|
||||
},
|
||||
Object {
|
||||
"amount": 80,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price2-discount",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "Winter sale for VIP customers.",
|
||||
"ends_at": null,
|
||||
"id": "pl",
|
||||
"name": "VIP winter sale",
|
||||
"starts_at": null,
|
||||
"status": "active",
|
||||
"type": "sale",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"price_list_id": "pl",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant_2",
|
||||
},
|
||||
],
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku2",
|
||||
@@ -232,6 +288,7 @@ Object {
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": "test-barcode 1",
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": "test-ean1",
|
||||
@@ -257,6 +314,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
@@ -266,11 +324,37 @@ Object {
|
||||
"id": "test-price1",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant_1",
|
||||
},
|
||||
Object {
|
||||
"amount": 80,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": "test-price1-discount",
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "Winter sale for VIP customers.",
|
||||
"ends_at": null,
|
||||
"id": "pl",
|
||||
"name": "VIP winter sale",
|
||||
"starts_at": null,
|
||||
"status": "active",
|
||||
"type": "sale",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"price_list_id": "pl",
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": "test-variant_1",
|
||||
},
|
||||
],
|
||||
"product_id": "test-product",
|
||||
"sku": "test-sku1",
|
||||
@@ -300,6 +384,7 @@ Object {
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": null,
|
||||
"calculated_price": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": null,
|
||||
@@ -313,6 +398,7 @@ Object {
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"original_price": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
@@ -322,6 +408,7 @@ Object {
|
||||
"id": Any<String>,
|
||||
"max_quantity": null,
|
||||
"min_quantity": null,
|
||||
"price_list": null,
|
||||
"price_list_id": null,
|
||||
"region_id": null,
|
||||
"updated_at": Any<String>,
|
||||
|
||||
@@ -5,6 +5,8 @@ const {
|
||||
GiftCard,
|
||||
Cart,
|
||||
CustomShippingOption,
|
||||
PriceList,
|
||||
MoneyAmount,
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
@@ -90,20 +92,51 @@ describe("/store/carts", () => {
|
||||
|
||||
it("creates a cart with items", async () => {
|
||||
await productSeeder(dbConnection)
|
||||
|
||||
const yesterday = ((today) =>
|
||||
new Date(today.setDate(today.getDate() - 1)))(new Date())
|
||||
const tomorrow = ((today) =>
|
||||
new Date(today.setDate(today.getDate() + 1)))(new Date())
|
||||
|
||||
const priceList1 = await dbConnection.manager.create(PriceList, {
|
||||
id: "pl_current",
|
||||
name: "Past winter sale",
|
||||
description: "Winter sale for key accounts.",
|
||||
type: "sale",
|
||||
status: "active",
|
||||
starts_at: yesterday,
|
||||
ends_at: tomorrow,
|
||||
})
|
||||
|
||||
await dbConnection.manager.save(priceList1)
|
||||
|
||||
const ma_sale_1 = dbConnection.manager.create(MoneyAmount, {
|
||||
variant_id: "test-variant-sale",
|
||||
currency_code: "usd",
|
||||
amount: 800,
|
||||
price_list_id: "pl_current",
|
||||
})
|
||||
|
||||
await dbConnection.manager.save(ma_sale_1)
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post("/store/carts", {
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant_1",
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant_id: "test-variant_2",
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
})
|
||||
const response = await api
|
||||
.post("/store/carts", {
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant_1",
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant_id: "test-variant-sale",
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
response.data.cart.items.sort((a, b) => a.quantity - b.quantity)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart.items).toEqual([
|
||||
@@ -112,8 +145,9 @@ describe("/store/carts", () => {
|
||||
quantity: 1,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant_2",
|
||||
variant_id: "test-variant-sale",
|
||||
quantity: 2,
|
||||
unit_price: 800,
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -155,6 +189,122 @@ describe("/store/carts", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/line-items", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await doAfterEach()
|
||||
})
|
||||
|
||||
it("adds line item to cart", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Add standard line item to cart
|
||||
const response = await api
|
||||
.post(
|
||||
"/store/carts/test-cart/line-items",
|
||||
{
|
||||
variant_id: "test-variant-quantity",
|
||||
quantity: 1,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data.cart.items).toEqual([
|
||||
expect.objectContaining({
|
||||
cart_id: "test-cart",
|
||||
unit_price: 1000,
|
||||
variant_id: "test-variant-quantity",
|
||||
quantity: 1,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("adds line item to cart time limited sale", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Add standard line item to cart
|
||||
const response = await api
|
||||
.post(
|
||||
"/store/carts/test-cart/line-items",
|
||||
{
|
||||
variant_id: "test-variant-sale",
|
||||
quantity: 1,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data.cart.items).toEqual([
|
||||
expect.objectContaining({
|
||||
cart_id: "test-cart",
|
||||
unit_price: 800,
|
||||
variant_id: "test-variant-sale",
|
||||
quantity: 1,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("adds line item with quantity to cart with quantity discount", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Add standard line item to cart
|
||||
const response = await api
|
||||
.post(
|
||||
"/store/carts/test-cart/line-items",
|
||||
{
|
||||
variant_id: "test-variant-quantity",
|
||||
quantity: 90,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data.cart.items).toEqual([
|
||||
expect.objectContaining({
|
||||
cart_id: "test-cart",
|
||||
unit_price: 800,
|
||||
variant_id: "test-variant-quantity",
|
||||
quantity: 90,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("adds line item with quantity to cart with quantity discount no ceiling", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Add standard line item to cart
|
||||
const response = await api
|
||||
.post(
|
||||
"/store/carts/test-cart/line-items",
|
||||
{
|
||||
variant_id: "test-variant-quantity",
|
||||
quantity: 900,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data.cart.items).toEqual([
|
||||
expect.objectContaining({
|
||||
cart_id: "test-cart",
|
||||
unit_price: 700,
|
||||
variant_id: "test-variant-quantity",
|
||||
quantity: 900,
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
@@ -270,6 +420,46 @@ describe("/store/carts", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("updates prices when cart customer id is updated", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const beforeUpdate = await api
|
||||
.get(`/store/carts/test-cart-3`)
|
||||
.catch((error) => console.log(error))
|
||||
|
||||
expect(beforeUpdate.data.cart.items[0].unit_price).toEqual(8000)
|
||||
|
||||
const response = await api
|
||||
.post("/store/carts/test-cart-3", {
|
||||
customer_id: "test-customer-2",
|
||||
})
|
||||
.catch((error) => console.log(error))
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart.items[0].unit_price).toEqual(500)
|
||||
})
|
||||
|
||||
it("updates prices when cart region id is updated", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const beforeUpdate = await api
|
||||
.get(`/store/carts/test-cart-3`)
|
||||
.catch((error) => console.log(error))
|
||||
|
||||
expect(beforeUpdate.data.cart.items[0].unit_price).toEqual(8000)
|
||||
expect(beforeUpdate.data.cart.region_id).toEqual("test-region")
|
||||
|
||||
const response = await api
|
||||
.post("/store/carts/test-cart-3", {
|
||||
region_id: "test-region-multiple",
|
||||
})
|
||||
.catch((error) => console.log(error))
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart.region_id).toEqual("test-region-multiple")
|
||||
expect(response.data.cart.items[0].unit_price).toEqual(700)
|
||||
})
|
||||
|
||||
it("updates address using string id", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -377,7 +567,7 @@ describe("/store/carts", () => {
|
||||
await api.post(`/store/carts/test-cart-2/complete-cart`)
|
||||
} catch (error) {
|
||||
expect(error.response.data).toMatchSnapshot({
|
||||
code: "not_allowed",
|
||||
type: "not_allowed",
|
||||
message: "Cart has already been completed",
|
||||
code: "cart_incompatible_state",
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { ProductVariant } = require("@medusajs/medusa")
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
@@ -5,6 +6,7 @@ const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
const { simpleProductFactory } = require("../../factories")
|
||||
|
||||
const productSeeder = require("../../helpers/product-seeder")
|
||||
const storeProductSeeder = require("../../helpers/store-product-seeder")
|
||||
jest.setTimeout(30000)
|
||||
describe("/store/variants", () => {
|
||||
let medusaProcess
|
||||
@@ -22,46 +24,100 @@ describe("/store/variants", () => {
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
describe("GET /store/variants", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("includes default relations", async () => {
|
||||
const api = useApi()
|
||||
it("includes default relations", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/variants?ids=test-variant")
|
||||
const response = await api.get("/store/variants?ids=test-variant")
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variants: [
|
||||
{
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variants: [
|
||||
{
|
||||
allow_backorder: false,
|
||||
barcode: "test-barcode",
|
||||
created_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
ean: "test-ean",
|
||||
height: null,
|
||||
hs_code: null,
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
length: null,
|
||||
manage_inventory: true,
|
||||
material: null,
|
||||
metadata: null,
|
||||
mid_code: null,
|
||||
origin_country: null,
|
||||
product_id: "test-product",
|
||||
sku: "test-sku",
|
||||
title: "Test variant",
|
||||
upc: "test-upc",
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
options: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price",
|
||||
region_id: null,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("/test-variant", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/variants/test-variant")
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variant: {
|
||||
allow_backorder: false,
|
||||
barcode: "test-barcode",
|
||||
created_at: expect.any(String),
|
||||
@@ -106,103 +162,230 @@ describe("/store/variants", () => {
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
options: [
|
||||
{ created_at: expect.any(String), updated_at: expect.any(String) },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("lists by title", async () => {
|
||||
const api = useApi()
|
||||
describe("GET /store/variants advanced pricing", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await storeProductSeeder(dbConnection)
|
||||
|
||||
const response = await api.get(
|
||||
"/store/variants?title[]=test1&title[]=test2&inventory_quantity[gt]=10"
|
||||
)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variants: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
title: "test2",
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("/test-variant with currency code", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
"/store/variants/test-variant?currency_code=usd"
|
||||
)
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variant: {
|
||||
allow_backorder: false,
|
||||
barcode: "test-barcode",
|
||||
created_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
ean: "test-ean",
|
||||
height: null,
|
||||
hs_code: null,
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
length: null,
|
||||
manage_inventory: true,
|
||||
material: null,
|
||||
metadata: null,
|
||||
mid_code: null,
|
||||
origin_country: null,
|
||||
product_id: "test-product",
|
||||
sku: "test-sku",
|
||||
title: "Test variant",
|
||||
upc: "test-upc",
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
options: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
id: expect.any(String),
|
||||
option_id: expect.any(String),
|
||||
variant_id: expect.any(String),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
variant_id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price",
|
||||
region_id: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 80,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
price_list_id: "pl",
|
||||
id: "test-price-discount",
|
||||
region_id: null,
|
||||
variant_id: "test-variant",
|
||||
price_list: {
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
id: "pl",
|
||||
},
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("sets additional prices correctly when querying a variant", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/variants/test-variant?cart_id=test-cart")
|
||||
.catch((error) => console.log(error))
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variant: {
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
title: "Test variant",
|
||||
sku: "test-sku",
|
||||
ean: "test-ean",
|
||||
upc: "test-upc",
|
||||
barcode: "test-barcode",
|
||||
product_id: "test-product",
|
||||
allow_backorder: false,
|
||||
created_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
height: null,
|
||||
hs_code: null,
|
||||
length: null,
|
||||
manage_inventory: true,
|
||||
material: null,
|
||||
metadata: null,
|
||||
mid_code: null,
|
||||
origin_country: null,
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
options: [
|
||||
{
|
||||
id: "test-variant-option",
|
||||
value: "Default variant",
|
||||
option_id: "test-option",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
original_price: 100,
|
||||
calculated_price: 80,
|
||||
prices: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price",
|
||||
region_id: null,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 80,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
price_list_id: "pl",
|
||||
id: "test-price-discount",
|
||||
region_id: null,
|
||||
variant_id: "test-variant",
|
||||
price_list: {
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
id: "pl",
|
||||
},
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
product_id: expect.any(String),
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("/test-variant", async () => {
|
||||
const api = useApi()
|
||||
it("lists by title", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/variants/test-variant")
|
||||
const response = await api
|
||||
.get(
|
||||
"/store/variants?title[]=test1&title[]=test2&inventory_quantity[gt]=10"
|
||||
)
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variant: {
|
||||
allow_backorder: false,
|
||||
barcode: "test-barcode",
|
||||
created_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
ean: "test-ean",
|
||||
height: null,
|
||||
hs_code: null,
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
length: null,
|
||||
manage_inventory: true,
|
||||
material: null,
|
||||
metadata: null,
|
||||
mid_code: null,
|
||||
origin_country: null,
|
||||
product_id: "test-product",
|
||||
sku: "test-sku",
|
||||
title: "Test variant",
|
||||
upc: "test-upc",
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
options: [
|
||||
expect(response.data).toMatchSnapshot({
|
||||
variants: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
title: "test2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
options: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
id: expect.any(String),
|
||||
option_id: expect.any(String),
|
||||
variant_id: expect.any(String),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
variant_id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
product_id: expect.any(String),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price",
|
||||
region_id: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const { Product } = require("@medusajs/medusa")
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
@@ -201,17 +200,26 @@ describe("/store/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products.length).toEqual(5)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "giftcard",
|
||||
id: "test-product1",
|
||||
collection_id: "test-collection",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product",
|
||||
collection_id: "test-collection",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
collection_id: "test-collection2",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
collection_id: "test-collection2",
|
||||
id: "giftcard",
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -223,12 +231,111 @@ describe("/store/products", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("list params", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("Includes Additional prices when queried with a cart id", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/products?cart_id=test-cart")
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product1",
|
||||
collection_id: "test-collection",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product",
|
||||
collection_id: "test-collection",
|
||||
variants: [
|
||||
expect.objectContaining({
|
||||
original_price: 100,
|
||||
calculated_price: 80,
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "test-price",
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-price-discount",
|
||||
currency_code: "usd",
|
||||
amount: 80,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
original_price: 100,
|
||||
calculated_price: 80,
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "test-price2",
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-price2-discount",
|
||||
currency_code: "usd",
|
||||
amount: 80,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
original_price: 100,
|
||||
calculated_price: 80,
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "test-price1",
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-price1-discount",
|
||||
currency_code: "usd",
|
||||
amount: 80,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
collection_id: "test-collection2",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "giftcard",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("list params", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
const p1 = await simpleProductFactory(
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "testprod",
|
||||
@@ -238,7 +345,7 @@ describe("/store/products", () => {
|
||||
11
|
||||
)
|
||||
|
||||
const p2 = await simpleProductFactory(
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "testprod3",
|
||||
@@ -332,6 +439,8 @@ describe("/store/products", () => {
|
||||
height: null,
|
||||
hs_code: null,
|
||||
origin_country: null,
|
||||
calculated_price: null,
|
||||
original_price: null,
|
||||
barcode: "test-barcode",
|
||||
product_id: "test-product",
|
||||
created_at: expect.any(String),
|
||||
@@ -349,13 +458,30 @@ describe("/store/products", () => {
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price",
|
||||
region_id: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
id: "test-price",
|
||||
region_id: null,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
{
|
||||
id: "test-price-discount",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 80,
|
||||
currency_code: "usd",
|
||||
price_list_id: "pl",
|
||||
deleted_at: null,
|
||||
region_id: null,
|
||||
variant_id: "test-variant",
|
||||
price_list: {
|
||||
id: "pl",
|
||||
type: "sale",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -375,6 +501,8 @@ describe("/store/products", () => {
|
||||
hs_code: null,
|
||||
origin_country: null,
|
||||
barcode: null,
|
||||
calculated_price: null,
|
||||
original_price: null,
|
||||
product_id: "test-product",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
@@ -386,18 +514,33 @@ describe("/store/products", () => {
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
id: "test-price2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price2",
|
||||
region_id: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
deleted_at: null,
|
||||
region_id: null,
|
||||
variant_id: "test-variant_2",
|
||||
},
|
||||
{
|
||||
id: "test-price2-discount",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 80,
|
||||
currency_code: "usd",
|
||||
price_list_id: "pl",
|
||||
deleted_at: null,
|
||||
region_id: null,
|
||||
variant_id: "test-variant_2",
|
||||
price_list: {
|
||||
id: "pl",
|
||||
type: "sale",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -416,6 +559,8 @@ describe("/store/products", () => {
|
||||
height: null,
|
||||
hs_code: null,
|
||||
origin_country: null,
|
||||
calculated_price: null,
|
||||
original_price: null,
|
||||
barcode: "test-barcode 1",
|
||||
product_id: "test-product",
|
||||
created_at: expect.any(String),
|
||||
@@ -428,18 +573,35 @@ describe("/store/products", () => {
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
id: "test-price1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
deleted_at: null,
|
||||
id: "test-price1",
|
||||
region_id: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: null,
|
||||
deleted_at: null,
|
||||
region_id: null,
|
||||
variant_id: "test-variant_1",
|
||||
},
|
||||
{
|
||||
id: "test-price1-discount",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
amount: 80,
|
||||
currency_code: "usd",
|
||||
price_list_id: "pl",
|
||||
deleted_at: null,
|
||||
region_id: null,
|
||||
variant_id: "test-variant_1",
|
||||
price_list: {
|
||||
id: "pl",
|
||||
type: "sale",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user