-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ct tests, fix sf_client_config_sf_rest_api_test tests and i…
…mprove sf_client_access_token_server handling
- Loading branch information
1 parent
1079caa
commit 5ade238
Showing
7 changed files
with
286 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @author David Robakowski | ||
%%% @copyright (C) 2017, Synlay Technologies UG & Co. KG | ||
%%% @doc | ||
%%% | ||
%%% @end | ||
%%% Created : 21. Jan 2017 12:26 | ||
%%%------------------------------------------------------------------- | ||
-module(sf_client_SUITE). | ||
-author("David Robakowski"). | ||
|
||
-define(MAPPING_KEY, sf_client_config_eunit_lib). | ||
-define(RESTC_ERR_RESPONSE(ExpectedStatusCode, Header, Body), {error, ExpectedStatusCode, Header, Body}). | ||
|
||
|
||
-export([ | ||
all/0 | ||
,init_per_testcase/2 | ||
,end_per_testcase/2 | ||
,proper_integration_test/1 | ||
,credentials_changed/1 | ||
]). | ||
|
||
-include_lib("common_test/include/ct.hrl"). | ||
-include_lib("proper/include/proper.hrl"). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
|
||
%%all() -> []. | ||
%%all() -> [proper_integration_test, credentials_changed]. | ||
all() -> [proper_integration_test]. | ||
%%all() -> [credentials_changed]. | ||
|
||
|
||
init_per_testcase(_TestCase, Config) -> | ||
ok = sf_client_config_eunit_lib:setup(), | ||
Config. | ||
|
||
|
||
end_per_testcase(_TestCase, Config) -> | ||
sf_client_config_eunit_lib:teardown(Config). | ||
|
||
|
||
proper_integration_test(_Config) -> | ||
NumTests = list_to_integer(os:getenv("NUMTESTS", "100")), | ||
?assert(proper:quickcheck(integration_test(), [{numtests, NumTests}])). | ||
|
||
|
||
integration_test() -> | ||
?FORALL({Model1, Model2}, ?SUCHTHAT({Model1, Model2}, {sf_client:model(), sf_client:model()}, Model1 /= Model2), | ||
|
||
?WHENFAIL(ct:pal("intgration test failes with the following models:~n~p~n~n~p~n", [Model1, Model2]), | ||
begin | ||
InternalModelId = make_ref(), | ||
{ok, ID} = sf_client:create(?MAPPING_KEY, {InternalModelId, Model1}), | ||
{ok, ID} = sf_client:get_sobject_id_by_model(?MAPPING_KEY, {InternalModelId, Model1}), | ||
ok = sf_client:update(?MAPPING_KEY, ID, {InternalModelId, Model2}), | ||
{ok, ID} = sf_client:get_sobject_id_by_model(?MAPPING_KEY, {InternalModelId, Model2}), | ||
ok = sf_client:delete(?MAPPING_KEY, ID), | ||
{error, not_found} = sf_client:get_sobject_id_by_model(?MAPPING_KEY, {InternalModelId, Model1}), | ||
{error, not_found} = sf_client:get_sobject_id_by_model(?MAPPING_KEY, {InternalModelId, Model2}), | ||
true | ||
end)). | ||
|
||
|
||
credentials_changed(_Config) -> | ||
Model1 = <<>>, | ||
Model2 = <<>>, | ||
|
||
InternalModelId = make_ref(), | ||
{ok, _ID} = sf_client:create(?MAPPING_KEY, {InternalModelId, Model1}), | ||
|
||
meck:expect(restc, request, fun | ||
(post, json, "https://localhost/services/oauth2/token?grant_type=" ++ _, [200], [], []) -> | ||
?RESTC_ERR_RESPONSE(401, [], #{ | ||
<<"error">> => <<"invalid_grant">> | ||
}); | ||
|
||
%% Create a new resource => sf_client:create... | ||
(post, json, <<"https://localhost/services/data/v39.0/sobjects/MOCK_sobject_table_name">>, [201], | ||
[{<<"Authorization">>,<<"Bearer ACCESS_TOKEN">>}], _DbModel) -> | ||
?RESTC_ERR_RESPONSE(401, [], #{ | ||
<<"error">> => <<"invalid_grant">> | ||
}) | ||
end), | ||
|
||
InternalModel2Id = make_ref(), | ||
{error, max_retries} = sf_client:create(?MAPPING_KEY, {InternalModel2Id, Model2}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @author David Robakowski | ||
%%% @copyright (C) 2017, Synlay Technologies UG & Co. KG | ||
%%% @doc | ||
%%% | ||
%%% @end | ||
%%% Created : 21. Jan 2017 14:23 | ||
%%%------------------------------------------------------------------- | ||
-module(sf_client_access_token_server_SUITE). | ||
-author("David Robakowski"). | ||
|
||
-define(RESTC_ERR_RESPONSE(ExpectedStatusCode, Header, Body), {error, ExpectedStatusCode, Header, Body}). | ||
|
||
-export([ | ||
all/0 | ||
,init_per_testcase/2 | ||
,end_per_testcase/2 | ||
%% ,init_per_suite/1 | ||
%% ,end_per_suite/1 | ||
,integration_test/1 | ||
,token_expired/1 | ||
,invalid_credentials/1 | ||
]). | ||
|
||
-include_lib("common_test/include/ct.hrl"). | ||
-include_lib("proper/include/proper.hrl"). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
|
||
%%all() -> [integration_test, token_expired, invalid_credentials]. | ||
all() -> [integration_test, token_expired]. | ||
%%all() -> [integration_test]. | ||
%%all() -> [token_expired_test]. | ||
|
||
|
||
init_per_testcase(_TestCase, Config) -> | ||
AccessToken = term_to_binary(make_ref()), | ||
ok = sf_client_config_eunit_lib:setup(AccessToken), | ||
[{access_token, AccessToken} | Config]. | ||
|
||
|
||
end_per_testcase(_TestCase, Config) -> | ||
sf_client_config_eunit_lib:teardown(Config). | ||
|
||
|
||
integration_test(Config) -> | ||
AccessToken = ?config(access_token, Config), | ||
{ok, AccessToken} = sf_client_access_token_server:get_server_access_token(), | ||
NewAccessToken = term_to_binary(make_ref()), | ||
sf_client_config_eunit_lib:mock_access_token_request_success(NewAccessToken), | ||
{ok, NewAccessToken} = sf_client_access_token_server:reasign_server_access_token(), | ||
{ok, NewAccessToken} = sf_client_access_token_server:get_server_access_token(). | ||
|
||
|
||
token_expired(_Config) -> | ||
AccessToken = term_to_binary(make_ref()), | ||
sf_client_config_eunit_lib:mock_access_token_request_success(AccessToken), | ||
meck:expect(sf_client_config, get_access_token_expiry, fun() -> | ||
501 | ||
end), | ||
{ok, AccessToken} = sf_client_access_token_server:reasign_server_access_token(), | ||
NewAccessToken = term_to_binary(make_ref()), | ||
sf_client_config_eunit_lib:mock_access_token_request_success(NewAccessToken), | ||
catch timer:sleep(1000), | ||
{ok, NewAccessToken} = sf_client_access_token_server:get_server_access_token(). | ||
|
||
|
||
invalid_credentials(_Config) -> | ||
meck:expect(restc, request, fun | ||
(post, json, "https://localhost/services/oauth2/token?grant_type=" ++ _, [200], [], []) -> | ||
?RESTC_ERR_RESPONSE(401, [], #{ | ||
<<"error">> => <<"invalid_grant">> | ||
}) | ||
end), | ||
|
||
{error, bla} = sf_client_access_token_server:reasign_server_access_token(). |
Oops, something went wrong.