Skip to content

Commit

Permalink
Merge pull request #73 from pagopa/IDP-2511-change-amount-management-…
Browse files Browse the repository at this point in the history
…in-cents

fix: [IDP-2511] change amount management in cents
  • Loading branch information
Benedetta-fabbri authored May 10, 2024
2 parents 018bc0e + d047b7e commit da1d22e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 52 deletions.
6 changes: 3 additions & 3 deletions bdd/steps/discount_transaction_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def step_when_citizen_confirms_transaction(context, citizen_name, trx_name):

step_check_named_transaction_status(context=context, trx_name=trx_name, expected_status='AUTHORIZED')

update_user_counters(context=context, citizen_name=citizen_name, reward=res.json()['reward'])
update_user_counters(context=context, citizen_name=citizen_name, reward=res.json()['rewardCents'])

retry_timeline(expected=timeline_operations.transaction, request=timeline,
num_required=context.trxs_per_citizen[citizen_name], token=curr_token_io,
Expand All @@ -306,7 +306,7 @@ def step_when_citizen_confirms_transaction(context, citizen_name, trx_name):
check_unprocessed_transactions(initiative_id=context.initiative_id,
expected_trx_id=context.transactions[trx_name]['id'],
expected_effective_amount=context.transactions[trx_name]['amountCents'],
expected_reward_amount=context.latest_trx_details.json()['reward'],
expected_reward_amount=context.latest_trx_details.json()['rewardCents'],
expected_fiscal_code=context.citizens_fc[citizen_name],
merchant_id=associated_merchant_id,
expected_status='AUTHORIZED'
Expand All @@ -322,7 +322,7 @@ def step_when_citizen_rapidly_confirms_the_transactions(context, citizen_name, t
trx_name = context.transactions[trx_name]['trxCode']

res = complete_transaction_confirmation(context=context, trx_code=trx_name, token_io=curr_token_io)
update_user_counters(context=context, citizen_name=citizen_name, reward=res.json()['reward'])
update_user_counters(context=context, citizen_name=citizen_name, reward=res.json()['rewardCents'])
context.associated_citizen[trx_name] = context.citizens_fc[citizen_name]


Expand Down
9 changes: 5 additions & 4 deletions bdd/steps/family_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bdd.steps.idpay_code_steps import step_citizen_enroll_correctly_idpay_code
from bdd.steps.onboarding_steps import step_check_onboarding_status
from bdd.steps.ranking_steps import step_check_absence_in_ranking
from util.dataset_utility import euros_to_cents
from util.utility import detokenize_to_fc
from util.utility import get_io_token
from util.utility import retry_wallet
Expand Down Expand Up @@ -46,11 +47,11 @@ def step_demanded_family_member_onboards(context, citizen_name):

@then('the family member {citizen_name} has budget of {amount_left} euros left')
def step_check_family_member_budget_left(context, citizen_name, amount_left):
expected_amount_left = float(amount_left)
expected_amount_left = euros_to_cents(amount_left)
curr_token_io = get_io_token(context.citizens_fc[citizen_name])

retry_wallet(expected=expected_amount_left, request=wallet, token=curr_token_io,
initiative_id=context.initiative_id, field='amount', tries=10, delay=2)
initiative_id=context.initiative_id, field='amountCents', tries=10, delay=2)


@then('the family members {citizens_names} have budget of {amount_left} euros left')
Expand All @@ -63,11 +64,11 @@ def step_check_family_members_budget_left(context, citizens_names, amount_left):
@then('the family member {citizen_name} is rewarded with {expected_accrued} euros')
@given('the family member {citizen_name} is rewarded with {expected_accrued} euros')
def step_check_rewards_of_citizen(context, citizen_name, expected_accrued):
expected_accrued = float(expected_accrued)
expected_accrued = euros_to_cents(expected_accrued)
curr_token_io = get_io_token(context.citizens_fc[citizen_name])

retry_wallet(expected=expected_accrued, request=wallet, token=curr_token_io,
initiative_id=context.initiative_id, field='accrued', tries=10, delay=2)
initiative_id=context.initiative_id, field='accruedCents', tries=10, delay=2)


@given('the family members {citizens_names} enroll correctly a new IDPay Code on the initiative')
Expand Down
1 change: 0 additions & 1 deletion bdd/steps/initiative_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytz
from behave import given
from behave import then
from behave import when

from api.idpay import get_initiative_info
from api.idpay import get_initiative_statistics
Expand Down
58 changes: 29 additions & 29 deletions tests/test_cashback_like/test_cashback_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from util.dataset_utility import fake_fc
from util.dataset_utility import fake_iban
from util.dataset_utility import fake_pan
from util.dataset_utility import Reward
from util.dataset_utility import reward
from util.encrypt_utilities import pgp_string_routine
from util.transaction_upload import encrypt_and_upload
from util.utility import card_enroll
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_send_single_transaction():
onboarded_citizen_count_increment=1, accrued_rewards_increment=expected_accrued,
rewarded_trxs_increment=1)
# 1.2.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -153,7 +153,7 @@ def test_send_50_transaction_erode_budget_max_award():
skip_trx_check=True)

