FIN-39: additional info support (#46)

* FIN-39: additional info support

* FT-39: coverage off

* FIN-39: fix issues

* FIN-39: fix effects

---------

Co-authored-by: ttt161 <losto@nix>
This commit is contained in:
ttt161 2024-07-01 15:02:46 +03:00 committed by GitHub
parent 6d0040df4a
commit 9af7d71577
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 291 additions and 31 deletions

View File

@ -30,12 +30,12 @@ jobs:
run:
name: Run checks
needs: setup
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.10
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.14
with:
otp-version: ${{ needs.setup.outputs.otp-version }}
rebar-version: ${{ needs.setup.outputs.rebar-version }}
use-thrift: true
thrift-version: ${{ needs.setup.outputs.thrift-version }}
run-ct-with-compose: true
use-coveralls: true
cache-version: v2
cache-version: v3
upload-coverage: false

View File

@ -171,6 +171,25 @@
)
).
%%% Additional info
-define(cm_additional_info_modification(PartyName, Comment, Emails),
{additional_info_modification, #claimmgmt_AdditionalInfoModificationUnit{
party_name = PartyName,
comment = Comment,
manager_contact_emails = Emails
}}
).
-define(cm_additional_info_party_name_modification(PartyName),
{additional_info_party_name_modification, PartyName}
).
-define(cm_additional_info_party_comment_modification(PartyComment),
{additional_info_party_comment_modification, PartyComment}
).
-define(cm_additional_info_emails_modification(Emails),
{additional_info_emails_modification, Emails}
).
%%% Error
-define(cm_invalid_party_changeset(Reason, InvalidChangeset), #claimmgmt_InvalidChangeset{

View File

@ -138,6 +138,28 @@
{wallet_effect, #payproc_WalletEffectUnit{id = ID, effect = Effect}}
).
-define(additional_info_modification(PartyName, Comment, Emails),
{additional_info_modification, #'payproc_AdditionalInfoModificationUnit'{
party_name = PartyName,
comment = Comment,
manager_contact_emails = Emails
}}
).
-define(pm_additional_info_party_name_modification(PartyName),
{additional_info_party_name_modification, PartyName}
).
-define(pm_additional_info_party_comment_modification(PartyComment),
{additional_info_party_comment_modification, PartyComment}
).
-define(pm_additional_info_emails_modification(Emails),
{additional_info_emails_modification, Emails}
).
-define(additional_info_effect(Effect),
{additional_info_effect, #payproc_AdditionalInfoEffectUnit{effect = Effect}}
).
-define(claim_created(Claim),
{claim_created, Claim}
).

View File

@ -215,23 +215,65 @@ make_effects(Timestamp, Revision, Claim) ->
make_changeset_effects(get_changeset(Claim), Timestamp, Revision).
make_changeset_effects(Changeset, Timestamp, Revision) ->
make_changeset_effects(Changeset, Timestamp, Revision, fun pm_claim_effect:make/3).
make_changeset_safe_effects(Changeset, Timestamp, Revision) ->
make_changeset_effects(Changeset, Timestamp, Revision, fun pm_claim_effect:make_safe/3).
make_changeset_effects(Changeset, Timestamp, Revision, Fun) ->
squash_effects(
lists:map(
fun(Change) ->
pm_claim_effect:make(Change, Timestamp, Revision)
lists:foldr(
fun
(?additional_info_modification(_PartyName, _Comment, _Emails) = Mod, Acc) ->
AdditionalInfoEffects = make_additional_info_effects(Mod, Timestamp, Revision, Fun),
AdditionalInfoEffects ++ Acc;
(Change, Acc) ->
[Fun(Change, Timestamp, Revision) | Acc]
end,
[],
Changeset
)
).
make_changeset_safe_effects(Changeset, Timestamp, Revision) ->
squash_effects(
lists:map(
fun(Change) ->
pm_claim_effect:make_safe(Change, Timestamp, Revision)
end,
Changeset
)
make_additional_info_effects(?additional_info_modification(PartyName, Comment, Emails), Timestamp, Revision, Fun) ->
AdditionalInfoMods = [
{party_name, PartyName},
{party_comment, Comment},
{emails, Emails}
],
make_additional_info_effects(AdditionalInfoMods, Timestamp, Revision, Fun, []).
make_additional_info_effects([], _Timestamp, _Revision, _Fun, Acc) ->
Acc;
make_additional_info_effects([{party_name, undefined} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(Tail, Timestamp, Revision, Fun, Acc);
make_additional_info_effects([{party_name, PartyName} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(
Tail,
Timestamp,
Revision,
Fun,
[Fun(?pm_additional_info_party_name_modification(PartyName), Timestamp, Revision) | Acc]
);
make_additional_info_effects([{party_comment, undefined} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(Tail, Timestamp, Revision, Fun, Acc);
make_additional_info_effects([{party_comment, Comment} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(
Tail,
Timestamp,
Revision,
Fun,
[Fun(?pm_additional_info_party_comment_modification(Comment), Timestamp, Revision) | Acc]
);
make_additional_info_effects([{emails, undefined} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(Tail, Timestamp, Revision, Fun, Acc);
make_additional_info_effects([{emails, Emails} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(
Tail,
Timestamp,
Revision,
Fun,
[Fun(?pm_additional_info_emails_modification(Emails), Timestamp, Revision) | Acc]
).
squash_effects(Effects) ->
@ -316,7 +358,9 @@ apply_claim_effect(?contract_effect(ID, Effect), Timestamp, Party) ->
apply_claim_effect(?shop_effect(ID, Effect), _, Party) ->
apply_shop_effect(ID, Effect, Party);
apply_claim_effect(?wallet_effect(ID, Effect), _, Party) ->
apply_wallet_effect(ID, Effect, Party).
apply_wallet_effect(ID, Effect, Party);
apply_claim_effect(?additional_info_effect(Effect), _, Party) ->
apply_additional_info_effect(Effect, Party).
apply_contractor_effect(_, {created, PartyContractor}, Party) ->
pm_party:set_contractor(PartyContractor, Party);
@ -403,6 +447,17 @@ update_wallet({account_created, Account}, Wallet) ->
raise_invalid_changeset(Reason) ->
throw(#payproc_InvalidChangeset{reason = Reason}).
apply_additional_info_effect({party_name, PartyName}, Party) ->
pm_party:set_party_name(PartyName, Party);
apply_additional_info_effect({party_comment, Comment}, Party) ->
pm_party:set_party_comment(Comment, Party);
apply_additional_info_effect({contact_info, #domain_PartyContactInfo{manager_contact_emails = Emails}}, Party) ->
ContactInfo = pm_party:get_contact_info(Party),
pm_party:set_contact_info(
ContactInfo#domain_PartyContactInfo{manager_contact_emails = Emails},
Party
).
%% Asserts
-spec assert_revision(claim(), claim_revision()) -> ok | no_return().
@ -422,6 +477,13 @@ assert_applicable(Claim, Timestamp, Revision, Party) ->
assert_changeset_applicable(get_changeset(Claim), Timestamp, Revision, Party).
-spec assert_changeset_applicable(changeset(), timestamp(), revision(), party()) -> ok | no_return().
assert_changeset_applicable(
[?additional_info_modification(_PartyName, _Comment, _Emails) | Others],
Timestamp,
Revision,
Party
) ->
assert_changeset_applicable(Others, Timestamp, Revision, Party);
assert_changeset_applicable([Change | Others], Timestamp, Revision, Party) ->
case Change of
?contract_modification(ID, Modification) ->

View File

@ -95,6 +95,13 @@ assert_modifications_applicable(
Party
) ->
assert_modifications_applicable(Others, Timestamp, Revision, Party);
assert_modifications_applicable(
[?cm_additional_info_modification(_PartyName, _Comment, _Emails) | Others],
Timestamp,
Revision,
Party
) ->
assert_modifications_applicable(Others, Timestamp, Revision, Party);
assert_modifications_applicable([PartyChange | Others], Timestamp, Revision, Party) ->
case PartyChange of
?cm_contract_modification(ID, Modification) ->

View File

@ -42,7 +42,13 @@ make(?cm_contract_modification(ID, Modification), Timestamp, Revision) ->
make(?cm_shop_modification(ID, Modification), Timestamp, Revision) ->
?shop_effect(ID, make_shop_effect(ID, Modification, Timestamp, Revision));
make(?cm_wallet_modification(ID, Modification), Timestamp, _Revision) ->
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp)).
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp));
make(?cm_additional_info_party_name_modification(PartyName), _Timestamp, _Revision) ->
?additional_info_effect(make_additional_info_effect(party_name, PartyName));
make(?cm_additional_info_party_comment_modification(Comment), _Timestamp, _Revision) ->
?additional_info_effect(make_additional_info_effect(party_comment, Comment));
make(?cm_additional_info_emails_modification(Emails), _Timestamp, _Revision) ->
?additional_info_effect(make_additional_info_effect(emails, Emails)).
%% NOTE Заглушка для пропуска фазы создания счетов для магазинов и кошельков на этапе проверки (Accept)
%% TODO Придумать имя получше/отрефакторить
@ -125,6 +131,16 @@ make_wallet_effect(ID, {creation, Params}, Timestamp) ->
make_wallet_effect(_, {account_creation, Params}, _) ->
{account_created, pm_wallet:create_account(Params)}.
make_additional_info_effect(party_name, PartyName) ->
{party_name, PartyName};
make_additional_info_effect(party_comment, Comment) ->
{party_comment, Comment};
make_additional_info_effect(emails, Emails) ->
{contact_info, #domain_PartyContactInfo{
manager_contact_emails = Emails,
registration_email = <<"ignored_value">>
}}.
assert_report_schedule_valid(_, #domain_ReportPreferences{service_acceptance_act_preferences = undefined}, _) ->
ok;
assert_report_schedule_valid(
@ -191,7 +207,9 @@ apply_claim_effect(?contract_effect(ID, Effect), Timestamp, Party) ->
apply_claim_effect(?shop_effect(ID, Effect), _, Party) ->
apply_shop_effect(ID, Effect, Party);
apply_claim_effect(?wallet_effect(ID, Effect), _, Party) ->
apply_wallet_effect(ID, Effect, Party).
apply_wallet_effect(ID, Effect, Party);
apply_claim_effect(?additional_info_effect(Effect), _, Party) ->
apply_additional_info_effect(Effect, Party).
apply_contractor_effect(_, {created, PartyContractor}, Party) ->
pm_party:set_contractor(PartyContractor, Party);
@ -271,6 +289,17 @@ apply_wallet_effect(ID, Effect, Party) ->
Wallet = pm_party:get_wallet(ID, Party),
pm_party:set_wallet(update_wallet(Effect, Wallet), Party).
apply_additional_info_effect({party_name, PartyName}, Party) ->
pm_party:set_party_name(PartyName, Party);
apply_additional_info_effect({party_comment, Comment}, Party) ->
pm_party:set_party_comment(Comment, Party);
apply_additional_info_effect({contact_info, #domain_PartyContactInfo{manager_contact_emails = Emails}}, Party) ->
ContactInfo = pm_party:get_contact_info(Party),
pm_party:set_contact_info(
ContactInfo#domain_PartyContactInfo{manager_contact_emails = Emails},
Party
).
update_wallet({account_created, Account}, Wallet) ->
Wallet#domain_Wallet{account = Account}.
@ -361,13 +390,58 @@ make_modifications_safe_effects(Modifications, Timestamp, Revision) ->
make_effects(Modifications, Timestamp, Revision, Fun) ->
squash_effects(
lists:filtermap(
lists:foldr(
fun
(?cm_shop_cash_register_modification_unit(_, _)) ->
false;
(Change) ->
{true, Fun(Change, Timestamp, Revision)}
(?cm_shop_cash_register_modification_unit(_, _), Acc) ->
Acc;
(?cm_additional_info_modification(_PartyName, _Comment, _Emails) = Mod, Acc) ->
AdditionalInfoEffects = make_additional_info_effects(Mod, Timestamp, Revision, Fun),
AdditionalInfoEffects ++ Acc;
(Change, Acc) ->
[Fun(Change, Timestamp, Revision) | Acc]
end,
[],
Modifications
)
).
make_additional_info_effects(?cm_additional_info_modification(PartyName, Comment, Emails), Timestamp, Revision, Fun) ->
AdditionalInfoMods = [
{party_name, PartyName},
{party_comment, Comment},
{emails, Emails}
],
make_additional_info_effects(AdditionalInfoMods, Timestamp, Revision, Fun, []).
make_additional_info_effects([], _Timestamp, _Revision, _Fun, Acc) ->
Acc;
make_additional_info_effects([{party_name, undefined} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(Tail, Timestamp, Revision, Fun, Acc);
make_additional_info_effects([{party_name, PartyName} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(
Tail,
Timestamp,
Revision,
Fun,
[Fun(?cm_additional_info_party_name_modification(PartyName), Timestamp, Revision) | Acc]
);
make_additional_info_effects([{party_comment, undefined} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(Tail, Timestamp, Revision, Fun, Acc);
make_additional_info_effects([{party_comment, Comment} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(
Tail,
Timestamp,
Revision,
Fun,
[Fun(?cm_additional_info_party_comment_modification(Comment), Timestamp, Revision) | Acc]
);
make_additional_info_effects([{emails, undefined} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(Tail, Timestamp, Revision, Fun, Acc);
make_additional_info_effects([{emails, Emails} | Tail], Timestamp, Revision, Fun, Acc) ->
make_additional_info_effects(
Tail,
Timestamp,
Revision,
Fun,
[Fun(?cm_additional_info_emails_modification(Emails), Timestamp, Revision) | Acc]
).

View File

@ -32,7 +32,13 @@ make(?contract_modification(ID, Modification), Timestamp, Revision) ->
make(?shop_modification(ID, Modification), Timestamp, Revision) ->
?shop_effect(ID, make_shop_effect(ID, Modification, Timestamp, Revision));
make(?wallet_modification(ID, Modification), Timestamp, _Revision) ->
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp)).
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp));
make(?pm_additional_info_party_name_modification(PartyName), _Timestamp, _Revision) ->
?additional_info_effect(make_additional_info_effect(party_name, PartyName));
make(?pm_additional_info_party_comment_modification(Comment), _Timestamp, _Revision) ->
?additional_info_effect(make_additional_info_effect(party_comment, Comment));
make(?pm_additional_info_emails_modification(Emails), _Timestamp, _Revision) ->
?additional_info_effect(make_additional_info_effect(emails, Emails)).
-spec make_safe(change(), timestamp(), revision()) -> effect() | no_return().
make_safe(
@ -116,6 +122,16 @@ make_wallet_effect(ID, {creation, Params}, Timestamp) ->
make_wallet_effect(_, {account_creation, Params}, _) ->
{account_created, pm_wallet:create_account(Params)}.
make_additional_info_effect(party_name, PartyName) ->
{party_name, PartyName};
make_additional_info_effect(party_comment, Comment) ->
{party_comment, Comment};
make_additional_info_effect(emails, Emails) ->
{contact_info, #domain_PartyContactInfo{
manager_contact_emails = Emails,
registration_email = <<"ignored_value">>
}}.
assert_report_schedule_valid(_, #domain_ReportPreferences{service_acceptance_act_preferences = undefined}, _) ->
ok;
assert_report_schedule_valid(

View File

@ -48,6 +48,12 @@
-export([wallet_suspension/3]).
-export([set_wallet/2]).
-export([get_contact_info/1]).
-export([set_contact_info/2]).
-export([set_party_name/2]).
-export([set_party_comment/2]).
-export_type([party/0]).
-export_type([party_revision/0]).
-export_type([party_status/0]).
@ -245,6 +251,22 @@ wallet_suspension(ID, Suspension, Party) ->
Wallet = get_wallet(ID, Party),
set_wallet(Wallet#domain_Wallet{suspension = Suspension}, Party).
-spec get_contact_info(party()) -> dmsl_domain_thrift:'PartyContactInfo'().
get_contact_info(#domain_Party{contact_info = ContactInfo}) ->
ContactInfo.
-spec set_contact_info(dmsl_domain_thrift:'PartyContactInfo'(), party()) -> party().
set_contact_info(ContactInfo, Party) ->
Party#domain_Party{contact_info = ContactInfo}.
-spec set_party_name(binary() | undefined, party()) -> party().
set_party_name(PartyName, Party) ->
Party#domain_Party{party_name = PartyName}.
-spec set_party_comment(binary() | undefined, party()) -> party().
set_party_comment(Comment, Party) ->
Party#domain_Party{comment = Comment}.
%% Internals
ensure_shop(#domain_Shop{} = Shop) ->

View File

@ -33,6 +33,7 @@
-export([invalid_shop_payout_tool_not_in_contract/1]).
-export([invalid_shop_payout_tool_currency_mismatch/1]).
-export([wallet_account_creation/1]).
-export([additional_info_modification/1]).
-type config() :: pm_ct_helper:config().
-type test_case_name() :: pm_ct_helper:test_case_name().
@ -73,7 +74,8 @@ all() ->
shop_already_exists,
invalid_shop_payout_tool_not_in_contract,
invalid_shop_payout_tool_currency_mismatch,
wallet_account_creation
wallet_account_creation,
additional_info_modification
].
-spec init_per_suite(config()) -> config().
@ -94,7 +96,7 @@ end_per_suite(C) ->
-spec party_creation(config()) -> _.
party_creation(C) ->
PartyID = cfg(party_id, C),
ContactInfo = #domain_PartyContactInfo{email = <<?MODULE_STRING>>},
ContactInfo = #domain_PartyContactInfo{registration_email = <<?MODULE_STRING>>},
ok = create_party(PartyID, ContactInfo, C),
{ok, Party} = get_party(PartyID, C),
#domain_Party{
@ -559,6 +561,32 @@ wallet_account_creation(C) ->
}
} = pm_party:get_wallet(WalletID, Party).
-spec additional_info_modification(config()) -> _.
additional_info_modification(C) ->
PartyName = <<"PartyName">>,
Comment = <<"PartyComment">>,
Emails = [
<<"Email1">>,
<<"Email2">>,
<<"Email3">>
],
Modifications = [
?cm_additional_info_modification(PartyName, Comment, Emails)
],
PartyID = cfg(party_id, C),
Claim = claim(Modifications, PartyID),
ok = accept_claim(Claim, C),
ok = commit_claim(Claim, C),
{ok, Party} = get_party(PartyID, C),
#domain_Party{
party_name = PartyName,
contact_info = #domain_PartyContactInfo{
registration_email = <<?MODULE_STRING>>,
manager_contact_emails = Emails
},
comment = Comment
} = Party.
%%% Internal functions
claim(PartyModifications, PartyID) ->

View File

@ -194,7 +194,7 @@ create_party_and_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Cl
make_party_params() ->
#payproc_PartyParams{
contact_info = #domain_PartyContactInfo{
email = <<?MODULE_STRING>>
registration_email = <<?MODULE_STRING>>
}
}.

View File

@ -527,7 +527,7 @@ end_per_testcase(_Name, _C) ->
party_creation(C) ->
Client = cfg(client, C),
PartyID = cfg(party_id, C),
ContactInfo = #domain_PartyContactInfo{email = <<?MODULE_STRING>>},
ContactInfo = #domain_PartyContactInfo{registration_email = <<?MODULE_STRING>>},
ok = pm_client_party:create(make_party_params(ContactInfo), Client),
[
?party_created(PartyID, ContactInfo, _),
@ -1310,12 +1310,16 @@ complex_claim_acceptance(C) ->
contract_id = ContractID,
payout_tool_id = <<"1">>
},
PartyName = <<"PartyName">>,
PartyComment = <<"PartyComment">>,
Emails = [],
ShopAccountParams = #payproc_ShopAccountParams{currency = ?cur(<<"RUB">>)},
Claim1 = assert_claim_pending(
pm_client_party:create_claim(
[
?shop_modification(ShopID1, {creation, Params1}),
?shop_modification(ShopID1, {shop_account_creation, ShopAccountParams})
?shop_modification(ShopID1, {shop_account_creation, ShopAccountParams}),
?additional_info_modification(PartyName, PartyComment, Emails)
],
Client
),
@ -1331,7 +1335,8 @@ complex_claim_acceptance(C) ->
pm_client_party:create_claim(
[
?shop_modification(ShopID2, {creation, Params2}),
?shop_modification(ShopID2, {shop_account_creation, ShopAccountParams})
?shop_modification(ShopID2, {shop_account_creation, ShopAccountParams}),
?additional_info_modification(PartyName, PartyComment, Emails)
],
Client
),
@ -1343,6 +1348,11 @@ complex_claim_acceptance(C) ->
true = Claim1#payproc_Claim.revision =/= Claim1_1#payproc_Claim.revision,
ok = accept_claim(Claim2, Client),
ok = accept_claim(Claim1_1, Client),
#domain_Party{
party_name = PartyName,
comment = PartyComment,
contact_info = #domain_PartyContactInfo{manager_contact_emails = Emails}
} = pm_client_party:get(Client),
#domain_Shop{details = Details1, category = ?cat(3)} = pm_client_party:get_shop(ShopID1, Client),
#domain_Shop{details = Details2} = pm_client_party:get_shop(ShopID2, Client).
@ -2175,7 +2185,7 @@ next_event(Client) ->
%%
make_party_params() ->
make_party_params(#domain_PartyContactInfo{email = <<?MODULE_STRING>>}).
make_party_params(#domain_PartyContactInfo{registration_email = <<?MODULE_STRING>>}).
make_party_params(ContactInfo) ->
#payproc_PartyParams{contact_info = ContactInfo}.

View File

@ -12,7 +12,7 @@
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"b04aba83100a4d0adc19b5797372970fd632f911"}},
{ref,"02e0ec0db6fc70c30a97d61af3729c4e09df4a88"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",