wallet deposit by category uuid and check its and other wallets desired balance

This commit is contained in:
hgh 2025-09-06 13:59:07 +03:30
parent 6c12f0b016
commit bcc07f75d4

View file

@ -9,18 +9,22 @@ from rest_framework.test import APITestCase
from apps.users.models import User
from apps.wallet.constans import TypeChoices
from apps.wallet.models import Wallet
from apps.wallet.models import Category
AccessToken = get_access_token_model()
Application = get_application_model()
class ApplicationApiFlowsTests(APITestCase):
application_access_token = 'u4naVsdKCbKNOhnElPyXcrwSnqqFbm'
payer_access_token = 'u4naVsdKCbKNOhnElPyXcrwSnqqFbm2'
client_id = '4INGOCMoulE0fNY1SQlTbPtsWqqxGj2DdqjADq6u'
application_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470053')
application_access_token = '14naVsdKCbKNOhnElPyXcrwSnqqFbm'
payer_access_token = '24naVsdKCbKNOhnElPyXcrwSnqqFbm'
payer_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470051')
payee_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470052')
application_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470053')
client_id = '4INGOCMoulE0fNY1SQlTbPtsWqqxGj2DdqjADq6u'
wallet_category1_uuid = uuid.UUID('114e8b86-8f4a-44d9-b29d-badceb470051')
wallet_category2_uuid = uuid.UUID('214e8b86-8f4a-44d9-b29d-badceb470051')
# application, _ = Application.objects.get_or_create(client_id=client_id, uuid=application_uuid)
scopes = [
'wallet.application.deposit:verify',
@ -71,6 +75,14 @@ class ApplicationApiFlowsTests(APITestCase):
client_id=self.client_id,
uuid=self.application_uuid,
)
self.wallet_category1, _ = Category.objects.get_or_create(application=self.application, uuid=self.wallet_category1_uuid)
self.wallet_category2, _ = Category.objects.get_or_create(application=self.application, uuid=self.wallet_category2_uuid)
self.application_wallet1, _ = Wallet.objects.get_or_create(owner_uuid=self.application_uuid, owner_type=TypeChoices.APPLICATION, balance=300, category=self.wallet_category1)
self.application_wallet2, _ = Wallet.objects.get_or_create(owner_uuid=self.application_uuid, owner_type=TypeChoices.APPLICATION, balance=300, category=self.wallet_category2)
self.payee_wallet1, _ = Wallet.objects.get_or_create(owner_uuid=self.payee_uuid, owner_type=TypeChoices.USER, category=self.wallet_category1)
self.payee_wallet2, _ = Wallet.objects.get_or_create(owner_uuid=self.payee_uuid, owner_type=TypeChoices.USER, category=self.wallet_category2)
self.payer_wallet1, _ = Wallet.objects.get_or_create(owner_uuid=self.payer_uuid, owner_type=TypeChoices.USER, balance=300, category=self.wallet_category1)
self.payer_wallet2, _ = Wallet.objects.get_or_create(owner_uuid=self.payer_uuid, owner_type=TypeChoices.USER, balance=300, category=self.wallet_category2)
def tearDown(self):
super().tearDown()
@ -85,7 +97,7 @@ class ApplicationApiFlowsTests(APITestCase):
def test_authentication_expired_token(self):
access_token = 'u4naVsdKCbKNOhnElPyXcrwSnqqFbm23'
access_token = '34naVsdKCbKNOhnElPyXcrwSnqqFbm'
expired_access_token, _created = AccessToken.objects.update_or_create(
token=access_token,
defaults={
@ -149,6 +161,56 @@ class ApplicationApiFlowsTests(APITestCase):
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 100)
def test_deposit_flow_category_success(self):
auth = self._create_authorization_header(self.application_access_token.token)
# Checking wallets initials values(application balance = 300 and payee balance = zero)
kwargs_category_uuid = {
'category_uuid': self.wallet_category1_uuid
}
response = self.client.get(reverse('wallet:application_wallet_balance_api', kwargs=kwargs_category_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 300)
kwargs_category_uuid_payee_uuid = {
'category_uuid': self.wallet_category1_uuid,
'uuid': self.payee_uuid,
}
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=kwargs_category_uuid_payee_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 0)
# Deposit process
data = {
'amount': 100,
'payee_id': self.payee_uuid,
'payee_type': TypeChoices.USER
}
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_category_uuid), data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 201)
json_response = response.json()
kwargs_category_uuid_transaction_uuid = {
'category_uuid': self.wallet_category1_uuid,
'uuid': json_response['uuid'],
}
response = self.client.get(reverse('wallet:application_deposit_verify_api', kwargs=kwargs_category_uuid_transaction_uuid), HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['state'], 5)
# Desired results
response = self.client.get(reverse('wallet:application_wallet_balance_api', kwargs=kwargs_category_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 200)
kwargs_category_uuid_payee_uuid = {
'category_uuid': self.wallet_category2_uuid,
'uuid': self.payee_uuid,
}
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=kwargs_category_uuid_payee_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 0)
def test_deposit_flow_insufficient_balance(self):
auth = self._create_authorization_header(self.application_access_token.token)