# 1.3.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -208,7 +208,7 @@ def test_send_single_200e_transaction_erode_budget_max_award():
onboarded_citizen_count_increment=1, accrued_rewards_increment=expected_accrued,
rewarded_trxs_increment=1)

check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -260,7 +260,7 @@ def test_not_award_after_budget_erosion():
# 1.5.4
expect_wallet_counters(expected_amount_left, expected_accrued, token, initiative_id)

check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

# 1.5.5
check_statistics(organization_id=organization_id, initiative_id=initiative_id, old_statistics=old_statistics,
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_award_again_after_reversal():
onboarded_citizen_count_increment=1, accrued_rewards_increment=expected_accrued,
rewarded_trxs_increment=num_trx)

check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand All @@ -368,7 +368,7 @@ def test_award_again_after_reversal():
expect_wallet_counters(expected_amount_left, expected_accrued, token, initiative_id)

# 1.6.9
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

reversal_transaction = custom_transaction(pan=pan, amount=curr_amount, correlation_id=latest_trx_correlation_id,
Expand All @@ -391,7 +391,7 @@ def test_award_again_after_reversal():
expect_wallet_counters(expected_amount_left, expected_accrued, token, initiative_id)

# 1.6.12
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, 0 - expected_reversal)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, 0 - expected_reversal)])
# 1.6.12
check_statistics(organization_id=organization_id, initiative_id=initiative_id, old_statistics=old_statistics,
onboarded_citizen_count_increment=1, accrued_rewards_increment=expected_accrued,
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_award_again_after_reversal():

# 1.6.15
check_rewards(initiative_id=initiative_id,
expected_rewards=[Reward(curr_iban, least_accrued)])
expected_rewards=[reward(curr_iban, least_accrued)])

# 1.6.16
check_statistics(organization_id=organization_id, initiative_id=initiative_id, old_statistics=old_statistics,
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_send_transaction_ko_card_enroll():
rewarded_trxs_increment=0)

# 1.7.7
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand Down Expand Up @@ -556,7 +556,7 @@ def test_remove_card_and_enroll_again():
expect_wallet_counters(expected_amount_left, expected_accrued, token, initiative_id)

# 1.8.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

# 1.8.7
check_statistics(organization_id=organization_id, initiative_id=initiative_id, old_statistics=old_statistics,
Expand Down Expand Up @@ -593,7 +593,7 @@ def test_remove_card_and_enroll_again():
rewarded_trxs_increment=1)

# 1.8.11
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)
# 1.8.12
card_enroll(test_fc, pan, initiative_id, num_required=2)
Expand Down Expand Up @@ -628,7 +628,7 @@ def test_remove_card_and_enroll_again():
expect_wallet_counters(expected_amount=expected_amount_left, expected_accrued=expected_accrued, token=token,
initiative_id=initiative_id)
# 1.8.15
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, least_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, least_accrued)])


@pytest.mark.IO
Expand Down Expand Up @@ -698,7 +698,7 @@ def test_ko_iban_enroll():
rewarded_trxs_increment=1)

