fix(wallet): adapt submit and verify process to new wallet, account concept

adapt submit and verify process to new wallet, account concept

test_deposit_flow_skip_insufficient_balance_for_allowed_negative_balance_applications
This commit is contained in:
Haydar Ghasemi 2025-10-27 12:29:56 +03:30
parent c5ec20e1f0
commit 450c6f0191
2 changed files with 21 additions and 19 deletions

View file

@ -14,10 +14,11 @@ from apps.wallet.models import Wallet
AccessToken = get_access_token_model()
Application = get_application_model()
application_uuid_hex = 'b14e8b86-8f4a-44d9-b29d-badceb470053'
class ApplicationApiFlowsTests(APITestCase):
client_id = '4INGOCMoulE0fNY1SQlTbPtsWqqxGj2DdqjADq6u'
application_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470053')
application_uuid = uuid.UUID(application_uuid_hex)
application_access_token = '14naVsdKCbKNOhnElPyXcrwSnqqFbm'
payer_access_token = '24naVsdKCbKNOhnElPyXcrwSnqqFbm'
payer_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470051')
@ -205,35 +206,36 @@ class ApplicationApiFlowsTests(APITestCase):
data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 422)
@override_settings(ALLOWED_NEGATIVE_BALANCE_APPLICATIONS=['b14e8b86-8f4a-44d9-b29d-badceb470053'])
@override_settings(ALLOWED_NEGATIVE_BALANCE_APPLICATIONS=[application_uuid_hex])
def test_deposit_flow_skip_insufficient_balance_for_allowed_negative_balance_applications(self):
auth = self._create_authorization_header(self.application_access_token.token)
# Checking wallets initials values(application balance = 300 and payee balance = zero)
response = self.client.get(reverse('wallet:application_account_balance_api'), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 300)
wallets = [self.wallet_rial_uuid.hex, self.wallet_reward_uuid.hex]
response = self.client.get(reverse('wallet:application_account_balance_api'), query_params={'wallet': ','.join(wallets)}, HTTP_AUTHORIZATION=auth)
self.assertGreater(response.json()['count'], 1)
from_wallet = response.json()['results'][0]
self.assertEqual(from_wallet['balance'], 300)
params = {
'uuid': self.payee_uuid,
'wallet_uuid': self.wallet_rial_uuid,
'user': self.payee_uuid,
}
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=params), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 0)
response = self.client.get(reverse('wallet:application_user_account_api', kwargs=params), query_params={'wallet': ','.join(wallets)}, HTTP_AUTHORIZATION=auth)
self.assertGreater(response.json()['count'], 1)
to_wallet = response.json()['results'][0]
self.assertEqual(to_wallet['balance'], 0)
# Deposit process
data = {
'amount': 500,
'payee': self.payee_uuid,
'payee_type': TypeChoices.USER,
'payee_account': self.wallet_rial_uuid,
'payee_wallet': self.wallet_rial_uuid,
}
kwargs_wallet_uuid_payee_uuid = {
'wallet_uuid': self.wallet_rial_uuid,
kwargs_payer_wallet = {
'payer_wallet': self.wallet_rial_uuid,
}
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_wallet_uuid_payee_uuid), data=data, HTTP_AUTHORIZATION=auth)
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_payer_wallet),
data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 201)
def test_deposit_flow_zero_amount(self):

View file

@ -181,9 +181,9 @@ class DepositSubmitAPIView(generics.CreateAPIView):
required_scopes = ['wallet.application.deposit:submit']
def get_queryset(self):
wallet_uuid = self.kwargs.get('wallet_uuid')
if wallet_uuid:
wallet = get_object_or_404(Wallet.objects.all(), uuid=wallet_uuid)
payer_wallet_uuid = self.kwargs.get('payer_wallet')
if payer_wallet_uuid:
wallet = get_object_or_404(Wallet.objects.all(), uuid=payer_wallet_uuid)
else:
wallet = None
application = get_application(self.request)