mirror of
https://github.com/valitydev/limiter.git
synced 2024-11-06 00:55:22 +00:00
TD-550: Adds business exceptions for rollback (#22)
* Bumps limiter-proto
This commit is contained in:
parent
5af0cc663a
commit
2b8723b0d1
@ -90,20 +90,24 @@ handle_get_error(Error) ->
|
||||
-spec handle_hold_error(_) -> no_return().
|
||||
handle_hold_error({_, {invalid_request, Errors}}) ->
|
||||
woody_error:raise(business, #base_InvalidRequest{errors = Errors});
|
||||
handle_hold_error({_, {invalid_operation_currency, {Currency, ExpectedCurrency}}}) ->
|
||||
handle_hold_error(Error) ->
|
||||
handle_business_error(Error).
|
||||
|
||||
-spec handle_business_error(_) -> no_return().
|
||||
handle_business_error({_, {invalid_operation_currency, {Currency, ExpectedCurrency}}}) ->
|
||||
woody_error:raise(business, #limiter_InvalidOperationCurrency{
|
||||
currency = Currency,
|
||||
expected_currency = ExpectedCurrency
|
||||
});
|
||||
handle_hold_error({_, {operation_context_not_supported, ContextType}}) ->
|
||||
handle_business_error({_, {operation_context_not_supported, ContextType}}) ->
|
||||
woody_error:raise(business, #limiter_OperationContextNotSupported{
|
||||
context_type = ContextType
|
||||
});
|
||||
handle_hold_error({_, {unsupported, {payment_tool, Type}}}) ->
|
||||
handle_business_error({_, {unsupported, {payment_tool, Type}}}) ->
|
||||
woody_error:raise(business, #limiter_PaymentToolNotSupported{
|
||||
payment_tool = atom_to_binary(Type)
|
||||
});
|
||||
handle_hold_error(Error) ->
|
||||
handle_business_error(Error) ->
|
||||
handle_default_error(Error).
|
||||
|
||||
-spec handle_commit_error(_) -> no_return().
|
||||
@ -118,7 +122,7 @@ handle_commit_error(Error) ->
|
||||
handle_rollback_error({_, {invalid_request, Errors}}) ->
|
||||
woody_error:raise(business, #base_InvalidRequest{errors = Errors});
|
||||
handle_rollback_error(Error) ->
|
||||
handle_default_error(Error).
|
||||
handle_business_error(Error).
|
||||
|
||||
-spec handle_default_error(_) -> no_return().
|
||||
handle_default_error({config, notfound}) ->
|
||||
|
@ -21,8 +21,11 @@
|
||||
-export([partial_commit_with_exchange/1]).
|
||||
-export([commit_with_exchange/1]).
|
||||
-export([hold_with_disabled_exchange/1]).
|
||||
-export([rollback_with_wrong_currency/1]).
|
||||
-export([hold_with_wrong_operation_context/1]).
|
||||
-export([rollback_with_wrong_operation_context/1]).
|
||||
-export([hold_with_wrong_payment_tool/1]).
|
||||
-export([rollback_with_wrong_payment_tool/1]).
|
||||
-export([get_limit_ok/1]).
|
||||
-export([get_limit_notfound/1]).
|
||||
-export([hold_ok/1]).
|
||||
@ -79,8 +82,11 @@ groups() ->
|
||||
partial_commit_with_exchange,
|
||||
commit_with_exchange,
|
||||
hold_with_disabled_exchange,
|
||||
rollback_with_wrong_currency,
|
||||
hold_with_wrong_operation_context,
|
||||
rollback_with_wrong_operation_context,
|
||||
hold_with_wrong_payment_tool,
|
||||
rollback_with_wrong_payment_tool,
|
||||
get_limit_ok,
|
||||
get_limit_notfound,
|
||||
hold_ok,
|
||||
@ -106,8 +112,11 @@ groups() ->
|
||||
partial_commit_with_exchange,
|
||||
commit_with_exchange,
|
||||
hold_with_disabled_exchange,
|
||||
rollback_with_wrong_currency,
|
||||
hold_with_wrong_operation_context,
|
||||
rollback_with_wrong_operation_context,
|
||||
hold_with_wrong_payment_tool,
|
||||
rollback_with_wrong_payment_tool,
|
||||
get_limit_ok,
|
||||
get_limit_notfound,
|
||||
hold_ok,
|
||||
@ -299,6 +308,19 @@ hold_with_disabled_exchange(C) ->
|
||||
{exception, #limiter_InvalidOperationCurrency{currency = Currency, expected_currency = ConfiguredCurrency}} =
|
||||
lim_client:hold(?LIMIT_CHANGE(ID, ?CHANGE_ID, Version), Context, ?config(client, C)).
|
||||
|
||||
-spec rollback_with_wrong_currency(config()) -> _.
|
||||
rollback_with_wrong_currency(C) ->
|
||||
ok = application:set_env(limiter, currency_conversion, disabled),
|
||||
Rational = #base_Rational{p = 1000000, q = 100},
|
||||
_ = mock_exchange(Rational, C),
|
||||
ConfiguredCurrency = <<"RUB">>,
|
||||
{ID, Version} = configure_limit(?time_range_month(), ?global(), ?turnover_metric_amount(ConfiguredCurrency), C),
|
||||
Currency = <<"USD">>,
|
||||
Cost = ?cash(10000, Currency),
|
||||
Context = ?payproc_ctx_invoice(Cost),
|
||||
{exception, #limiter_InvalidOperationCurrency{currency = Currency, expected_currency = ConfiguredCurrency}} =
|
||||
lim_client:rollback(?LIMIT_CHANGE(ID, ?CHANGE_ID, Version), Context, ?config(client, C)).
|
||||
|
||||
-spec hold_with_wrong_operation_context(config()) -> _.
|
||||
hold_with_wrong_operation_context(C) ->
|
||||
Rational = #base_Rational{p = 1000000, q = 100},
|
||||
@ -311,6 +333,18 @@ hold_with_wrong_operation_context(C) ->
|
||||
}} =
|
||||
lim_client:hold(?LIMIT_CHANGE(ID, ?CHANGE_ID, Version), Context, ?config(client, C)).
|
||||
|
||||
-spec rollback_with_wrong_operation_context(config()) -> _.
|
||||
rollback_with_wrong_operation_context(C) ->
|
||||
Rational = #base_Rational{p = 1000000, q = 100},
|
||||
_ = mock_exchange(Rational, C),
|
||||
{ID, Version} = configure_limit(?time_range_month(), ?global(), C),
|
||||
Cost = ?cash(10000),
|
||||
Context = ?wthdproc_ctx_withdrawal(Cost),
|
||||
{exception, #limiter_OperationContextNotSupported{
|
||||
context_type = {withdrawal_processing, #limiter_config_LimitContextTypeWithdrawalProcessing{}}
|
||||
}} =
|
||||
lim_client:rollback(?LIMIT_CHANGE(ID, ?CHANGE_ID, Version), Context, ?config(client, C)).
|
||||
|
||||
-spec hold_with_wrong_payment_tool(config()) -> _.
|
||||
hold_with_wrong_payment_tool(C) ->
|
||||
Rational = #base_Rational{p = 1000000, q = 100},
|
||||
@ -321,6 +355,16 @@ hold_with_wrong_payment_tool(C) ->
|
||||
{exception, #limiter_PaymentToolNotSupported{payment_tool = <<"crypto_currency">>}} =
|
||||
lim_client:hold(?LIMIT_CHANGE(ID, ?CHANGE_ID, Version), Context, ?config(client, C)).
|
||||
|
||||
-spec rollback_with_wrong_payment_tool(config()) -> _.
|
||||
rollback_with_wrong_payment_tool(C) ->
|
||||
Rational = #base_Rational{p = 1000000, q = 100},
|
||||
_ = mock_exchange(Rational, C),
|
||||
{ID, Version} = configure_limit(?time_range_week(), ?scope([?scope_payment_tool()]), ?turnover_metric_number(), C),
|
||||
NotSupportedPaymentTool = {crypto_currency, #domain_CryptoCurrencyRef{id = <<"wow;so-cryptic;much-hidden">>}},
|
||||
Context = ?payproc_ctx_payment(?invoice_payment(?cash(10000), ?cash(10000), NotSupportedPaymentTool)),
|
||||
{exception, #limiter_PaymentToolNotSupported{payment_tool = <<"crypto_currency">>}} =
|
||||
lim_client:rollback(?LIMIT_CHANGE(ID, ?CHANGE_ID, Version), Context, ?config(client, C)).
|
||||
|
||||
-spec get_limit_ok(config()) -> _.
|
||||
get_limit_ok(C) ->
|
||||
{ID, Version} = configure_limit(?time_range_month(), ?global(), C),
|
||||
|
@ -33,7 +33,7 @@
|
||||
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},1},
|
||||
{<<"limiter_proto">>,
|
||||
{git,"https://github.com/valitydev/limiter-proto.git",
|
||||
{ref,"e46f732ae357ae302b9b9e4cd8e95725bfd060ee"}},
|
||||
{ref,"bbd2c0dce044dd5b4e424fc8e38a0023a1685a22"}},
|
||||
0},
|
||||
{<<"machinery">>,
|
||||
{git,"https://github.com/valitydev/machinery-erlang.git",
|
||||
|
Loading…
Reference in New Issue
Block a user