# 1.9.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand All @@ -709,7 +709,7 @@ def test_ko_iban_enroll():
initiative_id=initiative_id, field='status', tries=3, delay=3)

# 1.9.7
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])


@pytest.mark.IO
Expand Down Expand Up @@ -764,7 +764,7 @@ def test_small_amount_no_award():
rewarded_trxs_increment=0)

# 1.10.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand Down Expand Up @@ -814,7 +814,7 @@ def test_send_minimum_awardable_amount():
expect_wallet_counters(expected_amount_left, expected_accrued, token, initiative_id)

# 1.11.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

# 1.11.7
check_statistics(organization_id=organization_id, initiative_id=initiative_id, old_statistics=old_statistics,
Expand Down Expand Up @@ -876,7 +876,7 @@ def test_send_transaction_after_fruition_period():
rewarded_trxs_increment=0)

# 1.12.7
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand Down Expand Up @@ -976,7 +976,7 @@ def test_send_transaction_after_unsubscribe():
expect_wallet_counters(expected_amount_left, expected_accrued, token=token, initiative_id=initiative_id)

# 1.22.8
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def test_get_pending_reward_after_unsubscribe():
assert [] == get_payment_instruments(initiative_id=initiative_id, token=token).json()['instrumentList']

# 1.25.8
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1191,7 +1191,7 @@ def test_onboarding_after_unsubscribe():
rewarded_trxs_increment=1)

# 1.28.11
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1305,7 +1305,7 @@ def test_no_reward_transaction_1sec_before_card_enrollment():
rewarded_trxs_increment=0)

# 1.29.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand Down Expand Up @@ -1363,7 +1363,7 @@ def test_award_correct_amount_after_partial_reversal():
rewarded_trxs_increment=1)

# 1.31.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1400,7 +1400,7 @@ def test_award_correct_amount_after_partial_reversal():
rewarded_trxs_increment=1)

# 1.31.11
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, 0 - expected_reversal)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, 0 - expected_reversal)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1485,7 +1485,7 @@ def test_no_reward_after_complete_reversal():
expect_wallet_counters(expected_amount_left, expected_accrued, token, initiative_id)

# 1.32.8
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)],
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)],
check_absence=True)

clean_trx_files(curr_file_name)
Expand Down Expand Up @@ -1542,7 +1542,7 @@ def test_reward_transaction_after_complete_reversal():
onboarded_citizen_count_increment=1, accrued_rewards_increment=expected_accrued,
rewarded_trxs_increment=1)
# 1.33.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1579,7 +1579,7 @@ def test_reward_transaction_after_complete_reversal():
rewarded_trxs_increment=0)

# 1.33.11
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, 0 - expected_reversal)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, 0 - expected_reversal)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1635,7 +1635,7 @@ def test_reward_transaction_after_partial_reversal():
onboarded_citizen_count_increment=1, accrued_rewards_increment=expected_accrued,
rewarded_trxs_increment=1)
# 1.34.6
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, expected_accrued)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, expected_accrued)])

clean_trx_files(curr_file_name)

Expand Down Expand Up @@ -1697,6 +1697,6 @@ def test_reward_transaction_after_partial_reversal():
rewarded_trxs_increment=2)

# 1.34.13
check_rewards(initiative_id=initiative_id, expected_rewards=[Reward(curr_iban, newly_accrued - expected_reversal)])
check_rewards(initiative_id=initiative_id, expected_rewards=[reward(curr_iban, newly_accrued - expected_reversal)])

clean_trx_files(curr_file_name)
5 changes: 5 additions & 0 deletions util/dataset_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ def fake_merchant_file(acquirer_id: str,
f'{acquirer_id};Esercente di test {datetime.datetime.now().strftime("%Y%m%d - %H%M%S")} {str(uuid.uuid4())[:4]};Indirizzo sede legale;Comune sede legale;Provincia sede legale;CAP sede Legale;[email protected];{merchant_info.fc};{merchant_info.vat};a;v;c;s;w;d;f;e;{merchant_info.iban}')

return merchants_csv


def euros_to_cents(amount):
amount = round(float(amount), 2)
return int(amount * 100)
Loading

0 comments on commit da1d22e

Please sign in to comment.