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

adapt submit and verify process to new wallet, account concept

passed tests
This commit is contained in:
Haydar Ghasemi 2025-10-28 12:15:40 +03:30
parent 65c9c62484
commit 7cec791602

View file

@ -360,64 +360,13 @@ class ApplicationApiFlowsTests(APITestCase):
to_wallet = response.json()['results'][0]
self.assertEqual(to_wallet['balance'], 200)
def test_withdraw_flow_wallet_success(self):
auth = self._create_authorization_header(self.payer_access_token.token)
# Checking wallets initials values(application balance = 300 and payee balance = zero)
kwargs_wallet_uuid = {
'wallet_uuid': self.wallet_rial_uuid
}
response = self.client.get(reverse('wallet:application_account_balance_api', kwargs=kwargs_wallet_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 300)
kwargs_wallet_uuid_payer_uuid = {
'wallet_uuid': self.wallet_rial_uuid,
'uuid': self.payer_uuid,
}
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=kwargs_wallet_uuid_payer_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 300)
# Deposit process
data = {
'amount': 100,
'payer': self.payer_uuid,
'payer_type': TypeChoices.USER,
'payer_account': self.wallet_rial_uuid,
}
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_wallet_uuid), data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 201)
json_response = response.json()
kwargs_wallet_uuid_transaction_uuid = {
'wallet_uuid': self.wallet_rial_uuid,
'uuid': json_response['uuid'],
}
response = self.client.get(reverse('wallet:application_withdraw_verify_api', kwargs=kwargs_wallet_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_account_balance_api', kwargs=kwargs_wallet_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 400)
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=kwargs_wallet_uuid_payer_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 200)
kwargs_wallet_uuid_payer_uuid = {
'wallet_uuid': self.wallet_reward_uuid,
'uuid': self.payer_uuid,
}
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=kwargs_wallet_uuid_payer_uuid), HTTP_AUTHORIZATION=auth)
self.assertContains(response, 'balance')
self.assertEqual(response.json()['balance'], 300)
def test_withdraw_flow_zero_amount(self):
auth = self._create_authorization_header(self.payer_access_token.token)
kwargs_payee_wallet = {
'payee_wallet': self.wallet_rial_uuid,
}
# Deposit process
data = {
'amount': 0,
@ -425,24 +374,23 @@ class ApplicationApiFlowsTests(APITestCase):
'payer_type': TypeChoices.USER,
'payer_account': self.wallet_rial_uuid,
}
kwargs_wallet_uuid = {
'wallet_uuid': self.wallet_rial_uuid,
}
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_wallet_uuid), data=data,
HTTP_AUTHORIZATION=auth)
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_payee_wallet),
data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 400)
def test_withdraw_flow_negative_amount(self):
auth = self._create_authorization_header(self.payer_access_token.token)
kwargs_payee_wallet = {
'payee_wallet': self.wallet_rial_uuid,
}
# Deposit process
data = {
'amount': -500,
'payer': self.payer_uuid,
'payer_type': TypeChoices.USER
'payer_type': TypeChoices.USER,
'payer_account': self.wallet_rial_uuid,
}
response = self.client.post(reverse('wallet:application_withdraw_submit_api'), data=data,
HTTP_AUTHORIZATION=auth)
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_payee_wallet), data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 400)
def test_withdraw_flow_prevent_double_spending(self):
@ -452,33 +400,35 @@ class ApplicationApiFlowsTests(APITestCase):
'wallet_uuid': self.wallet_rial_uuid,
}
# Checking wallets initials values(application balance = 300 and payee balance = zero)
response = self.client.get(reverse('wallet:application_account_balance_api', kwargs=kwargs_wallet_uuid), 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.payer_uuid,
'wallet_uuid': self.wallet_rial_uuid,
'owner': self.payer_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'], 300)
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'], 300)
# Deposit process
data = {
'uuid': 'b14e8b86-8f4a-44d9-b29d-badceb470053',
'amount': 200,
'amount': 100,
'payer': self.payer_uuid,
'payer_type': TypeChoices.USER,
'payer_account': self.wallet_rial_uuid,
'payer_wallet': self.wallet_rial_uuid,
}
kwargs_wallet_uuid = {
'wallet_uuid': self.wallet_rial_uuid,
kwargs_payee_wallet = {
'payee_wallet': self.wallet_rial_uuid,
}
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_wallet_uuid), data=data, HTTP_AUTHORIZATION=auth)
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_payee_wallet), data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 201)
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_wallet_uuid), data=data, HTTP_AUTHORIZATION=auth)
response = self.client.post(reverse('wallet:application_withdraw_submit_api', kwargs=kwargs_payee_wallet), data=data, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 201)