diff --git a/apps/workspaces/apis/urls.py b/apps/workspaces/apis/urls.py index 0bbdc06e..fc9b312a 100644 --- a/apps/workspaces/apis/urls.py +++ b/apps/workspaces/apis/urls.py @@ -5,6 +5,6 @@ urlpatterns = [ - path('/map_employees/', MapEmployeesView.as_view()), - path('/export_settings/', ExportSettingsView.as_view()), + path('/map_employees/', MapEmployeesView.as_view(), name='map-employees'), + path('/export_settings/', ExportSettingsView.as_view(), name='export-settings'), ] diff --git a/tests/test_workspaces/test_apis/__init__.py b/tests/test_workspaces/test_apis/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_workspaces/test_apis/test_export_settings/__init__.py b/tests/test_workspaces/test_apis/test_export_settings/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_workspaces/test_apis/test_export_settings/fixtures.py b/tests/test_workspaces/test_apis/test_export_settings/fixtures.py new file mode 100644 index 00000000..18a01fec --- /dev/null +++ b/tests/test_workspaces/test_apis/test_export_settings/fixtures.py @@ -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': {} + } +} diff --git a/tests/test_workspaces/test_apis/test_export_settings/test_views.py b/tests/test_workspaces/test_apis/test_export_settings/test_views.py new file mode 100644 index 00000000..203c154e --- /dev/null +++ b/tests/test_workspaces/test_apis/test_export_settings/test_views.py @@ -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