Skip to content

Commit

Permalink
added test for export settings api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Oct 25, 2023
1 parent cfb791b commit e9a0b17
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/workspaces/apis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@


urlpatterns = [
path('<int:workspace_id>/map_employees/', MapEmployeesView.as_view()),
path('<int:workspace_id>/export_settings/', ExportSettingsView.as_view()),
path('<int:workspace_id>/map_employees/', MapEmployeesView.as_view(), name='map-employees'),
path('<int:workspace_id>/export_settings/', ExportSettingsView.as_view(), name='export-settings'),
]
Empty file.
Empty file.
196 changes: 196 additions & 0 deletions tests/test_workspaces/test_apis/test_export_settings/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
data = {
'export_settings': {
'configuration': {
'reimbursable_expenses_object': 'EXPENSE REPORT',
'corporate_credit_card_expenses_object': 'EXPENSE REPORT',
'auto_map_employees': 'NAME',
'is_simplify_report_closure_enabled': False,
'employee_field_mapping': 'EMPLOYEE'
},
'expense_group_settings': {
'reimbursable_expense_group_fields': [
'fund_source',
'employee_email',
'claim_number',
'report_id'
],
'reimbursable_export_date_type': 'current_date',
'expense_state': 'PAYMENT_PROCESSING',
'corporate_credit_card_expense_group_fields': [
'fund_source',
'claim_number',
'employee_email',
'report_id',
'spent_at',
'expense_id'
],
'ccc_export_date_type': 'spent_at',
'ccc_expense_state': 'PAID'
},
'general_mappings': {
'reimbursable_account': {
'id': '',
'name': ''
},
'accounts_payable': {
'id': '',
'name': ''
},
'default_ccc_account': {
'id': '1',
'name': 'Elon musk'
},
'default_ccc_vendor': {
'id': '',
'name': ''
}
}
},
'response': {
'configuration': {
'reimbursable_expenses_object': 'EXPENSE_REPORT',
'corporate_credit_card_expenses_object': 'CHARGE_CARD_TRANSACTION',
'auto_map_employees': 'NAME',
'is_simplify_report_closure_enabled': False,
'employee_field_mapping': 'EMPLOYEE'
},
'expense_group_settings': {
'reimbursable_expense_group_fields': [
'fund_source',
'employee_email',
'claim_number',
'report_id'
],
'reimbursable_export_date_type': 'current_date',
'expense_state': 'PAYMENT_PROCESSING',
'corporate_credit_card_expense_group_fields': [
'fund_source',
'claim_number',
'employee_email',
'report_id',
'spent_at',
'expense_id'
],
'ccc_export_date_type': 'spent_at',
'ccc_expense_state': 'PAID'
},
'general_mappings': {
'reimbursable_account': {
'id': '',
'name': ''
},
'accounts_payable': {
'id': '',
'name': ''
},
'default_ccc_account': {
'id': '1',
'name': 'Elon musk'
},
'default_ccc_vendor': {
'id': '',
'name': ''
}
},
'workspace_id': 1
},
'export_settings_missing_values_configurations': {
'configurations': {},
'expense_group_settings': {
'reimbursable_expense_group_fields': [
'fund_source',
'employee_email',
'claim_number',
'report_id'
],
'reimbursable_export_date_type': 'current_date',
'expense_state': 'PAYMENT_PROCESSING',
'corporate_credit_card_expense_group_fields': [
'fund_source',
'claim_number',
'employee_email',
'report_id',
'spent_at',
'expense_id'
],
'ccc_export_date_type': 'spent_at',
'ccc_expense_state': 'PAID'
},
'general_mappings': {
'reimbursable_account': {
'id': '',
'name': ''
},
'accounts_payable': {
'id': '',
'name': ''
},
'default_ccc_account': {
'id': '1',
'name': 'Elon musk'
},
'default_ccc_vendor': {
'id': '',
'name': ''
}
}
},
'export_settings_missing_values_expense_group_settings': {
'configurations': {
'reimbursable_expenses_object': 'EXPENSE_REPORT',
'corporate_credit_card_expenses_object': 'CHARGE_CARD_TRANSACTION',
'auto_map_employees': 'NAME',
'is_simplify_report_closure_enabled': False,
'employee_field_mapping': 'EMPLOYEE'
},
'expense_group_settings': {},
'general_mappings': {
'reimbursable_account': {
'id': '',
'name': ''
},
'accounts_payable': {
'id': '',
'name': ''
},
'default_ccc_account': {
'id': '1',
'name': 'Elon musk'
},
'default_ccc_vendor': {
'id': '',
'name': ''
}
}
},
'export_settings_missing_values_general_mappings': {
'configurations': {
'reimbursable_expenses_object': 'EXPENSE_REPORT',
'corporate_credit_card_expenses_object': 'CHARGE_CARD_TRANSACTION',
'auto_map_employees': 'NAME',
'is_simplify_report_closure_enabled': False,
'employee_field_mapping': 'EMPLOYEE'
},
'expense_group_settings': {
'reimbursable_expense_group_fields': [
'fund_source',
'employee_email',
'claim_number',
'report_id'
],
'reimbursable_export_date_type': 'current_date',
'expense_state': 'PAYMENT_PROCESSING',
'corporate_credit_card_expense_group_fields': [
'fund_source',
'claim_number',
'employee_email',
'report_id',
'spent_at',
'expense_id'
],
'ccc_export_date_type': 'spent_at',
'ccc_expense_state': 'PAID'
},
'general_mappings': {}
}
}
83 changes: 83 additions & 0 deletions tests/test_workspaces/test_apis/test_export_settings/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import json
from tests.helper import dict_compare_keys
from apps.workspaces.models import Workspace, Configuration
from .fixtures import data
import pytest
from django.urls import reverse

@pytest.mark.django_db(databases=['default'])
def test_export_settings(api_client, access_token):

workspace = Workspace.objects.get(id=1)
workspace.onboarding_state = 'EXPORT_SETTINGS'
workspace.save()

url = reverse(
'export-settings', kwargs={
'workspace_id': 1
}
)

api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))
response = api_client.put(
url,
data=data['export_settings'],
format='json'
)

assert response.status_code == 200

response = json.loads(response.content)
workspace = Workspace.objects.get(id=1)

assert dict_compare_keys(response, data['response']) == [], 'workspaces api returns a diff in the keys'
assert workspace.onboarding_state == 'IMPORT_SETTINGS'

url = '/api/v2/workspaces/1/export_settings/'
api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))

payload = data['export_settings']
payload['expense_group_settings']['reimbursable_expense_group_fields'] = []
payload['expense_group_settings']['corporate_credit_card_expense_group_fields'] = []
payload['expense_group_settings']['reimbursable_export_date_type'] = ''
payload['expense_group_settings']['ccc_export_date_type'] = ''

response = api_client.put(
url,
data=payload,
format='json'
)

assert response.status_code == 200

response = json.loads(response.content)
workspace = Workspace.objects.get(id=1)

assert dict_compare_keys(response, data['response']) == [], 'workspaces api returns a diff in the keys'

invalid_configurations = data['export_settings_missing_values_configurations']
response = api_client.put(
url,
data=invalid_configurations,
format='json'
)

assert response.status_code == 400

invalid_expense_group_settings = data['export_settings_missing_values_expense_group_settings']
response = api_client.put(
url,
data=invalid_expense_group_settings,
format='json'
)

assert response.status_code == 400

invalid_general_mappings = data['export_settings_missing_values_general_mappings']
response = api_client.put(
url,
data=invalid_general_mappings,
format='json'
)

assert response.status_code == 400

0 comments on commit e9a0b17

Please sign in to comment.