mirror of
https://github.com/valitydev/party-management.git
synced 2024-11-06 09:15:18 +00:00
TD-416: Ensure partially reduced predicate is valid predicate (#23)
* Simplify combination consisting of single predicate * Add extra testcases * Enable coveralls
This commit is contained in:
parent
bbbeae5006
commit
1c7f97d16c
3
.github/workflows/erlang-checks.yaml
vendored
3
.github/workflows/erlang-checks.yaml
vendored
@ -30,11 +30,12 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
name: Run checks
|
name: Run checks
|
||||||
needs: setup
|
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:
|
with:
|
||||||
otp-version: ${{ needs.setup.outputs.otp-version }}
|
otp-version: ${{ needs.setup.outputs.otp-version }}
|
||||||
rebar-version: ${{ needs.setup.outputs.rebar-version }}
|
rebar-version: ${{ needs.setup.outputs.rebar-version }}
|
||||||
use-thrift: true
|
use-thrift: true
|
||||||
thrift-version: ${{ needs.setup.outputs.thrift-version }}
|
thrift-version: ${{ needs.setup.outputs.thrift-version }}
|
||||||
run-ct-with-compose: true
|
run-ct-with-compose: true
|
||||||
|
use-coveralls: true
|
||||||
cache-version: v2
|
cache-version: v2
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
}.
|
}.
|
||||||
|
|
||||||
-type predicate() :: dmsl_domain_thrift:'Predicate'().
|
-type predicate() :: dmsl_domain_thrift:'Predicate'().
|
||||||
-type criterion() :: dmsl_domain_thrift:'Criterion'().
|
|
||||||
|
|
||||||
-export_type([varset/0]).
|
-export_type([varset/0]).
|
||||||
|
|
||||||
@ -101,9 +100,7 @@ reduce_decisions([], _, _) ->
|
|||||||
[].
|
[].
|
||||||
|
|
||||||
-spec reduce_predicate(predicate(), varset(), pm_domain:revision()) ->
|
-spec reduce_predicate(predicate(), varset(), pm_domain:revision()) ->
|
||||||
predicate()
|
predicate().
|
||||||
% for a partially reduced criterion
|
|
||||||
| {criterion, criterion()}.
|
|
||||||
reduce_predicate(?const(B), _, _) ->
|
reduce_predicate(?const(B), _, _) ->
|
||||||
?const(B);
|
?const(B);
|
||||||
reduce_predicate({condition, C0}, VS, Rev) ->
|
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_combination(any_of, true, Ps, VS, Rev, []);
|
||||||
reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) ->
|
reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) ->
|
||||||
Criterion = pm_domain:get(Rev, {criterion, CriterionRef}),
|
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) ->
|
||||||
?const(B);
|
?const(B);
|
||||||
P1 ->
|
Predicate ->
|
||||||
{criterion, Criterion#domain_Criterion{predicate = P1}}
|
{criterion, CriterionRef};
|
||||||
|
NewPredicate ->
|
||||||
|
NewPredicate
|
||||||
end.
|
end.
|
||||||
|
|
||||||
reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) ->
|
reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) ->
|
||||||
@ -144,6 +144,8 @@ reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) ->
|
|||||||
end;
|
end;
|
||||||
reduce_combination(_, Fix, [], _, _, []) ->
|
reduce_combination(_, Fix, [], _, _, []) ->
|
||||||
?const(not Fix);
|
?const(not Fix);
|
||||||
|
reduce_combination(_, _, [], _, _, [P]) ->
|
||||||
|
P;
|
||||||
reduce_combination(Type, _, [], _, _, PAcc) ->
|
reduce_combination(Type, _, [], _, _, PAcc) ->
|
||||||
{Type, lists:reverse(PAcc)}.
|
{Type, lists:reverse(PAcc)}.
|
||||||
|
|
||||||
|
@ -107,10 +107,12 @@
|
|||||||
-export([compute_provider_terminal_not_found/1]).
|
-export([compute_provider_terminal_not_found/1]).
|
||||||
-export([compute_globals_ok/1]).
|
-export([compute_globals_ok/1]).
|
||||||
-export([compute_payment_routing_ruleset_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_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_irreducible_criterion/1]).
|
||||||
|
-export([compute_pred_w_partially_irreducible_criterion/1]).
|
||||||
-export([compute_terms_w_criteria/1]).
|
-export([compute_terms_w_criteria/1]).
|
||||||
-export([check_all_payment_methods/1]).
|
-export([check_all_payment_methods/1]).
|
||||||
-export([check_all_withdrawal_methods/1]).
|
-export([check_all_withdrawal_methods/1]).
|
||||||
@ -274,12 +276,14 @@ groups() ->
|
|||||||
compute_provider_terminal_not_found,
|
compute_provider_terminal_not_found,
|
||||||
compute_globals_ok,
|
compute_globals_ok,
|
||||||
compute_payment_routing_ruleset_ok,
|
compute_payment_routing_ruleset_ok,
|
||||||
compute_payment_routing_ruleset_unreducable,
|
compute_payment_routing_ruleset_irreducible,
|
||||||
compute_payment_routing_ruleset_not_found
|
compute_payment_routing_ruleset_not_found
|
||||||
]},
|
]},
|
||||||
{terms, [sequence], [
|
{terms, [sequence], [
|
||||||
party_creation,
|
party_creation,
|
||||||
|
compute_pred_w_partial_all_of,
|
||||||
compute_pred_w_irreducible_criterion,
|
compute_pred_w_irreducible_criterion,
|
||||||
|
compute_pred_w_partially_irreducible_criterion,
|
||||||
compute_terms_w_criteria,
|
compute_terms_w_criteria,
|
||||||
check_all_payment_methods,
|
check_all_payment_methods,
|
||||||
check_all_withdrawal_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_provider_terminal_not_found(config()) -> _ | no_return().
|
||||||
-spec compute_globals_ok(config()) -> _ | no_return().
|
-spec compute_globals_ok(config()) -> _ | no_return().
|
||||||
-spec compute_payment_routing_ruleset_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_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_irreducible_criterion(config()) -> _ | no_return().
|
||||||
|
-spec compute_pred_w_partially_irreducible_criterion(config()) -> _ | no_return().
|
||||||
-spec compute_terms_w_criteria(config()) -> _ | no_return().
|
-spec compute_terms_w_criteria(config()) -> _ | no_return().
|
||||||
|
|
||||||
party_creation(C) ->
|
party_creation(C) ->
|
||||||
@ -1847,7 +1853,7 @@ compute_payment_routing_ruleset_ok(C) ->
|
|||||||
]}
|
]}
|
||||||
} = pm_client_party:compute_routing_ruleset(?ruleset(1), DomainRevision, Varset, Client).
|
} = 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),
|
Client = cfg(client, C),
|
||||||
DomainRevision = pm_domain:head(),
|
DomainRevision = pm_domain:head(),
|
||||||
Varset = #payproc_Varset{},
|
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(_) ->
|
compute_pred_w_irreducible_criterion(_) ->
|
||||||
CritRef = ?crit(1),
|
CriterionRef = ?crit(1),
|
||||||
CritName = <<"HAHA GOT ME">>,
|
|
||||||
pm_ct_domain:with(
|
pm_ct_domain:with(
|
||||||
[
|
[
|
||||||
pm_ct_fixture:construct_criterion(
|
pm_ct_fixture:construct_criterion(
|
||||||
CritRef,
|
CriterionRef,
|
||||||
CritName,
|
<<"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, [
|
{all_of, [
|
||||||
{constant, true},
|
{constant, true},
|
||||||
{is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}}
|
{is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}}
|
||||||
@ -1894,8 +1935,8 @@ compute_pred_w_irreducible_criterion(_) ->
|
|||||||
],
|
],
|
||||||
fun(Revision) ->
|
fun(Revision) ->
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{criterion, #domain_Criterion{name = CritName, predicate = {all_of, [_]}}},
|
{is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}},
|
||||||
pm_selector:reduce_predicate({criterion, CritRef}, #{}, Revision)
|
pm_selector:reduce_predicate({criterion, CriterionRef}, #{}, Revision)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
).
|
).
|
||||||
|
@ -104,7 +104,8 @@
|
|||||||
{project_plugins, [
|
{project_plugins, [
|
||||||
{rebar3_lint, "1.0.1"},
|
{rebar3_lint, "1.0.1"},
|
||||||
{covertool, "2.0.4"},
|
{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, [
|
{erlfmt, [
|
||||||
|
Loading…
Reference in New Issue
Block a user