diff --git a/.github/workflows/erlang-checks.yaml b/.github/workflows/erlang-checks.yaml index f08b691..d2fac3b 100644 --- a/.github/workflows/erlang-checks.yaml +++ b/.github/workflows/erlang-checks.yaml @@ -30,11 +30,12 @@ jobs: run: name: Run checks needs: setup - uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.3 + uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.9 with: otp-version: ${{ needs.setup.outputs.otp-version }} rebar-version: ${{ needs.setup.outputs.rebar-version }} use-thrift: true thrift-version: ${{ needs.setup.outputs.thrift-version }} run-ct-with-compose: true + use-coveralls: true cache-version: v2 diff --git a/apps/party_management/src/pm_selector.erl b/apps/party_management/src/pm_selector.erl index baec5a3..46e944e 100644 --- a/apps/party_management/src/pm_selector.erl +++ b/apps/party_management/src/pm_selector.erl @@ -48,7 +48,6 @@ }. -type predicate() :: dmsl_domain_thrift:'Predicate'(). --type criterion() :: dmsl_domain_thrift:'Criterion'(). -export_type([varset/0]). @@ -101,9 +100,7 @@ reduce_decisions([], _, _) -> []. -spec reduce_predicate(predicate(), varset(), pm_domain:revision()) -> - predicate() - % for a partially reduced criterion - | {criterion, criterion()}. + predicate(). reduce_predicate(?const(B), _, _) -> ?const(B); reduce_predicate({condition, C0}, VS, Rev) -> @@ -126,11 +123,14 @@ reduce_predicate({any_of, Ps}, VS, Rev) -> reduce_combination(any_of, true, Ps, VS, Rev, []); reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) -> Criterion = pm_domain:get(Rev, {criterion, CriterionRef}), - case reduce_predicate(Criterion#domain_Criterion.predicate, VS, Rev) of + Predicate = Criterion#domain_Criterion.predicate, + case reduce_predicate(Predicate, VS, Rev) of ?const(B) -> ?const(B); - P1 -> - {criterion, Criterion#domain_Criterion{predicate = P1}} + Predicate -> + {criterion, CriterionRef}; + NewPredicate -> + NewPredicate end. reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) -> @@ -144,6 +144,8 @@ reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) -> end; reduce_combination(_, Fix, [], _, _, []) -> ?const(not Fix); +reduce_combination(_, _, [], _, _, [P]) -> + P; reduce_combination(Type, _, [], _, _, PAcc) -> {Type, lists:reverse(PAcc)}. diff --git a/apps/party_management/test/pm_party_tests_SUITE.erl b/apps/party_management/test/pm_party_tests_SUITE.erl index 69ca590..874cdc8 100644 --- a/apps/party_management/test/pm_party_tests_SUITE.erl +++ b/apps/party_management/test/pm_party_tests_SUITE.erl @@ -107,10 +107,12 @@ -export([compute_provider_terminal_not_found/1]). -export([compute_globals_ok/1]). -export([compute_payment_routing_ruleset_ok/1]). --export([compute_payment_routing_ruleset_unreducable/1]). +-export([compute_payment_routing_ruleset_irreducible/1]). -export([compute_payment_routing_ruleset_not_found/1]). +-export([compute_pred_w_partial_all_of/1]). -export([compute_pred_w_irreducible_criterion/1]). +-export([compute_pred_w_partially_irreducible_criterion/1]). -export([compute_terms_w_criteria/1]). -export([check_all_payment_methods/1]). -export([check_all_withdrawal_methods/1]). @@ -274,12 +276,14 @@ groups() -> compute_provider_terminal_not_found, compute_globals_ok, compute_payment_routing_ruleset_ok, - compute_payment_routing_ruleset_unreducable, + compute_payment_routing_ruleset_irreducible, compute_payment_routing_ruleset_not_found ]}, {terms, [sequence], [ party_creation, + compute_pred_w_partial_all_of, compute_pred_w_irreducible_criterion, + compute_pred_w_partially_irreducible_criterion, compute_terms_w_criteria, check_all_payment_methods, check_all_withdrawal_methods @@ -508,10 +512,12 @@ end_per_testcase(_Name, _C) -> -spec compute_provider_terminal_not_found(config()) -> _ | no_return(). -spec compute_globals_ok(config()) -> _ | no_return(). -spec compute_payment_routing_ruleset_ok(config()) -> _ | no_return(). --spec compute_payment_routing_ruleset_unreducable(config()) -> _ | no_return(). +-spec compute_payment_routing_ruleset_irreducible(config()) -> _ | no_return(). -spec compute_payment_routing_ruleset_not_found(config()) -> _ | no_return(). +-spec compute_pred_w_partial_all_of(config()) -> _ | no_return(). -spec compute_pred_w_irreducible_criterion(config()) -> _ | no_return(). +-spec compute_pred_w_partially_irreducible_criterion(config()) -> _ | no_return(). -spec compute_terms_w_criteria(config()) -> _ | no_return(). party_creation(C) -> @@ -1847,7 +1853,7 @@ compute_payment_routing_ruleset_ok(C) -> ]} } = pm_client_party:compute_routing_ruleset(?ruleset(1), DomainRevision, Varset, Client). -compute_payment_routing_ruleset_unreducable(C) -> +compute_payment_routing_ruleset_irreducible(C) -> Client = cfg(client, C), DomainRevision = pm_domain:head(), Varset = #payproc_Varset{}, @@ -1878,14 +1884,49 @@ compute_payment_routing_ruleset_not_found(C) -> %% +compute_pred_w_partial_all_of(_) -> + Revision = pm_domain:head(), + Predicate = + {all_of, [ + {constant, true}, + {condition, {currency_is, ?cur(<<"CNY">>)}}, + Cond1 = {condition, {category_is, ?cat(42)}}, + Cond2 = {condition, {shop_location_is, {url, <<"https://thisiswhyimbroke.com">>}}} + ]}, + ?assertMatch( + {all_of, [Cond1, Cond2]}, + pm_selector:reduce_predicate( + Predicate, + #{currency => ?cur(<<"CNY">>)}, + Revision + ) + ). + compute_pred_w_irreducible_criterion(_) -> - CritRef = ?crit(1), - CritName = <<"HAHA GOT ME">>, + CriterionRef = ?crit(1), pm_ct_domain:with( [ pm_ct_fixture:construct_criterion( - CritRef, - CritName, + CriterionRef, + <<"HAHA">>, + {condition, {currency_is, ?cur(<<"KZT">>)}} + ) + ], + fun(Revision) -> + ?assertMatch( + {criterion, CriterionRef}, + pm_selector:reduce_predicate({criterion, CriterionRef}, #{}, Revision) + ) + end + ). + +compute_pred_w_partially_irreducible_criterion(_) -> + CriterionRef = ?crit(1), + pm_ct_domain:with( + [ + pm_ct_fixture:construct_criterion( + CriterionRef, + <<"HAHA GOT ME">>, {all_of, [ {constant, true}, {is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}} @@ -1894,8 +1935,8 @@ compute_pred_w_irreducible_criterion(_) -> ], fun(Revision) -> ?assertMatch( - {criterion, #domain_Criterion{name = CritName, predicate = {all_of, [_]}}}, - pm_selector:reduce_predicate({criterion, CritRef}, #{}, Revision) + {is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}}, + pm_selector:reduce_predicate({criterion, CriterionRef}, #{}, Revision) ) end ). diff --git a/rebar.config b/rebar.config index ae0ef0c..292fe59 100644 --- a/rebar.config +++ b/rebar.config @@ -104,7 +104,8 @@ {project_plugins, [ {rebar3_lint, "1.0.1"}, {covertool, "2.0.4"}, - {erlfmt, "1.0.0"} + {erlfmt, "1.0.0"}, + {rebar3_lcov, {git, "https://github.com/valitydev/rebar3-lcov.git", {tag, "0.1"}}} ]}. {erlfmt, [