Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions apps/ff_server/src/ff_machine_handler.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-module(ff_machine_handler).

-export([init/2, terminate/3]).
-export([get_routes/0]).

-spec get_routes() -> _.
get_routes() ->
[
{"/traces/internal/source_v1/[:process_id]", ?MODULE, #{namespace => 'ff/source_v1'}},
{"/traces/internal/destination_v2/[:process_id]", ?MODULE, #{namespace => 'ff/destination_v2'}},
{"/traces/internal/deposit_v1/[:process_id]", ?MODULE, #{namespace => 'ff/deposit_v1'}},
{"/traces/internal/withdrawal_v2/[:process_id]", ?MODULE, #{namespace => 'ff/withdrawal_v2'}},
{"/traces/internal/withdrawal_session_v2/[:process_id]", ?MODULE, #{namespace => 'ff/withdrawal/session_v2'}}
].

-spec init(cowboy_req:req(), cowboy_http:opts()) ->
{ok, cowboy_req:req(), undefined}.
init(Request, Opts) ->
Method = cowboy_req:method(Request),
NS = maps:get(namespace, Opts),
ProcessID = cowboy_req:binding(process_id, Request),
maybe
{method_is_valid, true} ?= {method_is_valid, Method =:= <<"GET">>},
{process_id_is_valid, true} ?= {process_id_is_valid, is_binary(ProcessID)},
{ok, Trace} ?= ff_machine:trace(NS, ProcessID),
Body = unicode:characters_to_binary(json:encode(Trace)),
Req = cowboy_req:reply(200, #{}, Body, Request),
{ok, Req, undefined}
else
{method_is_valid, false} ->
Req1 = cowboy_req:reply(405, #{}, <<"Method Not Allowed">>, Request),
{ok, Req1, undefined};
{process_id_is_valid, false} ->
Req2 = cowboy_req:reply(400, #{}, <<"Invalid ProcessID">>, Request),
{ok, Req2, undefined};
{error, <<"process not found">>} ->
Req3 = cowboy_req:reply(404, #{}, <<"Unknown process">>, Request),
{ok, Req3, undefined}
end.

-spec terminate(term(), cowboy_req:req(), undefined) ->
ok.
terminate(_Reason, _Req, _State) ->
ok.
2 changes: 1 addition & 1 deletion apps/ff_server/src/ff_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ init([]) ->
handlers => WoodyHandlers,
event_handler => ff_woody_event_handler,
additional_routes =>
get_prometheus_routes() ++
get_prometheus_routes() ++ ff_machine_handler:get_routes() ++
[erl_health_handle:get_route(enable_health_logging(HealthCheck))]
}
)
Expand Down
56 changes: 55 additions & 1 deletion apps/ff_server/test/ff_deposit_handler_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
-export([unknown_test/1]).
-export([get_context_test/1]).
-export([get_events_test/1]).
-export([trace_deposit_ok_test/1]).

%% Internal types

Expand All @@ -56,7 +57,8 @@ groups() ->
create_negative_ok_test,
unknown_test,
get_context_test,
get_events_test
get_events_test,
trace_deposit_ok_test
]}
].

Expand Down Expand Up @@ -221,6 +223,58 @@ create_ok_test(_C) ->
ff_codec:unmarshal(timestamp_ms, DepositState#deposit_DepositState.created_at)
).

-spec trace_deposit_ok_test(config()) -> test_return().
trace_deposit_ok_test(_C) ->
Body = make_cash({100, <<"RUB">>}),
#{
party_id := PartyID,
wallet_id := WalletID,
source_id := SourceID
} = ct_objects:prepare_standard_environment(ct_objects:build_default_ctx()),
DepositID = genlib:bsuuid(),
ExternalID = genlib:bsuuid(),
Context = #{<<"NS">> => #{genlib:bsuuid() => genlib:bsuuid()}},
Metadata = ff_entity_context_codec:marshal(#{<<"metadata">> => #{<<"some key">> => <<"some data">>}}),
Description = <<"testDesc">>,
Params = #deposit_DepositParams{
id = DepositID,
party_id = PartyID,
body = Body,
source_id = SourceID,
wallet_id = WalletID,
metadata = Metadata,
external_id = ExternalID,
description = Description
},
{ok, _DepositState} = call_deposit('Create', {Params, ff_entity_context_codec:marshal(Context)}),
timer:sleep(1000),
TraceUrl = <<"http://localhost:8022/traces/internal/deposit_v1/", DepositID/binary>>,
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
{ok, TraceBody} = hackney:body(Ref),
[
#{
<<"args">> := [
[
#{<<"created">> := _},
#{<<"status_changed">> := <<"pending">>}
],
#{<<"NS">> := _}
],
<<"events">> := [
#{<<"event_id">> := 1, <<"event_payload">> := #{<<"created">> := _}, <<"event_timestamp">> := _},
#{<<"event_id">> := 2, <<"event_payload">> := #{<<"status_changed">> := _}, <<"event_timestamp">> := _}
],
<<"task_status">> := <<"finished">>,
<<"task_type">> := <<"init">>
},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>}
] = json:decode(TraceBody),
ok.

-spec create_negative_ok_test(config()) -> test_return().
create_negative_ok_test(_C) ->
Body = make_cash({-100, <<"RUB">>}),
Expand Down
40 changes: 39 additions & 1 deletion apps/ff_server/test/ff_destination_handler_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-export([create_ripple_wallet_destination_ok/1]).
-export([create_digital_wallet_destination_ok/1]).
-export([create_generic_destination_ok/1]).
-export([trace_destination_test/1]).

-type config() :: ct_helper:config().
-type test_case_name() :: ct_helper:test_case_name().
Expand All @@ -37,7 +38,8 @@ groups() ->
create_crypto_wallet_destination_ok,
create_ripple_wallet_destination_ok,
create_digital_wallet_destination_ok,
create_generic_destination_ok
create_generic_destination_ok,
trace_destination_test
]}
].

