From 3862c7d8513e2bfa6a68fb36b32440767b76512f Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Wed, 5 Jun 2024 07:32:21 +0530 Subject: [PATCH] feat: remove erpt from deep link redirection page and clean up report code (#3037) --- src/app/core/mock-data/api-reports.data.ts | 732 ------------------ src/app/core/mock-data/stats-response.data.ts | 328 +------- src/app/core/services/report.service.spec.ts | 608 +-------------- src/app/core/services/report.service.ts | 354 +-------- src/app/core/services/tasks.service.spec.ts | 7 +- .../core/services/transaction.service.spec.ts | 1 - .../deep-link-redirection.page.spec.ts | 29 +- .../deep-link-redirection.page.ts | 48 +- .../fyle/my-expenses/my-expenses.page.spec.ts | 1 - .../view-expense/view-expense.page.spec.ts | 1 - 10 files changed, 56 insertions(+), 2053 deletions(-) diff --git a/src/app/core/mock-data/api-reports.data.ts b/src/app/core/mock-data/api-reports.data.ts index 6f86a2b8a8..06cce9cc65 100644 --- a/src/app/core/mock-data/api-reports.data.ts +++ b/src/app/core/mock-data/api-reports.data.ts @@ -233,735 +233,3 @@ export const apiReportRes: ApiV2Response = deepFreeze({ offset: 0, url: '/v2/reports', }); - -export const apiReportSingleRes: ApiV2Response = deepFreeze({ - count: 1, - data: [ - { - _search_document: - "'145':5 'a':8 'abhishek':10 'ajain@fyle.in':12 'bangalore':9 'c/2023/01/r/31':6 'columns':3 'inr':4 'jain':11 'lion':7 'manage':2 'test':1", - approved_by: ['out3t2X258rd'], - ou_business_unit: null, - ou_department: 'Primary Sales', - ou_department_id: 'deptSdAUA5Urej', - ou_employee_id: 'A', - ou_id: 'ouCI4UQ2G0K1', - ou_level: 123, - ou_level_id: 'lvlEtPwKjAF6U', - ou_location: 'bangalore', - ou_mobile: null, - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: 'Primary Sales', - ou_title: 'lion', - report_approvals: { - out3t2X258rd: { - rank: 0, - state: 'APPROVAL_PENDING', - }, - }, - rp_amount: 145, - rp_approval_state: null, - rp_approved_at: null, - rp_claim_number: 'C/2023/01/R/31', - rp_created_at: new Date('2023-01-19T07:27:33.235573'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpfClhA1lglE', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 3, - rp_org_user_id: 'ouCI4UQ2G0K1', - rp_policy_flag: false, - rp_purpose: 'test_manage_columns', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'WEBAPP', - rp_state: 'APPROVER_PENDING', - rp_submitted_at: new Date('2023-01-19T07:27:36.879'), - rp_tax: 15.54, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - ], - limit: 1, - offset: 0, - url: '/v2/reports', -}); - -export const expectedReports: ApiV2Response = deepFreeze({ - count: 4, - data: [ - { - _search_document: - "'0':5 '2023':3 '5':1 'a':9,15,21,27 'abhishek':33 'ajain@fyle.in':35 'business':12,18,24,30 'c/2023/01/r/11':6 'director':7 'indeed':14,20,26,32 'inr':4 'jain':34 'jan':2 'long':11,17,23,29 'mumbai':8 'unit':13,19,25,31 'very':10,16,22,28", - approved_by: null, - ou_business_unit: - 'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed', - ou_department: '0000000', - ou_department_id: 'deptpmQ0SsMO0S', - ou_employee_id: '', - ou_id: 'ouX8dwsbLCLv', - ou_level: 123, - ou_level_id: 'lvlPtroPaClQy', - ou_location: 'Mumbai', - ou_mobile: '123456', - ou_org_id: 'orNVthTo2Zyo', - ou_org_name: 'Staging Loaded', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'director', - report_approvals: null, - rp_amount: 0, - rp_approval_state: null, - rp_approved_at: null, - rp_claim_number: 'C/2023/01/R/11', - rp_created_at: new Date('2023-01-17T06:35:06.814556'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpFE5X1Pqi9P', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 0, - rp_org_user_id: 'ouX8dwsbLCLv', - rp_policy_flag: false, - rp_purpose: '#5: Jan 2023', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'MOBILE', - rp_state: 'DRAFT', - rp_submitted_at: null, - rp_tax: null, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - { - _search_document: - "'2023':3 '4':1 '9400':5 'a':9,15,21,27 'abhishek':33 'ajain@fyle.in':35 'business':12,18,24,30 'c/2023/01/r/10':6 'director':7 'indeed':14,20,26,32 'inr':4 'jain':34 'jan':2 'long':11,17,23,29 'mumbai':8 'unit':13,19,25,31 'very':10,16,22,28", - approved_by: ['ouX8dwsbLCLv'], - ou_business_unit: - 'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed', - ou_department: '0000000', - ou_department_id: 'deptpmQ0SsMO0S', - ou_employee_id: '', - ou_id: 'ouX8dwsbLCLv', - ou_level: 123, - ou_level_id: 'lvlPtroPaClQy', - ou_location: 'Mumbai', - ou_mobile: '123456', - ou_org_id: 'orNVthTo2Zyo', - ou_org_name: 'Staging Loaded', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'director', - report_approvals: { - ouX8dwsbLCLv: { - rank: 99, - state: 'APPROVAL_PENDING', - }, - }, - rp_amount: 9400, - rp_approval_state: 'APPROVAL_PENDING', - rp_approved_at: null, - rp_claim_number: 'C/2023/01/R/10', - rp_created_at: new Date('2023-01-17T06:34:58.398683'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpSGcIEwzxDd', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 4, - rp_org_user_id: 'ouX8dwsbLCLv', - rp_policy_flag: true, - rp_purpose: '#4: Jan 2023', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'WEBAPP', - rp_state: 'APPROVER_INQUIRY', - rp_submitted_at: new Date('2023-01-17T06:34:59.523'), - rp_tax: 1152.3, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: true, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - { - _search_document: - "'2023':3 '324':5 '4':1 'a':9,15,21,27 'abhishek':33 'ajain@fyle.in':35 'business':12,18,24,30 'c/2023/01/r/9':6 'director':7 'indeed':14,20,26,32 'inr':4 'jain':34 'jan':2 'long':11,17,23,29 'mumbai':8 'unit':13,19,25,31 'very':10,16,22,28", - approved_by: ['ouX8dwsbLCLv'], - ou_business_unit: - 'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed', - ou_department: '0000000', - ou_department_id: 'deptpmQ0SsMO0S', - ou_employee_id: '', - ou_id: 'ouX8dwsbLCLv', - ou_level: 123, - ou_level_id: 'lvlPtroPaClQy', - ou_location: 'Mumbai', - ou_mobile: '123456', - ou_org_id: 'orNVthTo2Zyo', - ou_org_name: 'Staging Loaded', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'director', - report_approvals: { - ouX8dwsbLCLv: { - rank: 99, - state: 'APPROVAL_DONE', - }, - }, - rp_amount: 324, - rp_approval_state: 'APPROVAL_DONE', - rp_approved_at: new Date('2023-01-17T06:33:29.049'), - rp_claim_number: 'C/2023/01/R/9', - rp_created_at: new Date('2023-01-13T07:29:00.963045'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpGpzBpAxtSn', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 1, - rp_org_user_id: 'ouX8dwsbLCLv', - rp_policy_flag: false, - rp_purpose: '#4: Jan 2023', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'WORKFLOWS', - rp_state: 'APPROVED', - rp_submitted_at: new Date('2023-01-13T07:29:01.135'), - rp_tax: 49.42, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - { - _search_document: - "'10121.24':5 '2022':3 '24':1 'a':9,15,21,27 'abhishek':33 'ajain@fyle.in':35 'business':12,18,24,30 'c/2022/12/r/34':6 'dec':2 'director':7 'indeed':14,20,26,32 'inr':4 'jain':34 'long':11,17,23,29 'mumbai':8 'unit':13,19,25,31 'very':10,16,22,28", - approved_by: ['ouX8dwsbLCLv'], - ou_business_unit: - 'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed', - ou_department: '0000000', - ou_department_id: 'deptpmQ0SsMO0S', - ou_employee_id: '', - ou_id: 'ouX8dwsbLCLv', - ou_level: 123, - ou_level_id: 'lvlPtroPaClQy', - ou_location: 'Mumbai', - ou_mobile: '123456', - ou_org_id: 'orNVthTo2Zyo', - ou_org_name: 'Staging Loaded', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'director', - report_approvals: { - ouX8dwsbLCLv: { - rank: 99, - state: 'APPROVAL_PENDING', - }, - }, - rp_amount: 10121.24, - rp_approval_state: 'APPROVAL_PENDING', - rp_approved_at: null, - rp_claim_number: 'C/2022/12/R/34', - rp_created_at: new Date('2022-12-26T07:29:00.734031'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpFkJ6jUJOyg', - rp_locations: [], - rp_manual_flag: true, - rp_num_transactions: 3, - rp_org_user_id: 'ouX8dwsbLCLv', - rp_policy_flag: false, - rp_purpose: '#24: Dec 2022', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'WORKFLOWS', - rp_state: 'APPROVER_PENDING', - rp_submitted_at: new Date('2022-12-26T07:29:01.743'), - rp_tax: 305.08, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: true, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - ], - limit: 4, - offset: 0, - url: '/v2/reports', -}); - -export const apiAllReportsRes1: ApiV2Response = deepFreeze({ - count: 2, - data: [ - { - _search_document: - "'0':5 '2023':3 '4':1 'a':8 'abhishek':10 'ajain@fyle.in':12 'bangalore':9 'c/2023/02/r/5':6 'feb':2 'inr':4 'jain':11 'lion':7", - approved_by: null, - ou_business_unit: null, - ou_department: 'Primary Sales', - ou_department_id: 'deptSdAUA5Urej', - ou_employee_id: 'A', - ou_id: 'ouCI4UQ2G0K1', - ou_level: 123, - ou_level_id: 'lvlEtPwKjAF6U', - ou_location: 'bangalore', - ou_mobile: null, - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: 'Primary Sales', - ou_title: 'lion', - report_approvals: null, - rp_amount: 0, - rp_approval_state: null, - rp_approved_at: null, - rp_claim_number: 'C/2023/02/R/5', - rp_created_at: new Date('2023-02-01T00:23:42.505Z'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpkkdCNBFsJ2', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 0, - rp_org_user_id: 'ouCI4UQ2G0K1', - rp_policy_flag: false, - rp_purpose: '#4: Feb 2023', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'MOBILE', - rp_state: 'APPROVER_PENDING', - rp_submitted_at: new Date('2023-02-01T00:23:46.556Z'), - rp_tax: 0, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - { - _search_document: - "'16370.8':5 '2023':3 '4':1 'a':8 'abhishek':10 'ajain@fyle.in':12 'bangalore':9 'c/2023/02/r/4':6 'feb':2 'inr':4 'jain':11 'lion':7", - approved_by: null, - ou_business_unit: null, - ou_department: 'Primary Sales', - ou_department_id: 'deptSdAUA5Urej', - ou_employee_id: 'A', - ou_id: 'ouCI4UQ2G0K1', - ou_level: 123, - ou_level_id: 'lvlEtPwKjAF6U', - ou_location: 'bangalore', - ou_mobile: null, - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: 'Primary Sales', - ou_title: 'lion', - report_approvals: null, - rp_amount: 16370.8, - rp_approval_state: null, - rp_approved_at: null, - rp_claim_number: 'C/2023/02/R/4', - rp_created_at: new Date('2023-02-01T00:23:42.495Z'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpNiAxUFhUlo', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 1, - rp_org_user_id: 'ouCI4UQ2G0K1', - rp_policy_flag: false, - rp_purpose: '#4: Feb 2023', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'MOBILE', - rp_state: 'DRAFT', - rp_submitted_at: null, - rp_tax: 15509.18, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - ], - limit: 2, - offset: 0, - url: '/v2/reports', -}); - -export const apiAllReportsRes2: ApiV2Response = deepFreeze({ - count: 1, - data: [ - { - _search_document: - "'0':5 '2023':3 '5':1 'a':9,15,21,27 'abhishek':33 'ajain@fyle.in':35 'business':12,18,24,30 'c/2023/01/r/11':6 'director':7 'indeed':14,20,26,32 'inr':4 'jain':34 'jan':2 'long':11,17,23,29 'mumbai':8 'unit':13,19,25,31 'very':10,16,22,28", - approved_by: null, - ou_business_unit: - 'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed', - ou_department: '0000000', - ou_department_id: 'deptpmQ0SsMO0S', - ou_employee_id: '', - ou_id: 'ouX8dwsbLCLv', - ou_level: 123, - ou_level_id: 'lvlPtroPaClQy', - ou_location: 'Mumbai', - ou_mobile: '123456', - ou_org_id: 'orNVthTo2Zyo', - ou_org_name: 'Staging Loaded', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'director', - report_approvals: null, - rp_amount: 0, - rp_approval_state: null, - rp_approved_at: null, - rp_claim_number: 'C/2023/01/R/11', - rp_created_at: new Date('2023-01-17T01:05:06.814Z'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rpFE5X1Pqi9P', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 0, - rp_org_user_id: 'ouX8dwsbLCLv', - rp_policy_flag: false, - rp_purpose: '#5: Jan 2023', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: null, - rp_source: 'MOBILE', - rp_state: 'DRAFT', - rp_submitted_at: null, - rp_tax: null, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'ajain@fyle.in', - us_full_name: 'Abhishek Jain', - }, - ], - limit: 2, - offset: 2, - url: '/v2/reports', -}); - -export const apiTeamRptCountRes: ApiV2Response = deepFreeze({ - count: 25, - data: [ - { - _search_document: - "'8000':5 'aniruddha':7,9 'aniruddha.s@fyle.in':10 'c/2022/12/r/5':6 'dec':2 'inr':4 'kalyan':8 'new':1 'test':3", - approved_by: ['ouCI4UQ2G0K1'], - ou_business_unit: null, - ou_department: 'AniruddhaDept', - ou_department_id: 'deptJ2gTm72zsW', - ou_employee_id: null, - ou_id: 'ouWizR8UqaV9', - ou_level: 123, - ou_level_id: 'lvlBmu2wZ6oiC', - ou_location: 'Kalyan', - ou_mobile: '', - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'aniruddha', - report_approvals: { - ouCI4UQ2G0K1: { - rank: 0, - state: 'APPROVAL_DONE', - }, - ouyy40tyFnrP: { - rank: 0, - state: 'APPROVAL_DISABLED', - }, - }, - rp_amount: 8000, - rp_approval_state: 'APPROVAL_DONE', - rp_approved_at: new Date('2022-12-14T11:08:19.326'), - rp_claim_number: 'C/2022/12/R/5', - rp_created_at: new Date('2022-12-14T11:07:55.171487'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rphNNUiCISkD', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 1, - rp_org_user_id: 'ouWizR8UqaV9', - rp_policy_flag: false, - rp_purpose: 'New Dec Test', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: 'setU28WgLt5ia', - rp_source: 'WEBAPP', - rp_state: 'PAYMENT_PROCESSING', - rp_submitted_at: new Date('2022-12-14T11:07:55.614'), - rp_tax: 857.14, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: 'VERIFIED', - rp_verified: true, - sequential_approval_turn: false, - us_email: 'aniruddha.s@fyle.in', - us_full_name: 'aniruddha', - }, - ], - limit: 1, - offset: 0, - url: '/v2/reports', -}); - -export const apiTeamRptSingleRes: ApiV2Response = deepFreeze({ - count: 1, - data: [ - { - _search_document: - "'8000':5 'aniruddha':7,9 'aniruddha.s@fyle.in':10 'c/2022/12/r/5':6 'dec':2 'inr':4 'kalyan':8 'new':1 'test':3", - approved_by: ['ouCI4UQ2G0K1'], - ou_business_unit: null, - ou_department: 'AniruddhaDept', - ou_department_id: 'deptJ2gTm72zsW', - ou_employee_id: null, - ou_id: 'ouWizR8UqaV9', - ou_level: 123, - ou_level_id: 'lvlBmu2wZ6oiC', - ou_location: 'Kalyan', - ou_mobile: '', - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'aniruddha', - report_approvals: { - ouCI4UQ2G0K1: { - rank: 0, - state: 'APPROVAL_DONE', - }, - ouyy40tyFnrP: { - rank: 0, - state: 'APPROVAL_DISABLED', - }, - }, - rp_amount: 8000, - rp_approval_state: 'APPROVAL_DONE', - rp_approved_at: new Date('2022-12-14T11:08:19.326'), - rp_claim_number: 'C/2022/12/R/5', - rp_created_at: new Date('2022-12-14T11:07:55.171487'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rphNNUiCISkD', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 1, - rp_org_user_id: 'ouWizR8UqaV9', - rp_policy_flag: false, - rp_purpose: 'New Dec Test', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: 'setU28WgLt5ia', - rp_source: 'WEBAPP', - rp_state: 'PAYMENT_PROCESSING', - rp_submitted_at: new Date('2022-12-14T11:07:55.614'), - rp_tax: 857.14, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: 'VERIFIED', - rp_verified: true, - sequential_approval_turn: false, - us_email: 'aniruddha.s@fyle.in', - us_full_name: 'aniruddha', - }, - ], - limit: 1, - offset: 0, - url: '/v2/reports', -}); - -export const apiTeamReportPaginated1: ApiV2Response = deepFreeze({ - count: 25, - data: [ - { - _search_document: - "'8000':5 'aniruddha':7,9 'aniruddha.s@fyle.in':10 'c/2022/12/r/5':6 'dec':2 'inr':4 'kalyan':8 'new':1 'test':3", - approved_by: ['ouCI4UQ2G0K1'], - ou_business_unit: null, - ou_department: 'AniruddhaDept', - ou_department_id: 'deptJ2gTm72zsW', - ou_employee_id: null, - ou_id: 'ouWizR8UqaV9', - ou_level: 123, - ou_level_id: 'lvlBmu2wZ6oiC', - ou_location: 'Kalyan', - ou_mobile: '', - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'aniruddha', - report_approvals: { - ouCI4UQ2G0K1: { - rank: 0, - state: 'APPROVAL_DONE', - }, - ouyy40tyFnrP: { - rank: 0, - state: 'APPROVAL_DISABLED', - }, - }, - rp_amount: 8000, - rp_approval_state: 'APPROVAL_DONE', - rp_approved_at: new Date('2022-12-14T11:08:19.326'), - rp_claim_number: 'C/2022/12/R/5', - rp_created_at: new Date('2022-12-14T11:07:55.171487'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rphNNUiCISkD', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 1, - rp_org_user_id: 'ouWizR8UqaV9', - rp_policy_flag: false, - rp_purpose: 'New Dec Test', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: 'setU28WgLt5ia', - rp_source: 'WEBAPP', - rp_state: 'PAYMENT_PROCESSING', - rp_submitted_at: new Date('2022-12-14T11:07:55.614'), - rp_tax: 857.14, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: 'VERIFIED', - rp_verified: true, - sequential_approval_turn: false, - us_email: 'aniruddha.s@fyle.in', - us_full_name: 'aniruddha', - }, - { - _search_document: - "'10000':5 '2':1 '2022':3 'aniruddha':7,9 'aniruddha.s@fyle.in':10 'c/2022/12/r/4':6 'dec':2 'inr':4 'kalyan':8", - approved_by: ['ouCI4UQ2G0K1'], - ou_business_unit: null, - ou_department: 'AniruddhaDept', - ou_department_id: 'deptJ2gTm72zsW', - ou_employee_id: null, - ou_id: 'ouWizR8UqaV9', - ou_level: 123, - ou_level_id: 'lvlBmu2wZ6oiC', - ou_location: 'Kalyan', - ou_mobile: '', - ou_org_id: 'orrjqbDbeP9p', - ou_org_name: 'Fyle Staging', - ou_status: '"ACTIVE"', - ou_sub_department: null, - ou_title: 'aniruddha', - report_approvals: { - ouCI4UQ2G0K1: { - rank: 0, - state: 'APPROVAL_DONE', - }, - }, - rp_amount: 10000, - rp_approval_state: 'APPROVAL_DONE', - rp_approved_at: new Date('2022-12-14T10:46:29'), - rp_claim_number: 'C/2022/12/R/4', - rp_created_at: new Date('2022-12-14T10:46:17.921477'), - rp_currency: 'USD', - rp_exported: false, - rp_from_dt: null, - rp_id: 'rp8Y2OcgHjWB', - rp_locations: [], - rp_manual_flag: false, - rp_num_transactions: 1, - rp_org_user_id: 'ouWizR8UqaV9', - rp_policy_flag: false, - rp_purpose: '#2: Dec 2022', - rp_reimbursed_at: null, - rp_risk_state: null, - rp_risk_state_expense_count: null, - rp_settlement_id: 'setMGTXVLS0Nw', - rp_source: 'WEBAPP', - rp_state: 'PAYMENT_PROCESSING', - rp_submitted_at: new Date('2022-12-14T10:46:18.336'), - rp_tax: 9473.68, - rp_to_dt: null, - rp_trip_request_id: null, - rp_type: 'EXPENSE', - rp_verification_state: null, - rp_verified: false, - sequential_approval_turn: false, - us_email: 'aniruddha.s@fyle.in', - us_full_name: 'aniruddha', - }, - ], - limit: 10, - offset: 0, - url: '/v2/reports', -}); diff --git a/src/app/core/mock-data/stats-response.data.ts b/src/app/core/mock-data/stats-response.data.ts index 64232096de..38ba6f6df6 100644 --- a/src/app/core/mock-data/stats-response.data.ts +++ b/src/app/core/mock-data/stats-response.data.ts @@ -1,6 +1,4 @@ -import deepFreeze from 'deep-freeze-strict'; - -import { Datum, StatsResponse } from '../models/v2/stats-response.model'; +import { StatsResponse } from '../models/v2/stats-response.model'; // type StatsResponse = { // data: { // dimensions: string[]; @@ -15,192 +13,6 @@ import { Datum, StatsResponse } from '../models/v2/stats-response.model'; // aggregates?: string; // }; -export const apiReportStatsRes = new StatsResponse({ - data: [ - { - dimensions: ['rp_state'], - name: '1', - value: [ - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 28758273650702.816, - }, - { - function_name: 'count(rp_id)', - function_value: 56, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'APPROVED', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 642147.297922, - }, - { - function_name: 'count(rp_id)', - function_value: 2, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'APPROVER_INQUIRY', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 5177243929.65219, - }, - { - function_name: 'count(rp_id)', - function_value: 45, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'APPROVER_PENDING', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 93165.91, - }, - { - function_name: 'count(rp_id)', - function_value: 6, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'DRAFT', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 1221297040.1711, - }, - { - function_name: 'count(rp_id)', - function_value: 33, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'PAID', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 501602.12, - }, - { - function_name: 'count(rp_id)', - function_value: 4, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'PAYMENT_PENDING', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 5012.12, - }, - { - function_name: 'count(rp_id)', - function_value: 7, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'PAYMENT_PROCESSING', - }, - ], - }, - ], - }, - ], - url: '/v2/reports/stats', -}); - -export const apiReportStatsEmptyRes = new StatsResponse({ - data: [ - { - dimensions: ['rp_state'], - name: '1', - value: [ - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 642147.297922, - }, - { - function_name: 'count(rp_id)', - function_value: 2, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'APPROVER_INQUIRY', - }, - ], - }, - { - aggregates: [ - { - function_name: 'sum(rp_amount)', - function_value: 1221297040.1711, - }, - { - function_name: 'count(rp_id)', - function_value: 33, - }, - ], - key: [ - { - column_name: 'rp_state', - column_value: 'PAID', - }, - ], - }, - ], - }, - ], - url: '/v2/reports/stats', -}); - export const apiAssignedCardDetailsRes = new StatsResponse({ data: [ { @@ -278,141 +90,3 @@ export const apiAssignedCardDetailsRes = new StatsResponse({ ], url: '/v2/expenses_and_ccce/stats', }); - -export const apiReportStatsRawRes = new StatsResponse({ - data: [ - { - aggregates: [ - { - function_name: 'count(rp_id)', - function_value: 3, - }, - { - function_name: 'sum(rp_amount)', - function_value: 2804.2892810000003, - }, - ], - dimensions: [], - name: 'scalar_stat', - }, - ], - url: '/v2/reports/stats', -}); - -export const txnStats = new StatsResponse({ - data: [ - { - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 8, - }, - { - function_name: 'sum(tx_amount)', - function_value: 10583.73, - }, - ], - dimensions: [], - name: 'scalar_stat', - }, - ], - url: '/v2/expenses/stats', -}); - -export const transactionDatum1: Datum[] = deepFreeze([ - { - name: '', - dimensions: [], - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 4, - }, - { - function_name: 'sum(tx_amount)', - function_value: 3494, - }, - ], - }, - { - name: '', - dimensions: [], - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 964, - }, - { - function_name: 'sum(tx_amount)', - function_value: 568437, - }, - ], - }, - { - name: '', - dimensions: [], - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 5, - }, - { - function_name: 'sum(tx_amount)', - function_value: 371.87, - }, - ], - }, -]); - -export const transactionDatum2: Datum[] = deepFreeze([ - { - name: '', - dimensions: [], - aggregates: [], - }, - { - name: '', - dimensions: [], - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 964, - }, - { - function_name: 'sum(tx_amount)', - function_value: 568437, - }, - ], - }, - { - name: '', - dimensions: [], - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 5, - }, - { - function_name: 'sum(tx_amount)', - function_value: 371.87, - }, - ], - }, -]); - -export const transactionDatum3: Datum[] = deepFreeze([ - { - name: '', - dimensions: [], - aggregates: [ - { - function_name: 'count(tx_id)', - function_value: 4, - }, - { - function_name: 'sum(tx_amount)', - function_value: null, - }, - ], - }, -]); diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index 46019fe398..d1dad1dcbb 100644 --- a/src/app/core/services/report.service.spec.ts +++ b/src/app/core/services/report.service.spec.ts @@ -3,17 +3,7 @@ import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service'; import { DatePipe } from '@angular/common'; import { of } from 'rxjs'; import { PAGINATION_SIZE } from 'src/app/constants'; -import { apiReportStatsRawRes, apiReportStatsRes } from '../../core/mock-data/stats-response.data'; import { reportAllowedActionsResponse } from '../mock-data/allowed-actions.data'; -import { - apiReportRes, - apiReportSingleRes, - apiTeamRptCountRes, - apiTeamRptSingleRes, - apiTeamReportPaginated1, - apiAllReportsRes1, - apiAllReportsRes2, -} from '../mock-data/api-reports.data'; import { approversData1, apiAllApproverRes1, @@ -23,22 +13,10 @@ import { approversData2, approversData3, } from '../mock-data/approver.data'; -import { apiExpenseRes } from '../mock-data/expense.data'; import { apiEouRes } from '../mock-data/extended-org-user.data'; import { orgSettingsRes } from '../mock-data/org-settings.data'; import { apiReportAutoSubmissionDetails } from '../mock-data/report-auto-submission-details.data'; -import { - expectedErpt, - expectedSingleErpt, - unflattenedErptc, - unflattenedErptcArrayItem1, - unflattenedErptcArrayItem2, - unflattenedErptcArrayItem3, - unflattenedErptcArrayItem4, - singleERptcFixDatesMock, - addApproverERpts, - expectedAddedApproverERpts, -} from '../mock-data/report-unflattened.data'; +import { addApproverERpts, expectedAddedApproverERpts } from '../mock-data/report-unflattened.data'; import { reportUnflattenedData, reportUnflattenedData2, @@ -233,256 +211,6 @@ describe('ReportService', () => { }); }); - describe('getMyReports()', () => { - it('should get reports from API as specified by params', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - apiv2Service.get.and.returnValue(of(apiReportRes)); - spyOn(dateService, 'fixDates').and.returnValues( - apiReportRes.data[0], - apiReportRes.data[1], - apiReportRes.data[2], - apiReportRes.data[3] - ); - - const params = { - offset: 0, - limit: 10, - queryParams: { - or: [], - }, - order: 'rp_created_at.desc', - }; - - const apiParams = { - offset: 0, - limit: 10, - order: 'rp_created_at.desc,rp_id.desc', - rp_org_user_id: 'eq.ouX8dwsbLCLv', - or: [], - }; - - reportService.getMyReports(params).subscribe((res) => { - expect(res).toEqual(apiReportRes); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports', { params: apiParams }); - done(); - }); - }); - - it('should get reports from API when no order is specified', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - apiv2Service.get.and.returnValue(of(apiReportRes)); - spyOn(dateService, 'fixDates').and.returnValues( - apiReportRes.data[0], - apiReportRes.data[1], - apiReportRes.data[2], - apiReportRes.data[3] - ); - - const params = { - offset: 0, - limit: 10, - queryParams: { - or: [], - }, - }; - - const apiParams = { - offset: 0, - limit: 10, - order: 'rp_created_at.desc,rp_id.desc', - rp_org_user_id: 'eq.ouX8dwsbLCLv', - or: [], - }; - - reportService.getMyReports(params).subscribe((res) => { - expect(res).toEqual(apiReportRes); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports', { params: apiParams }); - done(); - }); - }); - }); - - it('getPaginatedERptc(): should get paginated extended-reports', (done) => { - apiService.get.and.returnValue(of(apiExtendedReportRes)); - dataTransformService.unflatten.and.returnValues( - unflattenedErptcArrayItem1, - unflattenedErptcArrayItem2, - unflattenedErptcArrayItem3, - unflattenedErptcArrayItem4 - ); - const params = { - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }; - - const apiParams = { - params: { - offset: 0, - limit: 4, - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }, - }; - - reportService.getPaginatedERptc(0, apiExtendedReportRes.length, params).subscribe((res) => { - expect(res).toEqual(expectedErpt); - expect(apiService.get).toHaveBeenCalledOnceWith('/erpts', apiParams); - expect(dataTransformService.unflatten).toHaveBeenCalledTimes(4); - done(); - }); - }); - - it('getERpt(): should get an extended report', (done) => { - apiService.get.and.returnValue(of(apiExtendedReportRes[0])); - const mockUnflattenedErptc = cloneDeep(unflattenedErptc); - dataTransformService.unflatten.and.returnValue(mockUnflattenedErptc); - spyOn(dateService, 'fixDates').and.returnValue(singleERptcFixDatesMock); - spyOn(dateService, 'getLocalDate').and.returnValue(new Date('2023-01-21T07:29:01.958Z')); - - const reportID = 'rprAfNrce73O'; - - reportService.getERpt(reportID).subscribe((res) => { - expect(res).toEqual(expectedSingleErpt); - expect(apiService.get).toHaveBeenCalledOnceWith(`/erpts/${reportID}`); - expect(dataTransformService.unflatten).toHaveBeenCalledOnceWith(apiExtendedReportRes[0]); - expect(dateService.fixDates).toHaveBeenCalledOnceWith(unflattenedErptc.rp); - expect(dateService.getLocalDate).toHaveBeenCalledOnceWith(unflattenedErptc.rp.created_at); - done(); - }); - }); - - it('getMyReportsCount(): should get reports count', (done) => { - spyOn(reportService, 'getMyReports').and.returnValue(of(apiReportRes)); - - const param = { - offset: 0, - limit: 1, - queryParams: {}, - }; - - reportService.getMyReportsCount().subscribe((res) => { - expect(res).toEqual(4); - expect(reportService.getMyReports).toHaveBeenCalledOnceWith(param); - done(); - }); - }); - - it('getReport(): should get the report from API as per report ID given', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - spyOn(reportService, 'getMyReports').and.returnValue(of(apiReportSingleRes)); - - const reportID = 'rpfClhA1lglE'; - - const params = { - offset: 0, - limit: 1, - queryParams: { - rp_id: `eq.${reportID}`, - }, - }; - - reportService.getReport(reportID).subscribe((res) => { - expect(res).toEqual(expectedReportSingleResponse); - expect(reportService.getMyReports).toHaveBeenCalledOnceWith(params); - done(); - }); - }); - - it('getTeamReportsCount(): should get a count of team reports', (done) => { - spyOn(reportService, 'getTeamReports').and.returnValue(of(apiTeamRptCountRes)); - - const params = { - offset: 0, - limit: 1, - queryParams: {}, - }; - - reportService.getTeamReportsCount().subscribe((res) => { - expect(res).toEqual(25); - expect(reportService.getTeamReports).toHaveBeenCalledOnceWith(params); - done(); - }); - }); - - describe('getTeamReports()', () => { - it('should get all team reports', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - apiv2Service.get.and.returnValue(of(apiTeamReportPaginated1)); - spyOn(dateService, 'fixDates').and.returnValues(apiTeamReportPaginated1.data[0], apiTeamReportPaginated1.data[1]); - - const params = { - offset: 0, - limit: 10, - queryParams: { - or: [], - }, - order: 'rp_submitted_at.desc', - }; - - reportService.getTeamReports(params).subscribe((res) => { - expect(res).toEqual(apiTeamReportPaginated1); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports', { - params: { - offset: 0, - limit: 10, - approved_by: 'cs.{ouX8dwsbLCLv}', - order: 'rp_submitted_at.desc,rp_id.desc', - or: [], - }, - }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - done(); - }); - }); - - it('should get all team reports when order is not specified', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - apiv2Service.get.and.returnValue(of(apiTeamReportPaginated1)); - spyOn(dateService, 'fixDates').and.returnValues(apiTeamReportPaginated1.data[0], apiTeamReportPaginated1.data[1]); - - const params = { - offset: 0, - limit: 10, - queryParams: { - or: [], - }, - }; - - reportService.getTeamReports(params).subscribe((res) => { - expect(res).toEqual(apiTeamReportPaginated1); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports', { - params: { - offset: 0, - limit: 10, - approved_by: 'cs.{ouX8dwsbLCLv}', - order: 'rp_created_at.desc,rp_id.desc', - or: [], - }, - }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - done(); - }); - }); - }); - - it('getTeamReport(): should get a team report', (done) => { - spyOn(reportService, 'getTeamReports').and.returnValue(of(apiTeamRptSingleRes)); - - const reportID = 'rphNNUiCISkD'; - - const params = { - offset: 0, - limit: 1, - queryParams: { - rp_id: `eq.${reportID}`, - }, - }; - - reportService.getTeamReport(reportID).subscribe((res) => { - expect(res).toEqual(apiTeamRptSingleRes.data[0]); - expect(reportService.getTeamReports).toHaveBeenCalledOnceWith(params); - done(); - }); - }); - it('getExports(): should get export actions for a report', (done) => { apiService.get.and.returnValue(of([])); @@ -716,65 +444,6 @@ describe('ReportService', () => { }); }); - describe('getAllExtendedReports():', () => { - it('should get all reports, single page data', (done) => { - spyOn(reportService, 'getMyReportsCount').and.returnValue(of(2)); - spyOn(reportService, 'getMyReports').and.returnValue(of(apiAllReportsRes1)); - - const params = { - queryParams: { - rp_state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', - }, - }; - - const getMyReportsParam = { - offset: 0, - limit: 2, - queryParams: { - rp_state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', - }, - order: undefined, - }; - - reportService.getAllExtendedReports(params).subscribe((res) => { - expect(res).toEqual(expectedAllReports); - expect(reportService.getMyReports).toHaveBeenCalledOnceWith(getMyReportsParam); - expect(reportService.getMyReportsCount).toHaveBeenCalledOnceWith(params.queryParams); - done(); - }); - }); - - it('should get all reports, multiple pages data', (done) => { - const getMyReportsSpy = spyOn(reportService, 'getMyReports'); - const params = { - queryParams: { - rp_state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', - }, - }; - - spyOn(reportService, 'getMyReportsCount').and.returnValue(of(3)); - getMyReportsSpy.withArgs(getMyReportsParam1).and.returnValue(of(apiAllReportsRes1)); - getMyReportsSpy.withArgs(getMyReportsParam2).and.returnValue(of(apiAllReportsRes2)); - - reportService.getAllExtendedReports(params).subscribe((res) => { - expect(res).toEqual(expectedPaginatedReports); - expect(reportService.getMyReports).toHaveBeenCalledWith(getMyReportsParam1); - expect(reportService.getMyReports).toHaveBeenCalledWith(getMyReportsParam2); - expect(reportService.getMyReports).toHaveBeenCalledTimes(2); - expect(reportService.getMyReportsCount).toHaveBeenCalledOnceWith(params.queryParams); - done(); - }); - }); - }); - - it('searchParamsGenerator(): should generate search parameters', () => { - const result = reportService.searchParamsGenerator({ state: 'edit' }); - - expect(result).toEqual({ - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }); - }); - it('getReportPurpose(): should get the purpose of the report', (done) => { const reportName = ' #7: Jan 2023'; apiService.post.and.returnValue(of(apiEmptyReportRes)); @@ -785,279 +454,4 @@ describe('ReportService', () => { done(); }); }); - - describe('getApproversInBulk()', () => { - it('should get approvers in bulk for all report IDs | single page', (done) => { - apiService.get.and.returnValue(of(apiAllApproverRes2)); - - reportService.getApproversInBulk(apiApproversParam).subscribe((res) => { - expect(res).toEqual(expectedApprovers); - expect(apiService.get).toHaveBeenCalledOnceWith('/reports/approvers', { - params: { report_ids: apiApproversParam }, - }); - done(); - }); - }); - - it('should return an empty list as report IDs are empty', (done) => { - apiService.get.and.returnValue(of(apiAllApproverRes2)); - - reportService.getApproversInBulk([]).subscribe((res) => { - expect(res).toEqual([]); - done(); - }); - }); - - it('should get approvers in bulk for all report IDs | multiple page', (done) => { - const report_ids = ['rpvwqzb9Jqq0', 'rpvcIMRMyM3A', 'rpDyD26O3qpV', 'rpqzKD4bPXpW']; - const param1 = { params: { report_ids: report_ids.slice(0, 2) } }; - const param2 = { params: { report_ids: report_ids.slice(2, 4) } }; - - apiService.get.withArgs('/reports/approvers', param1).and.returnValue(of(apiAllApproverRes1)); - apiService.get.withArgs('/reports/approvers', param2).and.returnValue(of(apiAllApproverRes2)); - - reportService.getApproversInBulk(report_ids).subscribe((res) => { - expect(res).toEqual(approversData2); - expect(apiService.get).toHaveBeenCalledWith('/reports/approvers', param1); - expect(apiService.get).toHaveBeenCalledWith('/reports/approvers', param2); - expect(apiService.get).toHaveBeenCalledTimes(2); - done(); - }); - }); - }); - - describe('getPaginatedERptcCount()', () => { - it('should get extended reports count', (done) => { - networkService.isOnline.and.returnValue(of(true)); - apiService.get.and.returnValue(of({ count: 4 })); - storageService.set.and.resolveTo(null); - - const apiParam = ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY']; - - reportService.getPaginatedERptcCount({ state: apiParam }).subscribe((res) => { - expect(res).toEqual({ count: 4 }); - expect(apiService.get).toHaveBeenCalledOnceWith('/erpts/count', { params: { state: apiParam } }); - expect(storageService.set).toHaveBeenCalledOnceWith('erpts-count' + JSON.stringify({ state: apiParam }), { - count: 4, - }); - done(); - }); - }); - - it('should return count when device is offline and use storage to give count', (done) => { - networkService.isOnline.and.returnValue(of(false)); - storageService.get.and.resolveTo({ count: 4 }); - - reportService.getPaginatedERptcCount({}).subscribe((res) => { - expect(res).toEqual({ count: 4 }); - expect(networkService.isOnline).toHaveBeenCalledTimes(1); - expect(storageService.get).toHaveBeenCalledTimes(1); - done(); - }); - }); - }); - - describe('addOrderByParams()', () => { - it('return the params when no order is specified', () => { - const params = { state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'] }; - - const result = reportService.addOrderByParams(params); - expect(result).toEqual(params); - }); - - it('return the params when order is specified', () => { - const params = { - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - order_by: 'rp_created_at.desc,rp_id.desc', - }; - - const result = reportService.addOrderByParams(params, 'rp_created_at.desc,rp_id.desc'); - expect(result).toEqual(params); - }); - }); - - describe('getUserReportParams():', () => { - it('generate parameters as per state | edit', () => { - const params = 'edit'; - - const expectedRes = { - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(3); - }); - - it('generate parameters as per state | draft', () => { - const params = 'draft'; - - const expectedRes = { - state: ['DRAFT'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(1); - }); - - it('generate parameters as per state | pending', () => { - const params = 'pending'; - - const expectedRes = { - state: ['APPROVER_PENDING'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(1); - }); - - it('generate parameters as per state | inquiry', () => { - const params = 'inquiry'; - - const expectedRes = { - state: ['APPROVER_INQUIRY'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(1); - }); - - it('generate parameters as per state | approved', () => { - const params = 'approved'; - - const expectedRes = { - state: ['APPROVED'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(1); - }); - - it('generate parameters as per state | payment_queue', () => { - const params = 'payment_queue'; - - const expectedRes = { - state: ['PAYMENT_PENDING'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(1); - }); - - it('generate parameters as per state | paid', () => { - const params = 'paid'; - - const expectedRes = { - state: ['PAID'], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(1); - }); - - it('generate parameters as per state | all', () => { - const params = 'all'; - - const expectedRes = { - state: [ - 'DRAFT', - 'COMPLETE', - 'APPROVED', - 'APPROVER_PENDING', - 'APPROVER_INQUIRY', - 'PAYMENT_PENDING', - 'PAYMENT_PROCESSING', - 'PAID', - 'REJECTED', - ], - }; - - const result = reportService.getUserReportParams(params); - expect(result).toEqual(expectedRes); - expect(expectedRes.state.length).toEqual(9); - }); - }); - - it('addApprovers(): add approvers to reports', () => { - const mockApproverData = cloneDeep(approversData1); - const mockERpts = cloneDeep(addApproverERpts); - const res = reportService.addApprovers(mockERpts, mockApproverData); - - expect(res).toEqual(expectedAddedApproverERpts); - }); - - it('getFilteredPendingReports(): should get filtered and pending reports', (done) => { - spyOn(reportService, 'searchParamsGenerator').and.returnValue({ - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }); - spyOn(reportService, 'getPaginatedERptcCount').and.returnValue(of({ count: 2 })); - spyOn(reportService, 'getPaginatedERptc').and.returnValue(of(addApproverERpts)); - spyOn(reportService, 'getApproversInBulk').and.returnValue(of(approversData1)); - spyOn(reportService, 'addApprovers').and.returnValue(expectedAddedApproverERpts); - - reportService.getFilteredPendingReports({ state: 'edit' }).subscribe((res) => { - expect(res).toEqual(expectedAddedApproverERpts); - expect(reportService.searchParamsGenerator).toHaveBeenCalledOnceWith({ state: 'edit' }); - expect(reportService.getPaginatedERptcCount).toHaveBeenCalledOnceWith({ - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }); - expect(reportService.getPaginatedERptc).toHaveBeenCalledOnceWith(0, 2, { - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }); - expect(reportService.getApproversInBulk).toHaveBeenCalledOnceWith(['rp35DK02IvMP', 'rppMWBOkXJeS']); - expect(reportService.addApprovers).toHaveBeenCalledOnceWith(addApproverERpts, approversData3); - done(); - }); - }); - - describe('getReportStatsData()', () => { - it('should get report stats data', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - apiv2Service.get.and.returnValue(of(apiReportStatsRawRes)); - - const params = { - rp_org_user_id: 'eq.ouX8dwsbLCLv', - approved_by: 'cs.{ouCI4UQ2G0K1}', - rp_approval_state: ['in.(APPROVAL_PENDING)'], - rp_state: ['in.(APPROVER_PENDING)'], - sequential_approval_turn: ['in.(true)'], - aggregates: 'count(rp_id),sum(rp_amount)', - scalar: true, - }; - - reportService.getReportStatsData(apiReportStatsRawParam).subscribe((res) => { - expect(res).toEqual(expectedReportRawStats); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports/stats', { params }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - done(); - }); - }); - - it('should get report stats data when default stats has been set to false', (done) => { - authService.getEou.and.resolveTo(apiEouRes); - apiv2Service.get.and.returnValue(of(new StatsResponse(apiReportStatsRawRes))); - - const params = { - approved_by: 'cs.{ouCI4UQ2G0K1}', - rp_approval_state: ['in.(APPROVAL_PENDING)'], - rp_state: ['in.(APPROVER_PENDING)'], - sequential_approval_turn: ['in.(true)'], - aggregates: 'count(rp_id),sum(rp_amount)', - scalar: true, - }; - - reportService.getReportStatsData(apiReportStatsRawParam, false).subscribe((res) => { - expect(res).toEqual(expectedReportRawStats); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports/stats', { params }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - done(); - }); - }); - }); }); diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index 4ac29301c8..09b2987184 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -1,25 +1,20 @@ import { DatePipe } from '@angular/common'; import { Inject, Injectable } from '@angular/core'; -import { Observable, Subject, from, of, range } from 'rxjs'; -import { catchError, concatMap, map, reduce, switchMap, tap } from 'rxjs/operators'; +import { Observable, Subject, of } from 'rxjs'; +import { catchError, map, switchMap } from 'rxjs/operators'; import { PAGINATION_SIZE } from 'src/app/constants'; import { CacheBuster, Cacheable } from 'ts-cacheable'; -import { ApiV2Response } from '../models/api-v2.model'; import { OrgSettings } from '../models/org-settings.model'; import { PdfExport } from '../models/pdf-exports.model'; import { Report } from '../models/platform/v1/report.model'; -import { ReportQueryParams } from '../models/report-api-params.model'; import { ReportAutoSubmissionDetails } from '../models/report-auto-submission-details.model'; -import { ReportParams } from '../models/report-params.model'; import { ReportPermission } from '../models/report-permission.model'; import { ReportPurpose } from '../models/report-purpose.model'; -import { ReportStateMap } from '../models/report-state-map.model'; import { UnflattenedReport } from '../models/report-unflattened.model'; import { ReportV1 } from '../models/report-v1.model'; import { ApproverPlatformApiService } from './approver-platform-api.service'; import { ExtendedReport } from '../models/report.model'; import { Approver } from '../models/v1/approver.model'; -import { Datum } from '../models/v2/stats-response.model'; import { ApiV2Service } from './api-v2.service'; import { ApiService } from './api.service'; import { AuthService } from './auth.service'; @@ -77,57 +72,6 @@ export class ReportService { return this.transactionService.clearCache(); } - @Cacheable({ - cacheBusterObserver: reportsCacheBuster$, - }) - getMyReportsCount(queryParams = {}): Observable { - return this.getMyReports({ - offset: 0, - limit: 1, - queryParams, - }).pipe(map((res) => res.count)); - } - - @Cacheable({ - cacheBusterObserver: reportsCacheBuster$, - }) - getPaginatedERptc( - offset: number, - limit: number, - params: { state?: string[]; order?: string } - ): Observable { - const data = { - params: { - offset, - limit, - }, - }; - - Object.keys(params).forEach((param) => { - data.params[param] = params[param] as string | string[]; - }); - - return this.apiService - .get('/erpts', data) - .pipe(map((erptcs) => erptcs.map((erptc) => this.dataTransformService.unflatten(erptc)))); - } - - @Cacheable({ - cacheBusterObserver: reportsCacheBuster$, - }) - getERpt(rptId: string): Observable { - return this.apiService.get('/erpts/' + rptId).pipe( - map((data) => { - const erpt: UnflattenedReport = this.dataTransformService.unflatten(data); - this.dateService.fixDates(erpt.rp); - if (erpt && erpt.rp && erpt.rp.created_at) { - erpt.rp.created_at = this.dateService.getLocalDate(erpt.rp.created_at); - } - return erpt; - }) - ); - } - @CacheBuster({ cacheBusterNotifier: reportsCacheBuster$, }) @@ -258,168 +202,6 @@ export class ReportService { ); } - getUserReportParams(state: keyof ReportStateMap): Record<'state', string[]> { - const stateMap: ReportStateMap = { - draft: { - state: ['DRAFT'], - }, - pending: { - state: ['APPROVER_PENDING'], - }, - inquiry: { - state: ['APPROVER_INQUIRY'], - }, - approved: { - state: ['APPROVED'], - }, - payment_queue: { - state: ['PAYMENT_PENDING'], - }, - paid: { - state: ['PAID'], - }, - edit: { - state: ['DRAFT', 'APPROVER_PENDING', 'APPROVER_INQUIRY'], - }, - all: { - state: [ - 'DRAFT', - 'COMPLETE', - 'APPROVED', - 'APPROVER_PENDING', - 'APPROVER_INQUIRY', - 'PAYMENT_PENDING', - 'PAYMENT_PROCESSING', - 'PAID', - 'REJECTED', - ], - }, - }; - - return stateMap[state]; - } - - getPaginatedERptcCount(params: ReportParams): Observable<{ count: number }> { - return this.networkService.isOnline().pipe( - switchMap((isOnline: boolean) => { - if (isOnline) { - return this.apiService.get<{ count: number }>('/erpts/count', { params }).pipe( - tap((res) => { - this.storageService.set('erpts-count' + JSON.stringify(params), res); - }) - ); - } else { - return from(this.storageService.get<{ count: number }>('erpts-count' + JSON.stringify(params))); - } - }) - ); - } - - getMyReports( - config: Partial<{ - offset: number; - limit: number; - order: string; - queryParams: ReportQueryParams; - }> = { - offset: 0, - limit: 10, - queryParams: {}, - } - ): Observable> { - return from(this.authService.getEou()).pipe( - switchMap((eou) => - this.apiv2Service.get('/reports', { - params: { - offset: config.offset, - limit: config.limit, - order: `${config.order || 'rp_created_at.desc'},rp_id.desc`, - rp_org_user_id: 'eq.' + eou.ou.id, - ...config.queryParams, - }, - }) - ), - map( - (res) => - res as { - count: number; - data: ExtendedReport[]; - limit: number; - offset: number; - url: string; - } - ), - map((res) => ({ - ...res, - data: res.data.map((datum) => this.dateService.fixDates(datum)), - })) - ); - } - - getTeamReportsCount(queryParams = {}): Observable { - return this.getTeamReports({ - offset: 0, - limit: 1, - queryParams, - }).pipe(map((res) => res.count)); - } - - getTeamReports( - config: Partial<{ offset: number; limit: number; order: string; queryParams: Partial }> = { - offset: 0, - limit: 10, - queryParams: {}, - } - ): Observable> { - return from(this.authService.getEou()).pipe( - switchMap((eou) => - this.apiv2Service.get('/reports', { - params: { - offset: config.offset, - limit: config.limit, - approved_by: 'cs.{' + eou.ou.id + '}', - order: `${config.order || 'rp_created_at.desc'},rp_id.desc`, - ...config.queryParams, - }, - }) - ), - map( - (res) => - res as { - count: number; - data: ExtendedReport[]; - limit: number; - offset: number; - url: string; - } - ), - map((res) => ({ - ...res, - data: res.data.map((datum) => this.dateService.fixDates(datum)), - })) - ); - } - - getReport(id: string): Observable { - return this.getMyReports({ - offset: 0, - limit: 1, - queryParams: { - rp_id: `eq.${id}`, - }, - }).pipe(map((res) => res.data[0])); - } - - getTeamReport(id: string): Observable { - return this.getTeamReports({ - offset: 0, - limit: 1, - queryParams: { - rp_id: `eq.${id}`, - }, - }).pipe(map((res) => res.data[0])); - } - getExports(rptId: string): Observable<{ results: PdfExport[] }> { return this.apiService.get<{ results: PdfExport[] }>('/reports/' + rptId + '/exports'); } @@ -438,142 +220,10 @@ export class ReportService { return this.apiService.post('/reports/summary/download', data); } - getAllExtendedReports( - config: Partial<{ order: string; queryParams: ReportQueryParams }> - ): Observable { - return this.getMyReportsCount(config.queryParams).pipe( - switchMap((count) => { - count = count > this.paginationSize ? count / this.paginationSize : 1; - return range(0, count); - }), - concatMap((page) => - this.getMyReports({ - offset: this.paginationSize * page, - limit: this.paginationSize, - queryParams: config.queryParams, - order: config.order, - }) - ), - map((res) => res.data), - reduce((acc, curr) => acc.concat(curr), [] as ExtendedReport[]) - ); - } - - addOrderByParams( - params: { - state?: string[]; - }, - sortOrder?: string - ): { - state?: string[]; - order_by?: string; - } { - if (sortOrder) { - return Object.assign(params, { order_by: sortOrder }); - } else { - return params; - } - } - - searchParamsGenerator( - search: { state: keyof ReportStateMap; dateRange?: { from: string; to: string } }, - sortOrder?: string - ): Record { - let params = {}; - - params = this.userReportsSearchParamsGenerator(params, search); - params = this.addOrderByParams(params, sortOrder); - - return params; - } - - userReportsSearchParamsGenerator( - params: ReportParams, - search: { - state: keyof ReportStateMap; - dateRange?: { - from?: string; - to?: string; - }; - } - ): Record<'state', string[]> { - const searchParams = this.getUserReportParams(search.state); - return Object.assign({}, params, searchParams); - } - getReportPurpose(reportPurpose: { ids: string[] }): Observable { return this.apiService.post('/reports/purpose', reportPurpose).pipe(map((res) => res.purpose)); } - getApproversInBulk(rptIds: string[]): Observable { - if (!rptIds || rptIds.length === 0) { - return of([]); - } - const count = rptIds.length > this.paginationSize ? rptIds.length / this.paginationSize : 1; - return range(0, count).pipe( - map((page) => rptIds.slice(page * this.paginationSize, (page + 1) * this.paginationSize)), - concatMap((rptIds) => this.apiService.get('/reports/approvers', { params: { report_ids: rptIds } })), - reduce((acc: Approver[], curr: Approver) => acc.concat(curr), []) - ); - } - - addApprovers(erpts: UnflattenedReport[], approvers: Approver[]): UnflattenedReport[] { - const reportApprovalsMap: Record = {}; - - approvers.forEach((approver) => { - if (reportApprovalsMap[approver.report_id]) { - reportApprovalsMap[approver.report_id].push(approver); - } else { - reportApprovalsMap[approver.report_id] = [approver]; - } - }); - - return erpts.map((erpt) => { - erpt.rp.approvals = reportApprovalsMap[erpt.rp.id]; - return erpt; - }); - } - - getReportStatsData(params: {}, defaultOwnStats: boolean = true): Observable { - return from(this.authService.getEou()).pipe( - switchMap((eou) => { - const defaultStats = defaultOwnStats ? { rp_org_user_id: `eq.${eou.ou.id}` } : {}; - return this.apiv2Service.get('/reports/stats', { - params: { - ...defaultStats, - ...params, - }, - }); - }), - map((rawStatsResponse) => rawStatsResponse.data) - ); - } - - getFilteredPendingReports(searchParams: { state: keyof ReportStateMap }): Observable { - const params = this.searchParamsGenerator(searchParams); - - return this.getPaginatedERptcCount(params).pipe( - switchMap((results: { count: number }) => - // getting all results -> offset = 0, limit = count - this.getPaginatedERptc(0, results.count, params) - ), - switchMap((erpts) => { - const rptIds = erpts.map((erpt) => erpt.rp.id); - - return this.getApproversInBulk(rptIds).pipe( - map((approvals) => - this.addApprovers(erpts, approvals).filter( - (erpt) => - !erpt.rp.approvals || - (erpt.rp.approvals && - !(erpt.rp.approvals as Approver[]).some((approval) => approval.state === 'APPROVAL_DONE')) - ) - ) - ); - }) - ); - } - approverUpdateReportPurpose(report: Report): Observable { const params: { data: Pick } = { data: { diff --git a/src/app/core/services/tasks.service.spec.ts b/src/app/core/services/tasks.service.spec.ts index 4200211251..07428f0558 100644 --- a/src/app/core/services/tasks.service.spec.ts +++ b/src/app/core/services/tasks.service.spec.ts @@ -90,10 +90,7 @@ describe('TasksService', () => { const homeCurrency = 'INR'; beforeEach(() => { - const reportServiceSpy = jasmine.createSpyObj('ReportService', [ - 'getReportAutoSubmissionDetails', - 'getAllExtendedReports', - ]); + const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getReportAutoSubmissionDetails']); const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getExpenseStats', 'getDuplicateSets']); const userEventServiceSpy = jasmine.createSpyObj('UserEventService', ['onTaskCacheClear']); const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); @@ -247,8 +244,6 @@ describe('TasksService', () => { and: '(or(matched_corporate_card_transactions.eq.[],matched_corporate_card_transactions->0->status.neq.PENDING))', }) .and.returnValue(of(completeStats)); - - reportService.getAllExtendedReports.and.returnValue(of(allExtendedReportsResponse)); } it('should be able to fetch unreported expenses tasks', () => { diff --git a/src/app/core/services/transaction.service.spec.ts b/src/app/core/services/transaction.service.spec.ts index 3fcd1f55f1..85e7e957c7 100644 --- a/src/app/core/services/transaction.service.spec.ts +++ b/src/app/core/services/transaction.service.spec.ts @@ -37,7 +37,6 @@ import { UserEventService } from './user-event.service'; import { UtilityService } from './utility.service'; import * as dayjs from 'dayjs'; import { eouRes2 } from '../mock-data/extended-org-user.data'; -import { txnStats } from '../mock-data/stats-response.data'; import { expenseV2Data, expenseV2DataMultiple } from '../mock-data/expense-v2.data'; import * as lodash from 'lodash'; import { txnData, txnData2, txnData4, txnDataPayload, txnList, upsertTxnParam } from '../mock-data/transaction.data'; diff --git a/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts b/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts index 8af983b1c7..f16388c9f7 100644 --- a/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts +++ b/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts @@ -16,6 +16,10 @@ import { singleErqUnflattened } from '../core/mock-data/extended-advance-request import { DeepLinkService } from '../core/services/deep-link.service'; import { platformExpenseData } from 'src/app/core/mock-data/platform/v1/expense.data'; import { transformedExpenseData } from '../core/mock-data/transformed-expense.data'; +import { ApproverReportsService } from '../core/services/platform/v1/approver/reports.service'; +import { SpenderReportsService } from '../core/services/platform/v1/spender/reports.service'; +import { Approver } from '../core/models/approver.model'; +import { platformReportData } from '../core/mock-data/platform-report.data'; describe('DeepLinkRedirectionPage', () => { let component: DeepLinkRedirectionPage; @@ -28,6 +32,8 @@ describe('DeepLinkRedirectionPage', () => { let reportService: jasmine.SpyObj; let authService: jasmine.SpyObj; let deepLinkService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; + let approverReportsService: jasmine.SpyObj; let activeroutemock: ActivatedRoute; beforeEach(waitForAsync(() => { @@ -39,6 +45,8 @@ describe('DeepLinkRedirectionPage', () => { const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getERpt']); const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); const deepLinkServiceSpy = jasmine.createSpyObj('DeepLinkService', ['getExpenseRoute']); + const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['getReportById']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getReportById']); TestBed.configureTestingModule({ declarations: [DeepLinkRedirectionPage], @@ -52,6 +60,8 @@ describe('DeepLinkRedirectionPage', () => { { provide: ReportService, useValue: reportServiceSpy }, { provide: AuthService, useValue: authServiceSpy }, { provide: DeepLinkService, useValue: deepLinkServiceSpy }, + { provide: SpenderReportsService, useValue: spenderReportsServiceSpy }, + { provide: ApproverReportsService, useValue: approverReportsServiceSpy }, { provide: ActivatedRoute, useValue: { @@ -74,9 +84,10 @@ describe('DeepLinkRedirectionPage', () => { reportService = TestBed.inject(ReportService) as jasmine.SpyObj; authService = TestBed.inject(AuthService) as jasmine.SpyObj; deepLinkService = TestBed.inject(DeepLinkService) as jasmine.SpyObj; + approverReportsService = TestBed.inject(ApproverReportsService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; activeroutemock = TestBed.inject(ActivatedRoute); - reportService.getERpt.and.returnValue(of(expectedSingleErpt)); authService.getEou.and.resolveTo(apiEouRes); fixture = TestBed.createComponent(DeepLinkRedirectionPage); component = fixture.componentInstance; @@ -89,6 +100,8 @@ describe('DeepLinkRedirectionPage', () => { describe('redirectToReportModule', () => { it('should redirect to report module', fakeAsync(() => { + spenderReportsService.getReportById.and.returnValue(of(platformReportData)); + approverReportsService.getReportById.and.returnValue(of(platformReportData)); activeroutemock.snapshot.params = { sub_module: 'report', id: 'rprAfNrce73O', @@ -100,7 +113,7 @@ describe('DeepLinkRedirectionPage', () => { tick(500); expect(authService.getEou).toHaveBeenCalledTimes(1); tick(500); - expect(reportService.getERpt).toHaveBeenCalledOnceWith(activeroutemock.snapshot.params.id); + expect(spenderReportsService.getReportById).toHaveBeenCalledOnceWith(activeroutemock.snapshot.params.id); expect(router.navigate).toHaveBeenCalledOnceWith([ '/', 'enterprise', @@ -109,7 +122,9 @@ describe('DeepLinkRedirectionPage', () => { ]); })); - it('should redirect to team reports when ids do not match', fakeAsync(() => { + it('should redirect to team reports when there is no spender report', fakeAsync(() => { + spenderReportsService.getReportById.and.returnValue(of(null)); + approverReportsService.getReportById.and.returnValue(of(platformReportData)); activeroutemock.snapshot.params = { sub_module: 'report', id: 'rprAfNrce75O', @@ -122,8 +137,6 @@ describe('DeepLinkRedirectionPage', () => { }, }; - authService.getEou.and.resolveTo(updatedApiEouRes); - const updatedErpt = { ...expectedSingleErpt, rp: { @@ -131,14 +144,12 @@ describe('DeepLinkRedirectionPage', () => { org_user_id: 'rprAfNrce75O', }, }; - reportService.getERpt.and.returnValue(of(updatedErpt)); component.redirectToReportModule(); fixture.detectChanges(); expect(loaderService.showLoader).toHaveBeenCalledOnceWith('Loading....'); tick(500); expect(authService.getEou).toHaveBeenCalledTimes(1); tick(500); - expect(reportService.getERpt).toHaveBeenCalledOnceWith(activeroutemock.snapshot.params.id); expect(router.navigate).toHaveBeenCalledOnceWith([ '/', 'enterprise', @@ -159,8 +170,8 @@ describe('DeepLinkRedirectionPage', () => { spyOn(component, 'switchOrg'); const error = 'Something went wrong'; - authService.getEou.and.resolveTo(updatedApiEouRes); - reportService.getERpt.and.returnValue(throwError(() => error)); + spenderReportsService.getReportById.and.returnValue(throwError(() => error)); + approverReportsService.getReportById.and.returnValue(throwError(() => error)); component.redirectToReportModule(); fixture.detectChanges(); tick(500); diff --git a/src/app/deep-link-redirection/deep-link-redirection.page.ts b/src/app/deep-link-redirection/deep-link-redirection.page.ts index fe07b9c4d1..ae08ecb3e6 100644 --- a/src/app/deep-link-redirection/deep-link-redirection.page.ts +++ b/src/app/deep-link-redirection/deep-link-redirection.page.ts @@ -8,6 +8,8 @@ import { ReportService } from '../core/services/report.service'; import { EMPTY, catchError, filter, finalize, from, shareReplay, switchMap, map } from 'rxjs'; import { DeepLinkService } from '../core/services/deep-link.service'; import { ExpensesService } from '../core/services/platform/v1/spender/expenses.service'; +import { SpenderReportsService } from '../core/services/platform/v1/spender/reports.service'; +import { ApproverReportsService } from '../core/services/platform/v1/approver/reports.service'; @Component({ selector: 'app-deep-link-redirection', @@ -24,11 +26,13 @@ export class DeepLinkRedirectionPage { private authService: AuthService, private reportService: ReportService, private deepLinkService: DeepLinkService, - private expensesService: ExpensesService + private expensesService: ExpensesService, + private approverReportsService: ApproverReportsService, + private spenderReportsService: SpenderReportsService ) {} - ionViewWillEnter() { - const subModule = this.activatedRoute.snapshot.params.sub_module; + ionViewWillEnter(): void { + const subModule = this.activatedRoute.snapshot.params.sub_module as string; if (subModule === 'report') { this.redirectToReportModule(); @@ -39,10 +43,10 @@ export class DeepLinkRedirectionPage { } } - async redirectToAdvReqModule() { + async redirectToAdvReqModule(): Promise { await this.loaderService.showLoader('Loading....'); const currentEou = await this.authService.getEou(); - this.advanceRequestService.getEReq(this.activatedRoute.snapshot.params.id).subscribe( + this.advanceRequestService.getEReq(this.activatedRoute.snapshot.params.id as string).subscribe( (res) => { const id = res.advance.id || res.areq.id; @@ -63,7 +67,7 @@ export class DeepLinkRedirectionPage { ); } - async redirectToExpenseModule() { + async redirectToExpenseModule(): Promise { const expenseOrgId = this.activatedRoute.snapshot.params.orgId as string; const txnId = this.activatedRoute.snapshot.params.id as string; @@ -119,13 +123,19 @@ export class DeepLinkRedirectionPage { } } - async redirectToReportModule() { + async redirectToReportModule(): Promise { await this.loaderService.showLoader('Loading....'); const currentEou = await this.authService.getEou(); - this.reportService.getERpt(this.activatedRoute.snapshot.params.id as string).subscribe( - (res) => { - if (currentEou.ou.id === res.rp.org_user_id) { + const spenderReport$ = this.spenderReportsService.getReportById(this.activatedRoute.snapshot.params.id as string); + const approverReport$ = this.approverReportsService.getReportById(this.activatedRoute.snapshot.params.id as string); + const rptObservables$ = []; + if (currentEou.ou.roles.includes('APPROVER')) { + rptObservables$.push(this.approverReportsService.getReportById(this.activatedRoute.snapshot.params.id as string)); + } + spenderReport$.subscribe( + (spenderReport) => { + if (spenderReport) { this.router.navigate([ '/', 'enterprise', @@ -133,12 +143,16 @@ export class DeepLinkRedirectionPage { { id: this.activatedRoute.snapshot.params.id as string }, ]); } else { - this.router.navigate([ - '/', - 'enterprise', - 'view_team_report', - { id: this.activatedRoute.snapshot.params.id as string }, - ]); + approverReport$.subscribe((approverReport) => { + if (approverReport) { + this.router.navigate([ + '/', + 'enterprise', + 'view_team_report', + { id: this.activatedRoute.snapshot.params.id as string }, + ]); + } + }); } }, () => { @@ -150,7 +164,7 @@ export class DeepLinkRedirectionPage { ); } - switchOrg() { + switchOrg(): void { this.router.navigate(['/', 'auth', 'switch_org']); } } diff --git a/src/app/fyle/my-expenses/my-expenses.page.spec.ts b/src/app/fyle/my-expenses/my-expenses.page.spec.ts index c2256a5cb5..5bcaab1313 100644 --- a/src/app/fyle/my-expenses/my-expenses.page.spec.ts +++ b/src/app/fyle/my-expenses/my-expenses.page.spec.ts @@ -86,7 +86,6 @@ import { snackbarPropertiesRes3, snackbarPropertiesRes4, } from 'src/app/core/mock-data/snackbar-properties.data'; -import { transactionDatum1, transactionDatum3 } from 'src/app/core/mock-data/stats-response.data'; import { txnList } from 'src/app/core/mock-data/transaction.data'; import { unflattenedTxnData } from 'src/app/core/mock-data/unflattened-txn.data'; import { unformattedTxnData } from 'src/app/core/mock-data/unformatted-transaction.data'; diff --git a/src/app/fyle/view-expense/view-expense.page.spec.ts b/src/app/fyle/view-expense/view-expense.page.spec.ts index a37a6becea..70f7cc5941 100644 --- a/src/app/fyle/view-expense/view-expense.page.spec.ts +++ b/src/app/fyle/view-expense/view-expense.page.spec.ts @@ -35,7 +35,6 @@ import { individualExpPolicyStateData3 } from 'src/app/core/mock-data/individual import { FyPopoverComponent } from 'src/app/shared/components/fy-popover/fy-popover.component'; import { FyViewAttachmentComponent } from 'src/app/shared/components/fy-view-attachment/fy-view-attachment.component'; import { expenseFieldsMapResponse, expenseFieldsMapResponse4 } from 'src/app/core/mock-data/expense-fields-map.data'; -import { apiTeamReportPaginated1, apiTeamRptSingleRes } from 'src/app/core/mock-data/api-reports.data'; import { filledCustomProperties } from 'src/app/core/test-data/custom-inputs.spec.data'; import { dependentFieldValues } from 'src/app/core/test-data/dependent-fields.service.spec.data'; import { orgSettingsGetData } from 'src/app/core/test-data/org-settings.service.spec.data';