From f4e4ccc1f24cdb202c45447cce3e734a0350ecd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Tue, 8 Nov 2022 19:06:38 +0400 Subject: [PATCH] added allow support --- apps/hellgate/src/hg_routing.erl | 11 ++++++++ apps/hellgate/test/hg_ct_domain.hrl | 1 + .../test/hg_route_rules_tests_SUITE.erl | 26 ++++++++++++++----- rebar.lock | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/apps/hellgate/src/hg_routing.erl b/apps/hellgate/src/hg_routing.erl index 3f589e1..f93ba37 100644 --- a/apps/hellgate/src/hg_routing.erl +++ b/apps/hellgate/src/hg_routing.erl @@ -617,6 +617,7 @@ check_terms_acceptability(recurrent_payment, Terms, VS) -> acceptable_payment_terms( #domain_PaymentsProvisionTerms{ + allow = Allow, currencies = CurrenciesSelector, categories = CategoriesSelector, payment_methods = PMsSelector, @@ -630,6 +631,7 @@ acceptable_payment_terms( % TODO varsets getting mixed up % it seems better to pass down here hierarchy of contexts w/ appropriate module accessors ParentName = 'PaymentsProvisionTerms', + _ = acceptable_allow(ParentName, Allow), _ = try_accept_term(ParentName, currency, getv(currency, VS), CurrenciesSelector), _ = try_accept_term(ParentName, category, getv(category, VS), CategoriesSelector), _ = try_accept_term(ParentName, payment_tool, getv(payment_tool, VS), PMsSelector), @@ -692,6 +694,15 @@ acceptable_partial_refunds_terms( acceptable_partial_refunds_terms(undefined, _RVS) -> throw(?rejected({'PartialRefundsProvisionTerms', undefined})). +acceptable_allow(_ParentName, undefined) -> + true; +acceptable_allow(_ParentName, {constant, true}) -> + true; +acceptable_allow(ParentName, {constant, false}) -> + throw(?rejected({ParentName, allow})); +acceptable_allow(_ParentName, Ambiguous) -> + error({misconfiguration, {'Could not reduce predicate to a value', {allow, Ambiguous}}}). + %% acceptable_recurrent_paytool_terms( diff --git a/apps/hellgate/test/hg_ct_domain.hrl b/apps/hellgate/test/hg_ct_domain.hrl index 9c97628..89f9afe 100644 --- a/apps/hellgate/test/hg_ct_domain.hrl +++ b/apps/hellgate/test/hg_ct_domain.hrl @@ -163,6 +163,7 @@ }). -define(payment_terms, #domain_PaymentsProvisionTerms{ + allow = {constant, true}, currencies = {value, ?ordset([ diff --git a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl index 8fb1422..8c9900c 100644 --- a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl +++ b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl @@ -239,7 +239,8 @@ mock_party_management(SupPid) -> {candidates, [ ?candidate({constant, true}, ?trm(1)), ?candidate({constant, true}, ?trm(2)), - ?candidate({constant, true}, ?trm(3)) + ?candidate({constant, true}, ?trm(3)), + ?candidate({constant, true}, ?trm(4)) ]} }}; ('ComputeRoutingRuleset', {?ruleset(1), ?base_routing_rule_domain_revision, _}) -> @@ -292,6 +293,12 @@ mock_party_management(SupPid) -> ])} } }}; + ('ComputeProviderTerminalTerms', {?prv(4), _, ?base_routing_rule_domain_revision, _}) -> + {ok, #domain_ProvisionTermSet{ + payments = ?payment_terms#domain_PaymentsProvisionTerms{ + allow = {constant, false} + } + }}; ('ComputeProviderTerminalTerms', {?prv(1), _, ?routing_with_risk_coverage_set_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = ?payment_terms#domain_PaymentsProvisionTerms{ @@ -400,7 +407,8 @@ no_route_found_for_payment(_C) -> [ {?prv(1), ?trm(1), {'PaymentsProvisionTerms', cost}}, {?prv(2), ?trm(2), {'PaymentsProvisionTerms', category}}, - {?prv(3), ?trm(3), {'PaymentsProvisionTerms', payment_tool}} + {?prv(3), ?trm(3), {'PaymentsProvisionTerms', payment_tool}}, + {?prv(4), ?trm(4), {'PaymentsProvisionTerms', allow}} ], RejectedRoutes1 ), @@ -418,7 +426,8 @@ no_route_found_for_payment(_C) -> [ {?prv(1), ?trm(1), {'PaymentsProvisionTerms', currency}}, {?prv(2), ?trm(2), {'PaymentsProvisionTerms', category}}, - {?prv(3), ?trm(3), {'PaymentsProvisionTerms', payment_tool}} + {?prv(3), ?trm(3), {'PaymentsProvisionTerms', payment_tool}}, + {?prv(4), ?trm(4), {'PaymentsProvisionTerms', allow}} ], RejectedRoutes2 ). @@ -456,7 +465,8 @@ gather_route_success(_C) -> ?assertMatch( [ {?prv(2), ?trm(2), {'PaymentsProvisionTerms', category}}, - {?prv(3), ?trm(3), {'PaymentsProvisionTerms', payment_tool}} + {?prv(3), ?trm(3), {'PaymentsProvisionTerms', payment_tool}}, + {?prv(4), ?trm(4), {'PaymentsProvisionTerms', allow}} ], RejectedRoutes ). @@ -495,7 +505,8 @@ rejected_by_table_prohibitions(_C) -> [ {?prv(3), ?trm(3), {'RoutingRule', undefined}}, {?prv(1), ?trm(1), {'PaymentsProvisionTerms', payment_tool}}, - {?prv(2), ?trm(2), {'PaymentsProvisionTerms', category}} + {?prv(2), ?trm(2), {'PaymentsProvisionTerms', category}}, + {?prv(4), ?trm(4), {'PaymentsProvisionTerms', allow}} ], RejectedRoutes ), @@ -562,11 +573,11 @@ ruleset_misconfig(_C) -> -spec routes_selected_for_low_risk_score(config()) -> test_return(). routes_selected_for_low_risk_score(C) -> - routes_selected_with_risk_score(C, low, [?prv(1), ?prv(2), ?prv(3)]). + routes_selected_with_risk_score(C, low, [?prv(1), ?prv(2), ?prv(3), ?prv(4)]). -spec routes_selected_for_high_risk_score(config()) -> test_return(). routes_selected_for_high_risk_score(C) -> - routes_selected_with_risk_score(C, high, [?prv(2), ?prv(3)]). + routes_selected_with_risk_score(C, high, [?prv(2), ?prv(3), ?prv(4)]). routes_selected_with_risk_score(_C, RiskScore, ProviderRefs) -> Currency = ?cur(<<"RUB">>), @@ -755,6 +766,7 @@ construct_domain_fixture() -> {terminal, ?trm(1)} => {terminal, ?terminal_obj(?trm(1), ?prv(1))}, {terminal, ?trm(2)} => {terminal, ?terminal_obj(?trm(2), ?prv(2))}, {terminal, ?trm(3)} => {terminal, ?terminal_obj(?trm(3), ?prv(3))}, + {terminal, ?trm(4)} => {terminal, ?terminal_obj(?trm(4), ?prv(4))}, {terminal, ?trm(11)} => {terminal, ?terminal_obj(?trm(11), ?prv(11))}, {terminal, ?trm(12)} => {terminal, ?terminal_obj(?trm(12), ?prv(12))}, {payment_institution, ?pinst(1)} => diff --git a/rebar.lock b/rebar.lock index 4a83bf3..23b9cf4 100644 --- a/rebar.lock +++ b/rebar.lock @@ -17,7 +17,7 @@ {<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"6655937cfd504d14bf83c40f5d09315dbffbdcfc"}}, + {ref,"d59017c42e41e2e94f79a9c2260a814fe0b0ca77"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt-client.git",