feat(core-flows,medusa,types,utils): rename psma to prices (#6796)
What: Renames pricesetmoneyamount to prices Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
fbc369705d
commit
9073d7aba3
+64
-139
@@ -57,85 +57,15 @@ moduleIntegrationTestRunner({
|
||||
describe("PricingModule Service - Calculate Price", () => {
|
||||
describe("calculatePrices", () => {
|
||||
beforeEach(async () => {
|
||||
const moneyAmountsData = [
|
||||
{
|
||||
id: "psma-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 1000,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
{
|
||||
id: "psma-company_id-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 500,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
{
|
||||
id: "psma-company_id-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 400,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 300,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id+company_id-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 999,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id-PLN-5-qty",
|
||||
currency_code: "PLN",
|
||||
amount: 250,
|
||||
min_quantity: 4,
|
||||
max_quantity: 10,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id_company_id-PL-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 200,
|
||||
min_quantity: 1,
|
||||
max_quantity: 3,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id_company_id-PL-EUR-4-qty",
|
||||
currency_code: "EUR",
|
||||
amount: 50,
|
||||
min_quantity: 4,
|
||||
max_quantity: 10,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id_company_id-PL-EUR-customer-group",
|
||||
currency_code: "EUR",
|
||||
amount: 100,
|
||||
min_quantity: 1,
|
||||
max_quantity: 3,
|
||||
},
|
||||
]
|
||||
|
||||
const priceSetsData = [
|
||||
{
|
||||
id: "price-set-EUR",
|
||||
},
|
||||
{
|
||||
id: "price-set-PLN",
|
||||
},
|
||||
{ id: "price-set-EUR" },
|
||||
{ id: "price-set-PLN" },
|
||||
] as unknown as CreatePriceSetDTO[]
|
||||
|
||||
const priceSetMoneyAmountsData = [
|
||||
const pricesData = [
|
||||
{
|
||||
id: "psma-PLN",
|
||||
title: "psma PLN",
|
||||
id: "price-PLN",
|
||||
title: "price PLN",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 1000,
|
||||
@@ -144,8 +74,8 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 0,
|
||||
},
|
||||
{
|
||||
id: "psma-company_id-EUR",
|
||||
title: "psma EUR - company_id",
|
||||
id: "price-company_id-EUR",
|
||||
title: "price EUR - company_id",
|
||||
price_set_id: "price-set-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 500,
|
||||
@@ -154,8 +84,8 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "psma-company_id-PLN",
|
||||
title: "psma PLN - company_id",
|
||||
id: "price-company_id-PLN",
|
||||
title: "price PLN - company_id",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 400,
|
||||
@@ -164,8 +94,8 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id-PLN",
|
||||
title: "psma PLN - region_id",
|
||||
id: "price-region_id-PLN",
|
||||
title: "price PLN - region_id",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 300,
|
||||
@@ -174,8 +104,8 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id+company_id-PLN",
|
||||
title: "psma region_id + company_id",
|
||||
id: "price-region_id+company_id-PLN",
|
||||
title: "price region_id + company_id",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 999,
|
||||
@@ -184,8 +114,8 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 2,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id-PLN-5-qty",
|
||||
title: "psma PLN - region_id 5 qty",
|
||||
id: "price-region_id-PLN-5-qty",
|
||||
title: "price PLN - region_id 5 qty",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "PLN",
|
||||
amount: 250,
|
||||
@@ -194,8 +124,8 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id_company_id-PL-EUR",
|
||||
title: "psma PLN - region_id PL with EUR currency",
|
||||
id: "price-region_id_company_id-PL-EUR",
|
||||
title: "price PLN - region_id PL with EUR currency",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "EUR",
|
||||
amount: 200,
|
||||
@@ -204,8 +134,9 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 2,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id_company_id-PL-EUR-4-qty",
|
||||
title: "psma PLN - region_id PL with EUR currency for quantity 4",
|
||||
id: "price-region_id_company_id-PL-EUR-4-qty",
|
||||
title:
|
||||
"price PLN - region_id PL with EUR currency for quantity 4",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "EUR",
|
||||
amount: 50,
|
||||
@@ -214,9 +145,9 @@ moduleIntegrationTestRunner({
|
||||
rules_count: 2,
|
||||
},
|
||||
{
|
||||
id: "psma-region_id_company_id-PL-EUR-customer-group",
|
||||
id: "price-region_id_company_id-PL-EUR-customer-group",
|
||||
title:
|
||||
"psma PLN - region_id PL with EUR currency for customer group",
|
||||
"price PLN - region_id PL with EUR currency for customer group",
|
||||
price_set_id: "price-set-PLN",
|
||||
currency_code: "EUR",
|
||||
amount: 100,
|
||||
@@ -254,7 +185,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-company_id",
|
||||
value: "EUR",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-company_id-EUR",
|
||||
price_id: "price-company_id-EUR",
|
||||
},
|
||||
{
|
||||
id: "price-rule-company_id-PLN",
|
||||
@@ -262,7 +193,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-company_id",
|
||||
value: "medusa-company-id",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-company_id-PLN",
|
||||
price_id: "price-company_id-PLN",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-PLN",
|
||||
@@ -270,7 +201,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-region_id",
|
||||
value: "PL",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-region_id-PLN",
|
||||
price_id: "price-region_id-PLN",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id+company_id-PL",
|
||||
@@ -278,7 +209,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-region_id",
|
||||
value: "PL",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-region_id+company_id-PLN",
|
||||
price_id: "price-region_id+company_id-PLN",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id+company_id-medusa-company-id",
|
||||
@@ -286,7 +217,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-company_id",
|
||||
value: "medusa-company-id",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-region_id+company_id-PLN",
|
||||
price_id: "price-region_id+company_id-PLN",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-PLN-5-qty",
|
||||
@@ -294,7 +225,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-region_id",
|
||||
value: "PL",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-region_id-PLN-5-qty",
|
||||
price_id: "price-region_id-PLN-5-qty",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-company_id-PL",
|
||||
@@ -302,7 +233,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-region_id",
|
||||
value: "PL",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-region_id_company_id-PL-EUR",
|
||||
price_id: "price-region_id_company_id-PL-EUR",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-company_id-PLN",
|
||||
@@ -310,7 +241,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-company_id",
|
||||
value: "medusa-company-id",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: "psma-region_id_company_id-PL-EUR",
|
||||
price_id: "price-region_id_company_id-PL-EUR",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-company_id-PL-4-qty",
|
||||
@@ -318,8 +249,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-region_id",
|
||||
value: "PL",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id:
|
||||
"psma-region_id_company_id-PL-EUR-4-qty",
|
||||
price_id: "price-region_id_company_id-PL-EUR-4-qty",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-company_id-PLN-4-qty",
|
||||
@@ -327,8 +257,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-company_id",
|
||||
value: "medusa-company-id",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id:
|
||||
"psma-region_id_company_id-PL-EUR-4-qty",
|
||||
price_id: "price-region_id_company_id-PL-EUR-4-qty",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-currency_customer_group_code-PL",
|
||||
@@ -336,8 +265,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-region_id",
|
||||
value: "PL",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id:
|
||||
"psma-region_id_company_id-PL-EUR-customer-group",
|
||||
price_id: "price-region_id_company_id-PL-EUR-customer-group",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-currency_customer_group_code-PLN",
|
||||
@@ -345,8 +273,7 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-company_id",
|
||||
value: "medusa-company-id",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id:
|
||||
"psma-region_id_company_id-PL-EUR-customer-group",
|
||||
price_id: "price-region_id_company_id-PL-EUR-customer-group",
|
||||
},
|
||||
{
|
||||
id: "price-rule-region_id-currency_customer_group_code-test_customer_group",
|
||||
@@ -354,15 +281,13 @@ moduleIntegrationTestRunner({
|
||||
rule_type_id: "rule-type-customer_group_id",
|
||||
value: "test-customer-group",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id:
|
||||
"psma-region_id_company_id-PL-EUR-customer-group",
|
||||
price_id: "price-region_id_company_id-PL-EUR-customer-group",
|
||||
},
|
||||
] as unknown as CreatePriceRuleDTO[]
|
||||
|
||||
await seedPriceData(MikroOrmWrapper.forkManager(), {
|
||||
moneyAmountsData,
|
||||
priceSetsData,
|
||||
priceSetMoneyAmountsData,
|
||||
pricesData,
|
||||
priceRuleData,
|
||||
ruleTypesData,
|
||||
})
|
||||
@@ -427,14 +352,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 1000,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -483,14 +408,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 300,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -539,14 +464,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 1000,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -651,14 +576,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 300,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -707,14 +632,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 1000,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -741,14 +666,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 250,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN-5-qty",
|
||||
id: "price-region_id-PLN-5-qty",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 4,
|
||||
max_quantity: 10,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN-5-qty",
|
||||
id: "price-region_id-PLN-5-qty",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 4,
|
||||
@@ -802,14 +727,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 300,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -864,14 +789,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 100,
|
||||
currency_code: "EUR",
|
||||
calculated_price: {
|
||||
id: "psma-region_id_company_id-PL-EUR-customer-group",
|
||||
id: "price-region_id_company_id-PL-EUR-customer-group",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 3,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id_company_id-PL-EUR-customer-group",
|
||||
id: "price-region_id_company_id-PL-EUR-customer-group",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -926,14 +851,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 300,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -988,14 +913,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 1000,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-PLN",
|
||||
id: "price-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -1104,14 +1029,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 300,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -1487,14 +1412,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 300,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 4,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-region_id-PLN",
|
||||
id: "price-region_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -1700,14 +1625,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 400,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-company_id-PLN",
|
||||
id: "price-company_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-company_id-PLN",
|
||||
id: "price-company_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
@@ -1775,14 +1700,14 @@ moduleIntegrationTestRunner({
|
||||
original_amount: 400,
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: "psma-company_id-PLN",
|
||||
id: "price-company_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
},
|
||||
original_price: {
|
||||
id: "psma-company_id-PLN",
|
||||
id: "price-company_id-PLN",
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
|
||||
+58
-60
@@ -273,17 +273,17 @@ moduleIntegrationTestRunner({
|
||||
{ id: [createdId] },
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts",
|
||||
"price_set_money_amounts.price_set",
|
||||
"prices",
|
||||
"prices.price_set",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"starts_at",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.price_list_id",
|
||||
"prices.amount",
|
||||
"prices.currency_code",
|
||||
"prices.price_list_id",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
@@ -294,7 +294,7 @@ moduleIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
starts_at: updateDate,
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
price_list: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
@@ -428,16 +428,16 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts",
|
||||
"price_set_money_amounts.price_set",
|
||||
"prices",
|
||||
"prices.price_set",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.price_list_id",
|
||||
"prices.amount",
|
||||
"prices.currency_code",
|
||||
"prices.price_list_id",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
@@ -447,7 +447,7 @@ moduleIntegrationTestRunner({
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
price_list: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
@@ -534,19 +534,19 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts",
|
||||
"price_set_money_amounts.price_set",
|
||||
"price_set_money_amounts.price_rules",
|
||||
"prices",
|
||||
"prices.price_set",
|
||||
"prices.price_rules",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.price_rules.value",
|
||||
"price_set_money_amounts.rules_count",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.price_list_id",
|
||||
"prices.price_rules.value",
|
||||
"prices.rules_count",
|
||||
"prices.amount",
|
||||
"prices.currency_code",
|
||||
"prices.price_list_id",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
@@ -556,7 +556,7 @@ moduleIntegrationTestRunner({
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rules_count: 1,
|
||||
price_rules: expect.arrayContaining([
|
||||
@@ -673,19 +673,19 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts",
|
||||
"price_set_money_amounts.price_set",
|
||||
"price_set_money_amounts.price_rules",
|
||||
"prices",
|
||||
"prices.price_set",
|
||||
"prices.price_rules",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.price_rules.value",
|
||||
"price_set_money_amounts.rules_count",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.price_list_id",
|
||||
"prices.price_rules.value",
|
||||
"prices.rules_count",
|
||||
"prices.amount",
|
||||
"prices.currency_code",
|
||||
"prices.price_list_id",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
@@ -695,7 +695,7 @@ moduleIntegrationTestRunner({
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rules_count: 0,
|
||||
price_list: expect.objectContaining({
|
||||
@@ -782,21 +782,21 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts",
|
||||
"price_set_money_amounts.price_set",
|
||||
"price_set_money_amounts.price_rules",
|
||||
"price_set_money_amounts.price_rules.rule_type",
|
||||
"prices",
|
||||
"prices.price_set",
|
||||
"prices.price_rules",
|
||||
"prices.price_rules.rule_type",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.price_rules.value",
|
||||
"price_set_money_amounts.price_rules.rule_type.rule_attribute",
|
||||
"price_set_money_amounts.rules_count",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.price_list_id",
|
||||
"prices.price_rules.value",
|
||||
"prices.price_rules.rule_type.rule_attribute",
|
||||
"prices.rules_count",
|
||||
"prices.amount",
|
||||
"prices.currency_code",
|
||||
"prices.price_list_id",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
@@ -806,7 +806,7 @@ moduleIntegrationTestRunner({
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rules_count: 1,
|
||||
price_list: expect.objectContaining({
|
||||
@@ -878,21 +878,21 @@ moduleIntegrationTestRunner({
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: [
|
||||
"price_set_money_amounts",
|
||||
"price_set_money_amounts.price_set",
|
||||
"price_set_money_amounts.price_rules",
|
||||
"price_set_money_amounts.price_rules.rule_type",
|
||||
"prices",
|
||||
"prices.price_set",
|
||||
"prices.price_rules",
|
||||
"prices.price_rules.rule_type",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
"price_list_rules.rule_type",
|
||||
],
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.price_rules.value",
|
||||
"price_set_money_amounts.price_rules.rule_type.rule_attribute",
|
||||
"price_set_money_amounts.rules_count",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.currency_code",
|
||||
"price_set_money_amounts.price_list_id",
|
||||
"prices.price_rules.value",
|
||||
"prices.price_rules.rule_type.rule_attribute",
|
||||
"prices.rules_count",
|
||||
"prices.amount",
|
||||
"prices.currency_code",
|
||||
"prices.price_list_id",
|
||||
"price_list_rules.price_list_rule_values.value",
|
||||
"price_list_rules.rule_type.rule_attribute",
|
||||
],
|
||||
@@ -902,7 +902,7 @@ moduleIntegrationTestRunner({
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rules_count: 2,
|
||||
price_rules: expect.arrayContaining([
|
||||
@@ -1000,26 +1000,24 @@ moduleIntegrationTestRunner({
|
||||
let [priceList] = await service.listPriceLists(
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: ["price_set_money_amounts"],
|
||||
select: ["price_set_money_amounts.id"],
|
||||
relations: ["prices"],
|
||||
select: ["prices.id"],
|
||||
}
|
||||
)
|
||||
|
||||
await service.removePrices(
|
||||
priceList.price_set_money_amounts!.map((psma) => psma.id)
|
||||
)
|
||||
await service.removePrices(priceList.prices!.map((price) => price.id))
|
||||
;[priceList] = await service.listPriceLists(
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: ["price_set_money_amounts"],
|
||||
select: ["id", "price_set_money_amounts.id"],
|
||||
relations: ["prices"],
|
||||
select: ["id", "prices.id"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
price_set_money_amounts: [],
|
||||
prices: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
+24
-28
@@ -1,11 +1,11 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { CreatePriceRuleDTO, IPricingModuleService } from "@medusajs/types"
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { PriceSetMoneyAmount } from "../../../../src"
|
||||
import { Price } from "../../../../src"
|
||||
import { createPrices } from "../../../__fixtures__/price"
|
||||
import { createPriceRules } from "../../../__fixtures__/price-rule"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
@@ -23,7 +23,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await createPriceSets(testManager)
|
||||
await createRuleTypes(testManager)
|
||||
await createPriceSetMoneyAmounts(testManager)
|
||||
await createPrices(testManager)
|
||||
await createPriceRules(testManager)
|
||||
})
|
||||
|
||||
@@ -73,6 +73,7 @@ moduleIntegrationTestRunner({
|
||||
price_set: {
|
||||
id: "price-set-1",
|
||||
},
|
||||
price_set_id: "price-set-1",
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -272,38 +273,33 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should create a PriceRule successfully", async () => {
|
||||
const psma: PriceSetMoneyAmount = testManager.create(
|
||||
PriceSetMoneyAmount,
|
||||
{
|
||||
currency_code: "EUR",
|
||||
amount: 100,
|
||||
price_set_id: "price-set-1",
|
||||
title: "test",
|
||||
rules_count: 0,
|
||||
}
|
||||
)
|
||||
const price: Price = testManager.create(Price, {
|
||||
currency_code: "EUR",
|
||||
amount: 100,
|
||||
price_set_id: "price-set-1",
|
||||
title: "test",
|
||||
rules_count: 0,
|
||||
})
|
||||
|
||||
await testManager.persist(psma).flush()
|
||||
await testManager.persist(price).flush()
|
||||
|
||||
await service.createPriceRules([
|
||||
{
|
||||
id: "price-rule-new",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
value: "region_1",
|
||||
price_list_id: "test",
|
||||
price_set_money_amount_id: psma.id,
|
||||
} as unknown as CreatePriceRuleDTO,
|
||||
])
|
||||
await service.createPriceRules({
|
||||
id: "price-rule-new",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
value: "region_1",
|
||||
price_list_id: "test",
|
||||
price_id: price.id,
|
||||
})
|
||||
|
||||
const [pricerule] = await service.listPriceRules({
|
||||
const [priceRule] = await service.listPriceRules({
|
||||
id: ["price-rule-new"],
|
||||
})
|
||||
|
||||
expect(pricerule).toEqual(
|
||||
expect(priceRule).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "price-rule-new",
|
||||
} as unknown as CreatePriceRuleDTO)
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
+36
-85
@@ -1,11 +1,10 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreatePriceSetDTO,
|
||||
CreatePriceSetRuleTypeDTO,
|
||||
IPricingModuleService,
|
||||
} from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { PriceSetRuleType } from "../../../../src"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
@@ -39,14 +38,14 @@ moduleIntegrationTestRunner({
|
||||
await seedPriceData(testManager)
|
||||
await createPriceSetPriceRules(testManager, [
|
||||
{
|
||||
price_set: "price-set-1",
|
||||
rule_type: "rule-type-1",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
},
|
||||
{
|
||||
price_set: "price-set-2",
|
||||
rule_type: "rule-type-2",
|
||||
price_set_id: "price-set-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
},
|
||||
] as unknown as CreatePriceSetRuleTypeDTO[])
|
||||
])
|
||||
})
|
||||
|
||||
describe("list", () => {
|
||||
@@ -84,12 +83,8 @@ moduleIntegrationTestRunner({
|
||||
id: ["price-set-1"],
|
||||
},
|
||||
{
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.id",
|
||||
"price_set_money_amounts.amount",
|
||||
],
|
||||
relations: ["price_set_money_amounts"],
|
||||
select: ["id", "prices.id", "prices.amount"],
|
||||
relations: ["prices"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -98,7 +93,7 @@ moduleIntegrationTestRunner({
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-set-1",
|
||||
price_set_money_amounts: [
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "price-set-money-amount-USD",
|
||||
amount: 500,
|
||||
@@ -146,12 +141,8 @@ moduleIntegrationTestRunner({
|
||||
id: ["price-set-1"],
|
||||
},
|
||||
{
|
||||
select: [
|
||||
"id",
|
||||
"price_set_money_amounts.amount",
|
||||
"price_set_money_amounts.id",
|
||||
],
|
||||
relations: ["price_set_money_amounts"],
|
||||
select: ["id", "prices.amount", "prices.id"],
|
||||
relations: ["prices"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -161,7 +152,7 @@ moduleIntegrationTestRunner({
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-set-1",
|
||||
price_set_money_amounts: [
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "price-set-money-amount-USD",
|
||||
amount: 500,
|
||||
@@ -379,7 +370,7 @@ moduleIntegrationTestRunner({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
price_set_money_amounts: [
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
@@ -417,7 +408,7 @@ moduleIntegrationTestRunner({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
@@ -431,7 +422,7 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a price set with rule types and money amountss", async () => {
|
||||
it("should create a price set with rule types and money amounts", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "region_id" }],
|
||||
@@ -454,7 +445,7 @@ moduleIntegrationTestRunner({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
price_set_money_amounts: [
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
@@ -493,12 +484,8 @@ moduleIntegrationTestRunner({
|
||||
const createdPriceSet = await service.create([
|
||||
{
|
||||
rules: [
|
||||
{
|
||||
rule_attribute: "region_id",
|
||||
},
|
||||
{
|
||||
rule_attribute: "currency_code",
|
||||
},
|
||||
{ rule_attribute: "region_id" },
|
||||
{ rule_attribute: "currency_code" },
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
@@ -521,23 +508,12 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
await service.removeRules([
|
||||
{
|
||||
id: createdPriceSet[0].id,
|
||||
rules: ["region_id"],
|
||||
},
|
||||
{ id: createdPriceSet[0].id, rules: ["region_id"] },
|
||||
])
|
||||
|
||||
let priceSet = await service.list(
|
||||
{
|
||||
id: [createdPriceSet[0].id],
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"rule_types",
|
||||
"price_set_money_amounts",
|
||||
"price_rules",
|
||||
],
|
||||
}
|
||||
{ id: [createdPriceSet[0].id] },
|
||||
{ relations: ["rule_types", "prices", "price_rules"] }
|
||||
)
|
||||
|
||||
expect(
|
||||
@@ -552,7 +528,7 @@ moduleIntegrationTestRunner({
|
||||
}),
|
||||
},
|
||||
],
|
||||
price_set_money_amounts: [
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
amount: 500,
|
||||
currency_code: "EUR",
|
||||
@@ -568,29 +544,18 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
|
||||
await service.removeRules([
|
||||
{
|
||||
id: createdPriceSet[0].id,
|
||||
rules: ["currency_code"],
|
||||
},
|
||||
{ id: createdPriceSet[0].id, rules: ["currency_code"] },
|
||||
])
|
||||
|
||||
priceSet = await service.list(
|
||||
{
|
||||
id: [createdPriceSet[0].id],
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"rule_types",
|
||||
"price_set_money_amounts",
|
||||
"price_rules",
|
||||
],
|
||||
}
|
||||
{ id: [createdPriceSet[0].id] },
|
||||
{ relations: ["rule_types", "prices", "price_rules"] }
|
||||
)
|
||||
expect(priceSet).toEqual([
|
||||
{
|
||||
id: expect.any(String),
|
||||
price_rules: [],
|
||||
price_set_money_amounts: [],
|
||||
prices: [],
|
||||
rule_types: [],
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
@@ -617,13 +582,13 @@ moduleIntegrationTestRunner({
|
||||
|
||||
const [priceSet] = await service.list(
|
||||
{ id: ["price-set-1"] },
|
||||
{ relations: ["price_set_money_amounts"] }
|
||||
{ relations: ["prices"] }
|
||||
)
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
@@ -659,13 +624,13 @@ moduleIntegrationTestRunner({
|
||||
|
||||
const priceSets = await service.list(
|
||||
{ id: ["price-set-1", "price-set-2"] },
|
||||
{ relations: ["price_set_money_amounts"] }
|
||||
{ relations: ["prices"] }
|
||||
)
|
||||
|
||||
expect(priceSets).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
@@ -674,7 +639,7 @@ moduleIntegrationTestRunner({
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-set-2",
|
||||
price_set_money_amounts: expect.arrayContaining([
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 150,
|
||||
currency_code: "EUR",
|
||||
@@ -707,17 +672,14 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addRules", () => {
|
||||
it("should add rules to existing price set", async () => {
|
||||
console.log("1")
|
||||
await service.addRules([
|
||||
{
|
||||
priceSetId: "price-set-1",
|
||||
rules: [
|
||||
{
|
||||
attribute: "region_id",
|
||||
},
|
||||
],
|
||||
rules: [{ attribute: "region_id" }],
|
||||
},
|
||||
])
|
||||
|
||||
console.log("2")
|
||||
const [priceSet] = await service.list(
|
||||
{ id: ["price-set-1"] },
|
||||
{ relations: ["rule_types"] }
|
||||
@@ -745,11 +707,7 @@ moduleIntegrationTestRunner({
|
||||
await service.addRules([
|
||||
{
|
||||
priceSetId: "price-set-doesn't-exist",
|
||||
rules: [
|
||||
{
|
||||
attribute: "region_id",
|
||||
},
|
||||
],
|
||||
rules: [{ attribute: "region_id" }],
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
@@ -766,14 +724,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
try {
|
||||
await service.addRules([
|
||||
{
|
||||
priceSetId: "price-set-1",
|
||||
rules: [
|
||||
{
|
||||
attribute: "city",
|
||||
},
|
||||
],
|
||||
},
|
||||
{ priceSetId: "price-set-1", rules: [{ attribute: "city" }] },
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
|
||||
Reference in New Issue
Block a user