mirror of
https://github.com/valitydev/party-management.git
synced 2024-11-06 01:05:21 +00:00
parent
4a94036a44
commit
486616e7ae
@ -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.
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user