mirror of
https://github.com/valitydev/wapi-lib.git
synced 2024-11-06 18:25:17 +00:00
110be44152
* added bouncer context * finished refactor wallet handler * fixed build * fixed dialyzer * finished fixed dialyzer * added fixes + setup tests * fixed more errors * fixed process return * fixed auth wapi context * setuped some suites * fixed all tests * fixed dialyzer * formatted * fixed linter * fixed * updated bouncer proto and client, fixed
133 lines
3.9 KiB
Erlang
133 lines
3.9 KiB
Erlang
-module(wapi_residence_tests_SUITE).
|
|
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
-include_lib("jose/include/jose_jwk.hrl").
|
|
-include_lib("wapi_wallet_dummy_data.hrl").
|
|
|
|
-export([all/0]).
|
|
-export([groups/0]).
|
|
-export([init_per_suite/1]).
|
|
-export([end_per_suite/1]).
|
|
-export([init_per_group/2]).
|
|
-export([end_per_group/2]).
|
|
-export([init_per_testcase/2]).
|
|
-export([end_per_testcase/2]).
|
|
|
|
-export([init/1]).
|
|
|
|
-export([
|
|
get_residence_ok/1,
|
|
get_residence_fail_notfound/1
|
|
]).
|
|
|
|
% common-api is used since it is the domain used in production RN
|
|
% TODO: change to wallet-api (or just omit since it is the default one) when new tokens will be a thing
|
|
-define(DOMAIN, <<"common-api">>).
|
|
-define(badresp(Code), {error, {invalid_response_code, Code}}).
|
|
-define(emptyresp(Code), {error, {Code, #{}}}).
|
|
|
|
-type test_case_name() :: atom().
|
|
-type config() :: [{atom(), any()}].
|
|
-type group_name() :: atom().
|
|
|
|
-behaviour(supervisor).
|
|
|
|
-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
|
|
init([]) ->
|
|
{ok, {#{strategy => one_for_all, intensity => 1, period => 1}, []}}.
|
|
|
|
-spec all() -> [{group, test_case_name()}].
|
|
all() ->
|
|
[
|
|
{group, base}
|
|
].
|
|
|
|
-spec groups() -> [{group_name(), list(), [test_case_name()]}].
|
|
groups() ->
|
|
[
|
|
{base, [], [
|
|
get_residence_ok,
|
|
get_residence_fail_notfound
|
|
]}
|
|
].
|
|
|
|
%%
|
|
%% starting/stopping
|
|
%%
|
|
-spec init_per_suite(config()) -> config().
|
|
init_per_suite(C) ->
|
|
wapi_ct_helper:init_suite(?MODULE, C).
|
|
|
|
-spec end_per_suite(config()) -> _.
|
|
end_per_suite(C) ->
|
|
_ = wapi_ct_helper:stop_mocked_service_sup(?config(suite_test_sup, C)),
|
|
_ = [application:stop(App) || App <- ?config(apps, C)],
|
|
ok.
|
|
|
|
-spec init_per_group(group_name(), config()) -> config().
|
|
init_per_group(Group, Config) when Group =:= base ->
|
|
ok = wapi_context:save(
|
|
wapi_context:create(#{
|
|
woody_context => woody_context:new(<<"init_per_group/", (atom_to_binary(Group, utf8))/binary>>)
|
|
})
|
|
),
|
|
Party = genlib:bsuuid(),
|
|
{ok, Token} = wapi_ct_helper:issue_token(Party, [{[party], write}], unlimited, ?DOMAIN),
|
|
Config1 = [{party, Party} | Config],
|
|
[{context, wapi_ct_helper:get_context(Token)} | Config1];
|
|
init_per_group(_, Config) ->
|
|
Config.
|
|
|
|
-spec end_per_group(group_name(), config()) -> _.
|
|
end_per_group(_Group, _C) ->
|
|
ok.
|
|
|
|
-spec init_per_testcase(test_case_name(), config()) -> config().
|
|
init_per_testcase(Name, C) ->
|
|
C1 = wapi_ct_helper:makeup_cfg([wapi_ct_helper:test_case_name(Name), wapi_ct_helper:woody_ctx()], C),
|
|
ok = wapi_context:save(C1),
|
|
[{test_sup, wapi_ct_helper:start_mocked_service_sup(?MODULE)} | C1].
|
|
|
|
-spec end_per_testcase(test_case_name(), config()) -> config().
|
|
end_per_testcase(_Name, C) ->
|
|
ok = wapi_context:cleanup(),
|
|
_ = wapi_ct_helper:stop_mocked_service_sup(?config(test_sup, C)),
|
|
ok.
|
|
|
|
%%% Tests
|
|
|
|
-spec get_residence_ok(config()) -> _.
|
|
get_residence_ok(C) ->
|
|
_ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetResidence">>, C),
|
|
{ok, _} = call_api(
|
|
fun swag_client_wallet_residences_api:get_residence/3,
|
|
#{
|
|
binding => #{
|
|
<<"residence">> => <<"RUS">>
|
|
}
|
|
},
|
|
wapi_ct_helper:cfg(context, C)
|
|
).
|
|
|
|
-spec get_residence_fail_notfound(config()) -> _.
|
|
get_residence_fail_notfound(C) ->
|
|
_ = wapi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetResidence">>, C),
|
|
{error, {404, #{}}} = call_api(
|
|
fun swag_client_wallet_residences_api:get_residence/3,
|
|
#{
|
|
binding => #{
|
|
<<"residence">> => <<"ENG">>
|
|
}
|
|
},
|
|
wapi_ct_helper:cfg(context, C)
|
|
).
|
|
|
|
%%
|
|
|
|
-spec call_api(function(), map(), wapi_client_lib:context()) -> {ok, term()} | {error, term()}.
|
|
call_api(F, Params, Context) ->
|
|
{Url, PreparedParams, Opts} = wapi_client_lib:make_request(Context, Params),
|
|
Response = F(Url, PreparedParams, Opts),
|
|
wapi_client_lib:handle_response(Response).
|