Expand Down Expand Up @@ -139,6 +141,42 @@ create_generic_destination_ok(C) ->
}},
create_destination_ok(Resource, C).

-spec trace_destination_test(config()) -> test_return().
trace_destination_test(C) ->
Resource =
{bank_card, #'fistful_base_ResourceBankCard'{
bank_card = #'fistful_base_BankCard'{
token = <<"TOKEN shmOKEN">>
}
}},
AuthData =
{sender_receiver, #destination_SenderReceiverAuthData{
sender = <<"SenderToken">>,
receiver = <<"ReceiverToken">>
}},
{ok, #destination_DestinationState{id = ID}} = create_destination_ok(AuthData, Resource, C),
TraceUrl = <<"http://localhost:8022/traces/internal/destination_v2/", ID/binary>>,
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
{ok, Body} = hackney:body(Ref),
[
#{
<<"args">> := [
[
#{<<"created">> := _},
#{<<"account">> := _}
],
#{<<"NS">> := #{}}
],
<<"events">> := [
#{<<"event_id">> := 1, <<"event_payload">> := #{<<"created">> := _}, <<"event_timestamp">> := _},
#{<<"event_id">> := 2, <<"event_payload">> := #{<<"account">> := _}, <<"event_timestamp">> := _}
],
<<"task_status">> := <<"finished">>,
<<"task_type">> := <<"init">>
}
] = json:decode(Body),
ok.

%%----------------------------------------------------------------------
%% Internal functions
%%----------------------------------------------------------------------
Expand Down
35 changes: 34 additions & 1 deletion apps/ff_server/test/ff_source_handler_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-export([get_source_context_ok_test/1]).
-export([create_source_ok_test/1]).
-export([unknown_test/1]).
-export([trace_source_ok_test/1]).

-type config() :: ct_helper:config().
-type test_case_name() :: ct_helper:test_case_name().
Expand All @@ -36,7 +37,8 @@ groups() ->
get_source_events_ok_test,
get_source_context_ok_test,
create_source_ok_test,
unknown_test
unknown_test,
trace_source_ok_test
]}
].

Expand Down Expand Up @@ -104,6 +106,37 @@ create_source_ok_test(C) ->
}},
create_source_ok(Resource, C).

