CAPI-32 Change event responses and modify tests for satisfy the newes… (#15)

* CAPI-32 Change event responses and modify tests for satisfy the newest images and swag
This commit is contained in:
Artem Ocheredko 2016-10-21 13:35:43 +03:00 committed by GitHub
parent ea96fdd2f5
commit 730ad23d13
8 changed files with 239 additions and 122 deletions

View File

@ -1,6 +1,6 @@
{application, capi , [
{description, "A service that does something"},
{vsn, "1"},
{vsn, "0.1.0"},
{registered, []},
{mod, { capi , []}},
{applications, [

View File

@ -114,7 +114,7 @@ get_actions() ->
'GetPaymentRevenueStats' => [<<"payments_revenue_stats:get">>],
'GetPaymentGeoStats' => [<<"payments_geo_stats:get">>],
'GetPaymentRateStats' => [<<"payments_rate_stats:get">>],
'GetPaymentInstrumentStats' => [<<"payments_instrument_stats:get">>],
'GetPaymentMethodStats' => [<<"payments_instrument_stats:get">>],
'GetMyParty' => [<<"party:get">>, <<"party:create">>],
'ActivateShop' => [<<"shops:activate">>, <<"party:create">>],
'CreateShop' => [<<"shop:create">>, <<"party:create">>],

View File

@ -392,11 +392,11 @@ process_request(OperationID = 'GetPaymentRateStats', Req, Context) ->
process_request_error(OperationID, Error)
end;
process_request(OperationID = 'GetPaymentInstrumentStats', Req, Context) ->
process_request(OperationID = 'GetPaymentMethodStats', Req, Context) ->
RequestID = maps:get('X-Request-ID', Req),
case maps:get(paymentInstrument, Req) of
<<"card">> ->
StatType = payments_card_stat,
case maps:get(paymentMethod, Req) of
bank_card ->
StatType = payments_pmt_cards_stat,
Result = call_merchant_stat(StatType, Req, Context, RequestID),
case Result of
{ok, #merchstat_StatResponse{data = {'records', Stats}}} ->
@ -938,7 +938,7 @@ decode_payment_event(_, {
invoice_payment_status_changed,
#'payproc_InvoicePaymentStatusChanged'{payment_id = PaymentID, status = {Status, _}}
}) ->
{<<"paymentStatusChanged">>, #{
{<<"EventPaymentStatusChanged">>, #{
<<"paymentID">> => PaymentID,
<<"status">> => genlib:to_binary(Status)
}}.
@ -1131,8 +1131,9 @@ decode_stat_response(customers_rate_stat, Response) ->
<<"uniqueCount">> => genlib:to_int(maps:get(<<"unic_count">>, Response))
};
decode_stat_response(payments_card_stat, Response) ->
decode_stat_response(payments_pmt_cards_stat, Response) ->
#{
<<"statType">> => <<"PaymentMethodBankCardStat">>, %% @TODO deal with nested responses decoding
<<"offset">> => genlib:to_int(maps:get(<<"offset">>, Response)),
<<"totalCount">> => genlib:to_int(maps:get(<<"total_count">>, Response)),
<<"paymentSystem">> => maps:get(<<"payment_system">>, Response),
@ -1295,7 +1296,7 @@ decode_shop_account_state(#payproc_ShopAccountState{
decode_user_interaction({redirect, BrowserRequest}) ->
#{
<<"interactionType">> => <<"redirect">>,
<<"interactionType">> => <<"Redirect">>,
<<"request">> => decode_browser_request(BrowserRequest)
}.
@ -1303,7 +1304,7 @@ decode_browser_request({get_request, #'BrowserGetRequest'{
uri = UriTemplate
}}) ->
#{
<<"requestType">> => <<"browserGetRequest">>,
<<"requestType">> => <<"BrowserGetRequest">>,
<<"uriTemplate">> => UriTemplate
};
@ -1312,7 +1313,7 @@ decode_browser_request({post_request, #'BrowserPostRequest'{
form = UserInteractionForm
}}) ->
#{
<<"requestType">> => <<"browserPostRequest">>,
<<"requestType">> => <<"BrowserPostRequest">>,
<<"uriTemplate">> => UriTemplate,
<<"form">> => decode_user_interaction_form(UserInteractionForm)
}.
@ -1473,4 +1474,3 @@ create_party(Context, RequestContext) ->
Error
end,
{R, NewRequestContext}.

View File

@ -9,6 +9,8 @@
-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/1]).
@ -29,6 +31,7 @@
get_payment_revenue_stats_ok_test/1,
get_payment_geo_stats_ok_test/1,
get_payment_rate_stats_ok_test/1,
get_payment_method_stats_ok_test/1,
%%%%
get_my_party_ok_test/1,
suspend_my_party_ok_test/1,
@ -53,7 +56,7 @@
-define(CAPI_SERVICE_TYPE, real).
-define(CAPI_CDS_STORAGE_URL, "http://cds:8022/v1/storage").
-define(CAPI_INVOICING_URL, "http://hellgate:8022/v1/processing/invoicing").
-define(CAPI_MERCHANT_STAT_URL, "http://magista:8082/stat").
-define(CAPI_MERCHANT_STAT_URL, "http://magista:8022/stat").
-define(CAPI_PARTY_MANAGEMENT_URL, "http://hellgate:8022/v1/processing/partymgmt").
-define(CAPI_REPOSITORY_URL, "http://dominant:8022/v1/domain/repository").
@ -112,7 +115,8 @@ groups() ->
get_payment_conversion_stats_ok_test,
get_payment_revenue_stats_ok_test,
get_payment_geo_stats_ok_test,
get_payment_rate_stats_ok_test
get_payment_rate_stats_ok_test,
get_payment_method_stats_ok_test
]},
{party_management, [sequence], [
get_my_party_ok_test,
@ -177,8 +181,23 @@ init_per_suite(Config) ->
end_per_suite(C) ->
_ = unlink(?config(test_sup, C)),
exit(?config(test_sup, C), shutdown),
ok = cleanup(),
[application:stop(App) || App <- proplists:get_value(apps, C)].
-spec init_per_group(Name :: atom(), config()) -> config().
init_per_group(statistics, Config) ->
ShopID = create_and_activate_shop(Config),
[{shop_id, ShopID} | Config];
init_per_group(_, Config) ->
Config.
-spec end_per_group(Name :: atom(), config()) -> config().
end_per_group(_, Config) ->
Config.
%% tests
-spec authorization_error_no_header_test(config()) -> _.
@ -262,18 +281,22 @@ get_payment_by_id_ok_test(Config) ->
-spec get_invoices_stats_ok_test(config()) -> _.
get_invoices_stats_ok_test(Config) ->
ShopID = ?config(shop_id, Config),
Qs = qs([
{<<"limit">>, <<"2">>},
{<<"offset">>, <<"0">>},
{<<"fromTime">>, <<"2015-08-11T19:42:35Z">>},
{<<"toTime">>, <<"2020-08-11T19:42:35Z">>}
]),
Path = "/v1/analytics/shops/THRIFT-SHOP/invoices?" ++ Qs,
Path = "/v1/analytics/shops/" ++ genlib:to_list(ShopID) ++ "/invoices?" ++ Qs,
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_payment_conversion_stats_ok_test(config()) -> _.
get_payment_conversion_stats_ok_test(Config) ->
ShopID = ?config(shop_id, Config),
Qs = qs([
{<<"splitUnit">>, <<"minute">>},
{<<"splitSize">>, <<"1">>},
@ -282,12 +305,14 @@ get_payment_conversion_stats_ok_test(Config) ->
{<<"fromTime">>, <<"2015-08-11T19:42:35Z">>},
{<<"toTime">>, <<"2020-08-11T19:42:35Z">>}
]),
Path = "/v1/analytics/shops/THRIFT-SHOP/payments/stats/conversion?" ++ Qs,
Path = "/v1/analytics/shops/" ++ genlib:to_list(ShopID) ++ "/payments/stats/conversion?" ++ Qs,
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_payment_revenue_stats_ok_test(config()) -> _.
get_payment_revenue_stats_ok_test(Config) ->
ShopID = ?config(shop_id, Config),
Qs = qs([
{<<"splitUnit">>, <<"minute">>},
{<<"splitSize">>, <<"1">>},
@ -296,12 +321,14 @@ get_payment_revenue_stats_ok_test(Config) ->
{<<"fromTime">>, <<"2015-08-11T19:42:35Z">>},
{<<"toTime">>, <<"2020-08-11T19:42:35Z">>}
]),
Path = "/v1/analytics/shops/THRIFT-SHOP/payments/stats/revenue?" ++ Qs,
Path = "/v1/analytics/shops/" ++ genlib:to_list(ShopID) ++ "/payments/stats/revenue?" ++ Qs,
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_payment_geo_stats_ok_test(config()) -> _.
get_payment_geo_stats_ok_test(Config) ->
ShopID = ?config(shop_id, Config),
Qs = qs([
{<<"splitUnit">>, <<"minute">>},
{<<"splitSize">>, <<"1">>},
@ -310,12 +337,14 @@ get_payment_geo_stats_ok_test(Config) ->
{<<"fromTime">>, <<"2015-08-11T19:42:35Z">>},
{<<"toTime">>, <<"2020-08-11T19:42:35Z">>}
]),
Path = "/v1/analytics/shops/THRIFT-SHOP/payments/stats/geo?" ++ Qs,
Path = "/v1/analytics/shops/" ++ genlib:to_list(ShopID) ++ "/payments/stats/geo?" ++ Qs,
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_payment_rate_stats_ok_test(config()) -> _.
get_payment_rate_stats_ok_test(Config) ->
ShopID = ?config(shop_id, Config),
Qs = qs([
{<<"splitUnit">>, <<"minute">>},
{<<"splitSize">>, <<"1">>},
@ -324,7 +353,25 @@ get_payment_rate_stats_ok_test(Config) ->
{<<"fromTime">>, <<"2015-08-11T19:42:35Z">>},
{<<"toTime">>, <<"2020-08-11T19:42:35Z">>}
]),
Path = "/v1/analytics/shops/THRIFT-SHOP/customers/stats/rate?" ++ Qs,
Path = "/v1/analytics/shops/" ++ genlib:to_list(ShopID) ++ "/customers/stats/rate?" ++ Qs,
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_payment_method_stats_ok_test(config()) -> _.
get_payment_method_stats_ok_test(Config) ->
ShopID = ?config(shop_id, Config),
Qs = qs([
{<<"paymentMethod">>, <<"bank_card">>},
{<<"splitUnit">>, <<"minute">>},
{<<"splitSize">>, <<"1">>},
{<<"limit">>, <<"2">>},
{<<"offset">>, <<"0">>},
{<<"fromTime">>, <<"2015-08-11T19:42:35Z">>},
{<<"toTime">>, <<"2020-08-11T19:42:35Z">>}
]),
Path = "/v1/analytics/shops/" ++ genlib:to_list(ShopID) ++ "/customers/stats/payment_method?" ++ Qs,
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_my_party_ok_test(config()) -> _.
@ -762,9 +809,32 @@ default_approve_claim(ClaimID) ->
create_context()
).
-define(cur(ID), #domain_CurrencyRef{symbolic_code = ID}).
-define(pmt(C, T), #domain_PaymentMethodRef{id = {C, T}}).
-define(cat(ID), #domain_CategoryRef{id = ID}).
-define(prx(ID), #domain_ProxyRef{id = ID}).
-define(prv(ID), #domain_ProviderRef{id = ID}).
-define(trm(ID), #domain_TerminalRef{id = ID}).
-define(pst(ID), #domain_PaymentsServiceTermsRef{id = ID}).
-define(trmacc(Cur, Rec, Com),
#domain_TerminalAccountSet{currency = ?cur(Cur), receipt = Rec, compensation = Com}).
-define(cfpost(S, A1, D, A2, V),
#domain_CashFlowPosting{
source = #domain_CashFlowAccount{party = S, designation = genlib:to_binary(A1)},
destination = #domain_CashFlowAccount{party = D, designation = genlib:to_binary(A2)},
volume = V
}
).
-define(fixed(A),
{fixed, #domain_CashVolumeFixed{amount = A}}).
-define(share(P, Q, C),
{share, #domain_CashVolumeShare{parts = #'Rational'{p = P, q = Q}, 'of' = C}}).
populate_snapshot(ProxyUrl) ->
CategoryRefID = rand:uniform(10000),
CurrencySymbolicCode = <<"RUB">>,
{{ok, #'Snapshot'{version = Version}}, Context0} = cp_proto:call_service_safe(
repository,
'Checkout',
@ -773,91 +843,9 @@ populate_snapshot(ProxyUrl) ->
),
Ops = [
{'insert', #'InsertOp'{
object = {
party_prototype,
#domain_PartyPrototypeObject{
ref = #domain_PartyPrototypeRef{
id = 42
},
data = #domain_PartyPrototype{
shop = #domain_ShopPrototype{
category = #domain_CategoryRef{
id = CategoryRefID
},
details = #domain_ShopDetails{
name = <<"DefaultShopName">>
},
currency = #domain_CurrencyRef{
symbolic_code = CurrencySymbolicCode
}
},
default_services = #domain_ShopServices{}
}
}
}
}},
{'insert', #'InsertOp'{
object = {
category,
#domain_CategoryObject{
ref = #domain_CategoryRef{
id = CategoryRefID
},
data = #domain_Category{
name = genlib:unique()
}
}
}
}},
{'insert', #'InsertOp'{
object = {
currency,
#domain_CurrencyObject{
ref = #domain_CurrencyRef{symbolic_code = <<"RUB">>},
data = #domain_Currency{
name = <<"Russian rubles">>,
numeric_code = 643,
symbolic_code = CurrencySymbolicCode,
exponent = 2
}
}
}
}},
{'insert', #'InsertOp'{
object = {
globals,
#domain_GlobalsObject{
ref = #domain_GlobalsRef{},
data = #domain_Globals{
party_prototype = #domain_PartyPrototypeRef{
id = 42
},
providers = {
predicates,
ordsets:new()
},
system_accounts = {
predicates,
ordsets:new()
}
}
}
}
}},
{'insert', #'InsertOp'{
object = {
proxy,
#'domain_ProxyObject'{
ref = #'domain_ProxyRef'{
id = 1
},
data = #'domain_ProxyDefinition'{
url = ProxyUrl,
options = #{}
}
}
}
object = O
}}
|| O <- get_domain_fixture(ProxyUrl)
],
Commit = #'Commit'{
ops = Ops
@ -872,6 +860,116 @@ populate_snapshot(ProxyUrl) ->
timer:sleep(8000).
get_domain_fixture(ProxyUrl) ->
[
{globals, #domain_GlobalsObject{
ref = #domain_GlobalsRef{},
data = #domain_Globals{
party_prototype = #domain_PartyPrototypeRef{id = 42},
providers = {value, [?prv(1)]},
system_accounts = {predicates, []}
}
}},
{party_prototype, #domain_PartyPrototypeObject{
ref = #domain_PartyPrototypeRef{id = 42},
data = #domain_PartyPrototype{
shop = #domain_ShopPrototype{
category = ?cat(1),
currency = ?cur(<<"RUB">>),
details = #domain_ShopDetails{
name = <<"SUPER DEFAULT SHOP">>
}
},
default_services = #domain_ShopServices{
payments = #domain_PaymentsService{
domain_revision = 0,
terms = ?pst(1)
}
}
}
}},
{payments_service_terms, #domain_PaymentsServiceTermsObject{
ref = ?pst(1),
data = #domain_PaymentsServiceTerms{
payment_methods = {value, ordsets:from_list([
?pmt(bank_card, visa),
?pmt(bank_card, mastercard)
])},
limits = {predicates, [
#domain_AmountLimitPredicate{
if_ = {condition, {currency_is, ?cur(<<"RUB">>)}},
then_ = {value, #domain_AmountLimit{
min = {inclusive, 1000},
max = {exclusive, 4200000}
}}
}
]},
fees = {predicates, [
#domain_CashFlowPredicate{
if_ = {condition, {currency_is, ?cur(<<"RUB">>)}},
then_ = {value, [
?cfpost(merchant, general, system, compensation, ?share(45, 1000, payment_amount))
]}
}
]}
}
}},
{currency, #domain_CurrencyObject{
ref = ?cur(<<"RUB">>),
data = #domain_Currency{
name = <<"Russian rubles">>,
numeric_code = 643,
symbolic_code = <<"RUB">>,
exponent = 2
}
}},
{category, #domain_CategoryObject{
ref = ?cat(1),
data = #domain_Category{
name = <<"Categories">>,
description = <<"Goods sold by category providers">>
}
}},
{provider, #domain_ProviderObject{
ref = ?prv(1),
data = #domain_Provider{
name = <<"Brovider">>,
description = <<"A provider but bro">>,
terminal = {value, [?trm(1)]},
proxy = #domain_Proxy{
ref = ?prx(1),
additional = #{
<<"override">> => <<"brovider">>
}
}
}
}},
{terminal, #domain_TerminalObject{
ref = ?trm(1),
data = #domain_Terminal{
name = <<"Brominal 1">>,
description = <<"Brominal 1">>,
payment_method = #domain_PaymentMethodRef{id = {bank_card, visa}},
category = ?cat(1),
cash_flow = [
?cfpost(provider, receipt, merchant, general, ?share(1, 1, payment_amount)),
?cfpost(system, compensation, provider, compensation, ?share(18, 1000, payment_amount))
],
accounts = ?trmacc(<<"RUB">>, 10001, 10002),
options = #{
<<"override">> => <<"Brominal 1">>
}
}
}},
{proxy, #domain_ProxyObject{
ref = ?prx(1),
data = #domain_ProxyDefinition{
url = ProxyUrl,
options = #{}
}
}}
].
default_get_shop_accounts(ShopID, Config) ->
Path = "/v1/processing/shops/" ++ genlib:to_list(ShopID) ++ "/accounts",
{ok, 200, _RespHeaders, Body} = default_call(get, Path, #{}, Config),
@ -938,3 +1036,26 @@ start_service_handler(Module, C) ->
get_random_port() ->
rand:uniform(32768) + 32767.
cleanup() ->
{{ok, #'Snapshot'{domain = Domain, version = Version}}, Context0} = cp_proto:call_service_safe(
repository,
'Checkout',
[{head, #'Head'{}}],
create_context()
),
Commit = #'Commit'{
ops = [
{remove, #'RemoveOp'{
object = Object
}} ||
Object <- maps:values(Domain)
]
},
{{ok, _Version}, _} = cp_proto:call_service_safe(
repository,
'Commit',
[Version, Commit],
Context0
),
ok.

@ -1 +1 @@
Subproject commit 29d6caf9d1ef8b790f9b2fead6ee878f5656fe0c
Subproject commit 7a56dfce898cbc4c989f5d900ef3e50e0b8c2977

View File

@ -24,7 +24,7 @@
{service_urls, #{
invoicing => "http://hellgate:8022/v1/processing/invoicing",
cds_storage => "http://cds:8022/v1/storage",
merchant_stat => "http://magista:8082/stat",
merchant_stat => "http://magista:8022/stat",
party_management => "http://hellgate:8022/v1/processing/partymgmt",
repository => "http://dominant:8022/v1/domain/repository"
}}

View File

@ -21,37 +21,31 @@ services:
- SERVICE_NAME=capi
hellgate:
image: dr.rbkmoney.com/rbkmoney/hellgate:746b2c8f6d5b51397c19c89a557de34287139ec0
image: dr.rbkmoney.com/rbkmoney/hellgate:235513c47205ed190d3276fdb2c7948893b57cbd
restart: always
command: /opt/hellgate/bin/hellgate foreground
depends_on:
- machinegun
- shumway
environment:
- SERVICE_NAME=hellgate
cds:
image: dr.rbkmoney.com/rbkmoney/cds:dbbf05f7bcdb39a85ca12d290aeecea1bada89d1
image: dr.rbkmoney.com/rbkmoney/cds:fe3751a508600af87e67cc5add133d178a403fd6
restart: always
command: /opt/cds/bin/cds foreground
environment:
- SERVICE_NAME=cds
machinegun:
image: dr.rbkmoney.com/rbkmoney/machinegun:a48f9e93dd5a709d5f14db0c9785d43039282e86
restart: always
command: /opt/machinegun/bin/machinegun foreground
volumes:
- ./test/machinegun/sys.config:/opt/machinegun/releases/0.1.0/sys.config
environment:
- SERVICE_NAME=machinegun
magista:
image: dr.rbkmoney.com/rbkmoney/magista:b18a1b11388238775d9bc330b9b89bc425ca735d
image: dr.rbkmoney.com/rbkmoney/magista:bf7c71a9e8d7c25c901894d5fe705dc0f2efbdaa
restart: always
command: |
java
-Xmx512m
-jar /opt/magista/magista-1.0.4.jar
-jar /opt/magista/magista.jar
--db.jdbc.url=jdbc:postgresql://magista-db:5432/magista
--db.username=postgres
--db.password=postgres
@ -71,7 +65,7 @@ services:
- SERVICE_NAME=magista-db
bustermaze:
image: dr.rbkmoney.com/rbkmoney/bustermaze:dd60a565671e34ff743218e6cb52f07e5ce632ea
image: dr.rbkmoney.com/rbkmoney/bustermaze:c50c584f3f2fcc6edb226712b2d241e237121ead
restart: always
command: |
-Xmx512m
@ -80,6 +74,10 @@ services:
--spring.datasource.username=postgres
--spring.datasource.password=postgres
--hg.pooling.url=http://hellgate:8022/v1/processing/eventsink
--flyway.url=jdbc:postgresql://bustermaze-db:5432/bustermaze
--flyway.user=postgres
--flyway.password=postgres
--flyway.schemas=bm
depends_on:
- hellgate
- bustermaze-db
@ -122,8 +120,6 @@ services:
command: /opt/dominant/bin/dominant foreground
depends_on:
- machinegun
environment:
- SERVICE_NAME=dominant
starter:
image: ${BUILD_IMAGE}

@ -1 +1 @@
Subproject commit e7255e40d3d8ae8bdc6833cd7002c7e2801b9995
Subproject commit 78917f0ae966089ff97e0d2ae4c720b965e64902