TD-574: Add new condition (#29)

* TD-574: Add new condition

* Fix test
This commit is contained in:
ndiezel0 2023-05-10 02:09:19 +03:00 committed by GitHub
parent 4a94036a44
commit 486616e7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -1,6 +1,7 @@
-module(pm_condition).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("party_management/include/domain.hrl").
%%
@ -29,6 +30,8 @@ test({currency_is, V1}, #{currency := V2}, _) ->
V1 =:= V2;
test({cost_in, V}, #{cost := C}, _) ->
pm_cash_range:is_inside(C, V) =:= within;
test({cost_is_multiple_of, V}, #{cost := C}, _) ->
test_cash_is_multiple_of(V, C);
test({payment_tool, C}, #{payment_tool := V}, Rev) ->
pm_payment_tool:test_condition(C, V, Rev);
test({shop_location_is, V}, #{shop := S}, _) ->
@ -182,6 +185,14 @@ to_ternary_bool(Bool) when is_boolean(Bool) -> Bool;
to_ternary_bool(undefined) -> undefined;
to_ternary_bool(_) -> true.
test_cash_is_multiple_of(
#domain_Cash{amount = A1, currency = C},
#domain_Cash{amount = A2, currency = C}
) ->
A1 rem A2 =:= 0;
test_cash_is_multiple_of(_, _) ->
false.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
@ -267,4 +278,14 @@ ternary_while_truth_table_test() ->
Table
).
-spec cash_is_multiple_of_condition_test() -> _.
cash_is_multiple_of_condition_test() ->
Currency1 = <<"RUB">>,
Currency2 = <<"USD">>,
_ = [
?assertEqual(test_cash_is_multiple_of(?cash(10, Currency1), ?cash(5, Currency1)), true),
?assertEqual(test_cash_is_multiple_of(?cash(10, Currency1), ?cash(7, Currency1)), false),
?assertEqual(test_cash_is_multiple_of(?cash(10, Currency1), ?cash(5, Currency2)), false)
].
-endif.

View File

@ -9,7 +9,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"cc95eab778addb9b4cb86b648c60dc87d2cec645"}},
{ref,"03bf41075c39b6731c5ed200d5c4b0faaee9d937"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",