|
| 1 | +import requests_mock # type: ignore |
| 2 | + |
| 3 | +import cuenca |
| 4 | + |
| 5 | + |
| 6 | +def test_get_balance(): |
| 7 | + # It is the case when the user has transactions in the account |
| 8 | + response_json = { |
| 9 | + 'items': [ |
| 10 | + { |
| 11 | + 'id': 'LE6xvD1ocHmSIu7MgzlC9woj', |
| 12 | + 'created_at': '2021-08-17T21:45:23.061000', |
| 13 | + 'user_id': 'US3zGWi1n852bTyqD1wCZ1ft', |
| 14 | + 'name': 'RESTAURANT BRASIL MEXICO DF CMXMX', |
| 15 | + 'amount': 1212, |
| 16 | + 'descriptor': '', |
| 17 | + 'rolling_balance': 7578889, |
| 18 | + 'type': 'debit', |
| 19 | + 'related_transaction_uri': '/card_transactions/CT3TA', |
| 20 | + 'funding_instrument_uri': '/cards/CA243qFpGLDAaPamCMYHhS0p', |
| 21 | + 'wallet_id': 'default', |
| 22 | + } |
| 23 | + ], |
| 24 | + 'next_page_uri': None, |
| 25 | + } |
| 26 | + with requests_mock.mock() as m: |
| 27 | + m.get( |
| 28 | + 'https://sandbox.cuenca.com/balance_entries?limit=1', |
| 29 | + status_code=200, |
| 30 | + json=response_json, |
| 31 | + ) |
| 32 | + |
| 33 | + balance = cuenca.get_balance() |
| 34 | + assert balance == response_json['items'][0]['rolling_balance'] |
| 35 | + |
| 36 | + |
| 37 | +def test_get_balance_before_first_transaction(): |
| 38 | + # When the user have no transactions at all |
| 39 | + # balance_entries endpoint returns `items` as empty list. |
| 40 | + # It means that its balance is Mx$0.00 |
| 41 | + response_json = {'items': [], 'next_page_uri': None} |
| 42 | + |
| 43 | + with requests_mock.mock() as m: |
| 44 | + m.get( |
| 45 | + 'https://sandbox.cuenca.com/balance_entries?limit=1', |
| 46 | + status_code=200, |
| 47 | + json=response_json, |
| 48 | + ) |
| 49 | + |
| 50 | + balance = cuenca.get_balance() |
| 51 | + assert balance == 0 |
0 commit comments