Skip to content

Commit

Permalink
test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Nov 29, 2023
1 parent 93a7426 commit 7a3bef9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/accounting_exports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w

# Store expense IDs and remove unnecessary keys
expense_ids = accounting_export['expense_ids']
accounting_export[date_field] = accounting_export[date_field].strftime('%Y-%m-%dT%H:%M:%S')
accounting_export.pop('total')
accounting_export.pop('expense_ids')

Expand All @@ -137,6 +138,7 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w
workspace_id=workspace_id,
fund_source=accounting_export['fund_source'],
description=accounting_export,
status='EXPORT_READY'
)

# Add related expenses to the AccountingExport object
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def add_export_settings():
default_bank_account_name='Accounts Payable',
default_back_account_id='1',
reimbursable_expense_state='PAYMENT_PROCESSING',
reimbursable_expense_date='current_date' if workspace_id == 1 else 'last_spent_at',
reimbursable_expense_date='spent_at' if workspace_id == 1 else 'last_spent_at',
reimbursable_expense_grouped_by='REPORT' if workspace_id == 1 else 'EXPENSE',
credit_card_expense_export_type='CREDIT_CARD_PURCHASE' if workspace_id in [1, 2] else 'JOURNAL_ENTRY',
credit_card_expense_state='PAYMENT_PROCESSING',
Expand Down
62 changes: 62 additions & 0 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,66 @@
]
}
],
'expenses':[
{
'id':91,
'employee_email':'[email protected]',
'employee_name':'Joanna',
'category':'Food',
'sub_category':None,
'project':'Aaron Abbott',
'org_id':'or79Cob97KSh',
'expense_id':'txxTi9ZfdepC',
'expense_number':'E/2022/05/T/16',
'claim_number':'C/2022/05/R/4',
'report_title':'R/2022/05/R/4',
'amount':50.0,
'currency':'USD',
'foreign_amount':None,
'foreign_currency':None,
'tax_amount':None,
'tax_group_id':None,
'settlement_id':'setDiksMn83K7',
'reimbursable':True,
'billable':False,
'exported':False,
'state':'PAYMENT_PROCESSING',
'vendor':'Ashwin',
'cost_center':'Marketing',
'purpose':None,
'report_id':'rpViBmuYmAgw',
'corporate_card_id':None,
'file_ids':[

],
'spent_at':'2022-05-13T17:00:00Z',
'approved_at':'2022-05-13T09:30:13.484000Z',
'posted_at': '2021-12-22T07:30:26.289842+00:00',
'expense_created_at':'2022-05-13T09:29:43.535468Z',
'expense_updated_at':'2022-05-13T09:32:06.643941Z',
'created_at':'2022-05-23T11:11:28.241406Z',
'updated_at':'2022-05-23T11:11:28.241440Z',
'fund_source':'PERSONAL',
'source_account_type': 'PERSONAL_CASH_ACCOUNT',
'verified_at':'2022-05-23T11:11:28.241440Z',
'custom_properties':{
'Team':'',
'Class':'',
'Klass':'',
'Location':'',
'Team Copy':'',
'Tax Groups':'',
'Departments':'',
'Team 2 Postman':'',
'User Dimension':'',
'Location Entity':'',
'Operating System':'',
'System Operating':'',
'User Dimension Copy':'',
'Custom Expense Field':'None'
},
'paid_on_qbo':False,
'payment_number':'P/2022/05/R/7'
}
],
}
17 changes: 16 additions & 1 deletion tests/test_fyle/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from django.urls import reverse

from apps.accounting_exports.models import AccountingExport
from apps.fyle.models import Expense
from apps.workspaces.models import FyleCredential, Workspace
from tests.helpers import dict_compare_keys
from tests.test_fyle.fixtures import fixtures as data
Expand Down Expand Up @@ -114,11 +116,24 @@ def test_exportable_expense_group_view(api_client, test_connection, create_temp_
assert response.status_code == 200


def test_accounting_export_sync_view(api_client, test_connection, create_temp_workspace, add_fyle_credentials, add_export_settings):
def test_accounting_export_sync_view(api_client, test_connection, create_temp_workspace, add_fyle_credentials, add_export_settings, mocker):

access_token = test_connection.access_token
url = reverse('sync-accounting-exports', kwargs={'workspace_id': 1})

mocker.patch(
'fyle_integrations_platform_connector.apis.Expenses.get',
return_value = data['expenses'],
)

api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))

response = api_client.post(url)
assert response.status_code == 200

accounting_exports = AccountingExport.objects.filter(workspace_id=1)

assert accounting_exports[0].status == 'COMPLETE'

expenses = Expense.objects.filter(org_id='or79Cob97KSh')
assert len(expenses) == 1

0 comments on commit 7a3bef9

Please sign in to comment.