-spec trace_source_ok_test(config()) -> test_return().
trace_source_ok_test(C) ->
Resource =
{internal, #source_Internal{
details = <<"details">>
}},
State = create_source_ok(Resource, C),
ID = State#source_SourceState.id,
TraceUrl = <<"http://localhost:8022/traces/internal/source_v1/", ID/binary>>,
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
{ok, Body} = hackney:body(Ref),
[
#{
<<"args">> := [
[
#{<<"created">> := _},
#{<<"account">> := _}
],
#{<<"NS">> := #{}}
],
<<"events">> := [
#{<<"event_id">> := 1, <<"event_payload">> := #{<<"created">> := _}, <<"event_timestamp">> := _},
#{<<"event_id">> := 2, <<"event_payload">> := #{<<"account">> := _}, <<"event_timestamp">> := _}
],
<<"task_status">> := <<"finished">>,
<<"task_type">> := <<"init">>
},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>}
] = json:decode(Body),
ok.

-spec unknown_test(config()) -> test_return().
unknown_test(_C) ->
ID = <<"unknown_id">>,
Expand Down
77 changes: 77 additions & 0 deletions apps/ff_server/test/ff_withdrawal_handler_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
-export([create_adjustment_already_has_status_error_test/1]).
-export([create_adjustment_already_has_data_revision_error_test/1]).
-export([withdrawal_state_content_test/1]).
-export([trace_withdrawal_test/1]).

-type config() :: ct_helper:config().
-type test_case_name() :: ct_helper:test_case_name().
Expand Down Expand Up @@ -283,6 +284,82 @@ create_withdrawal_ok_test(_C) ->
FinalWithdrawalState#wthd_WithdrawalState.status
).

-spec trace_withdrawal_test(config()) -> test_return().
trace_withdrawal_test(_C) ->
Cash = make_cash({1000, <<"RUB">>}),
Ctx = ct_objects:build_default_ctx(),
#{
party_id := PartyID,
wallet_id := WalletID,
destination_id := DestinationID
} = ct_objects:prepare_standard_environment(Ctx#{body => Cash}),
WithdrawalID = genlib:bsuuid(),
ExternalID = genlib:bsuuid(),
Context = ff_entity_context_codec:marshal(#{<<"NS">> => #{}}),
Metadata = ff_entity_context_codec:marshal(#{<<"metadata">> => #{<<"some key">> => <<"some data">>}}),
ContactInfo = #fistful_base_ContactInfo{
phone_number = <<"1234567890">>,
email = <<"test@mail.com">>
},
Params = #wthd_WithdrawalParams{
id = WithdrawalID,
party_id = PartyID,
wallet_id = WalletID,
destination_id = DestinationID,
body = Cash,
metadata = Metadata,
external_id = ExternalID,
contact_info = ContactInfo
},
{ok, _WithdrawalState} = call_withdrawal('Create', {Params, Context}),
succeeded = ct_objects:await_final_withdrawal_status(WithdrawalID),

TraceUrl = <<"http://localhost:8022/traces/internal/withdrawal_v2/", WithdrawalID/binary>>,
{ok, 200, _Headers, Ref} = hackney:get(TraceUrl),
{ok, Body} = hackney:body(Ref),
[
#{
<<"args">> := [
[
#{<<"created">> := _},
#{<<"status_changed">> := <<"pending">>},
#{<<"resource_got">> := #{<<"bank_card">> := _}}
],
#{<<"NS">> := #{}}
],
<<"error">> := null,
<<"events">> := [
#{<<"event_id">> := 1, <<"event_timestamp">> := _, <<"event_payload">> := #{<<"created">> := _}},
#{<<"event_id">> := 2, <<"event_timestamp">> := _, <<"event_payload">> := #{<<"status_changed">> := _}},
#{<<"event_id">> := 3, <<"event_timestamp">> := _, <<"event_payload">> := #{<<"resource_got">> := _}}
],
<<"finished">> := _,
<<"otel_trace_id">> := _,
<<"retry_attempts">> := _,
<<"retry_interval">> := _,
<<"running">> := _,
<<"scheduled">> := _,
<<"task_id">> := _,
<<"task_metadata">> := #{<<"range">> := #{}},
<<"task_status">> := <<"finished">>,
<<"task_type">> := <<"init">>
},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{
<<"args">> := #{<<"notify">> := [<<"session_finished">> | _]},
<<"task_status">> := <<"finished">>,
<<"task_type">> := <<"call">>
},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>},
#{<<"task_status">> := <<"finished">>, <<"task_type">> := <<"timeout">>}
] = json:decode(Body),
ok.

-spec create_withdrawal_fail_email_test(config()) -> test_return().
create_withdrawal_fail_email_test(_C) ->
Cash = make_cash({1000, <<"RUB">>}),
Expand Down
Loading
Loading