mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
TD-671: FIX - Check withdrawal status on domain adjustment (#64)
This commit is contained in:
parent
d84edce7ec
commit
f1c188e42a
@ -158,7 +158,9 @@
|
||||
invalid_withdrawal_status_error()
|
||||
| invalid_status_change_error()
|
||||
| {another_adjustment_in_progress, adjustment_id()}
|
||||
| {invalid_cash_flow_change, {already_has_domain_revision, domain_revision()}}
|
||||
| {invalid_cash_flow_change,
|
||||
{already_has_domain_revision, domain_revision()}
|
||||
| {unavailable_status, status()}}
|
||||
| ff_adjustment:create_error().
|
||||
|
||||
-type finalize_session_error() ::
|
||||
@ -1601,13 +1603,17 @@ validate_change_same_status(Status, Status) ->
|
||||
|
||||
-spec validate_domain_revision_change(adjustment_params(), withdrawal_state()) ->
|
||||
{ok, valid}
|
||||
| {error, {invalid_cash_flow_change, {already_has_domain_revision, domain_revision()}}}.
|
||||
| {error,
|
||||
{invalid_cash_flow_change,
|
||||
{already_has_domain_revision, domain_revision()}
|
||||
| {unavailable_status, status()}}}.
|
||||
validate_domain_revision_change(#{change := {change_cash_flow, DomainRevision}}, Withdrawal) ->
|
||||
do(fun() ->
|
||||
valid = unwrap(
|
||||
invalid_cash_flow_change,
|
||||
validate_change_same_domain_revision(DomainRevision, final_domain_revision(Withdrawal))
|
||||
)
|
||||
),
|
||||
valid = unwrap(invalid_cash_flow_change, validate_current_status(status(Withdrawal)))
|
||||
end);
|
||||
validate_domain_revision_change(_Params, _Withdrawal) ->
|
||||
{ok, valid}.
|
||||
@ -1622,6 +1628,16 @@ validate_change_same_domain_revision(NewDomainRevision, OldDomainRevision) when
|
||||
validate_change_same_domain_revision(DomainRevision, DomainRevision) ->
|
||||
{error, {already_has_domain_revision, DomainRevision}}.
|
||||
|
||||
-spec validate_current_status(status()) ->
|
||||
{ok, valid}
|
||||
| {error, {unavailable_status, status()}}.
|
||||
validate_current_status(succeeded) ->
|
||||
{ok, valid};
|
||||
validate_current_status(Status = {failed, _Failure}) ->
|
||||
{error, {unavailable_status, Status}};
|
||||
validate_current_status(Status) ->
|
||||
{error, {unavailable_status, Status}}.
|
||||
|
||||
%% Adjustment helpers
|
||||
|
||||
-spec apply_adjustment_event(wrapped_adjustment_event(), withdrawal_state()) -> withdrawal_state().
|
||||
|
@ -26,6 +26,7 @@
|
||||
-export([no_pending_withdrawal_adjustments_test/1]).
|
||||
-export([unknown_withdrawal_test/1]).
|
||||
-export([adjustment_can_not_change_domain_revision_to_same/1]).
|
||||
-export([adjustment_can_not_change_domain_revision_with_failed_status/1]).
|
||||
-export([adjustment_can_change_domain_revision_test/1]).
|
||||
|
||||
%% Internal types
|
||||
@ -62,7 +63,8 @@ groups() ->
|
||||
no_parallel_adjustments_test,
|
||||
no_pending_withdrawal_adjustments_test,
|
||||
unknown_withdrawal_test,
|
||||
adjustment_can_not_change_domain_revision_to_same
|
||||
adjustment_can_not_change_domain_revision_to_same,
|
||||
adjustment_can_not_change_domain_revision_with_failed_status
|
||||
]},
|
||||
{non_parallel, [sequence], [
|
||||
adjustment_can_change_domain_revision_test
|
||||
@ -316,6 +318,27 @@ adjustment_can_not_change_domain_revision_to_same(C) ->
|
||||
}),
|
||||
?assertMatch({error, {invalid_cash_flow_change, {already_has_domain_revision, DomainRevision}}}, Result).
|
||||
|
||||
-spec adjustment_can_not_change_domain_revision_with_failed_status(config()) -> test_return().
|
||||
adjustment_can_not_change_domain_revision_with_failed_status(C) ->
|
||||
#{
|
||||
wallet_id := WalletID,
|
||||
destination_id := DestinationID
|
||||
} = prepare_standard_environment({100, <<"RUB">>}, C),
|
||||
WithdrawalID = generate_id(),
|
||||
Params = #{
|
||||
id => WithdrawalID,
|
||||
wallet_id => WalletID,
|
||||
destination_id => DestinationID,
|
||||
body => {1000, <<"RUB">>}
|
||||
},
|
||||
ok = ff_withdrawal_machine:create(Params, ff_entity_context:new()),
|
||||
?assertMatch({failed, _}, await_final_withdrawal_status(WithdrawalID)),
|
||||
Result = ff_withdrawal_machine:start_adjustment(WithdrawalID, #{
|
||||
id => generate_id(),
|
||||
change => {change_cash_flow, ct_domain_config:head() - 1}
|
||||
}),
|
||||
?assertMatch({error, {invalid_cash_flow_change, {unavailable_status, {failed, #{code := _}}}}}, Result).
|
||||
|
||||
-spec adjustment_can_change_domain_revision_test(config()) -> test_return().
|
||||
adjustment_can_change_domain_revision_test(C) ->
|
||||
ProviderID = 1,
|
||||
|
Loading…
Reference in New Issue
Block a user