From ea4ce2e066dd3f58f6cf261299dd9ae24b9fe01e Mon Sep 17 00:00:00 2001 From: Devendra Singh Rana <132900359+devendrafyle@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:57:40 +0530 Subject: [PATCH 1/3] test: fixed unit tests for handle_ccc_expense method (#2827) * fixed unit tests for handle_ccc_expense method * fixed the unit test for the changes --- src/app/core/mock-data/cc-transaction.data.ts | 196 ++++++++++++++++++ .../mock-data/matchedCCTransaction.data.ts | 19 ++ .../mock-data/transformed-expense.data.ts | 68 ++++++ .../core/mock-data/unflattened-txn.data.ts | 9 + ...porate-credit-card-expense.service.spec.ts | 19 ++ src/app/core/services/transaction.service.ts | 1 - .../add-edit-expense-6.spec.ts | 47 ++++- .../add-edit-expense.setup.spec.ts | 2 + 8 files changed, 354 insertions(+), 7 deletions(-) create mode 100644 src/app/core/mock-data/cc-transaction.data.ts diff --git a/src/app/core/mock-data/cc-transaction.data.ts b/src/app/core/mock-data/cc-transaction.data.ts new file mode 100644 index 0000000000..e60c4ec581 --- /dev/null +++ b/src/app/core/mock-data/cc-transaction.data.ts @@ -0,0 +1,196 @@ +import { corporateCardTransaction } from '../models/platform/v1/cc-transaction.model'; +import { TransactionStatus } from '../models/platform/v1/expense.model'; + +export const ccTransactionData: corporateCardTransaction = { + amount: 260.37, + assignor_user: null, + assignor_user_id: null, + auto_suggested_expense_ids: [], + can_delete: true, + category: null, + code: 'b1d89f85d1f44a22981e4b4c8b1af435', + corporate_card: { + bank_name: 'DSR', + card_number: '7620', + id: 'bacck9WlgA11Uh', + masked_number: '7620', + user_email: 'devendra.r@fyle.in', + user_full_name: 'Devendra Singh Rana', + }, + corporate_card_id: 'bacck9WlgA11Uh', + created_at: '2024-01-23T12:17:31.316675+00:00', + currency: 'USD', + description: null, + foreign_amount: null, + foreign_currency: null, + id: 'btxnSte7sVQCM8', + is_assigned: true, + is_auto_matched: false, + is_dismissed: false, + is_exported: false, + is_marked_personal: false, + last_assigned_at: new Date('2024-01-23T12:18:51.470532+00:00'), + last_auto_matched_at: new Date('2024-01-23T12:19:50.298547+00:00'), + last_dismissed_at: null, + last_marked_personal_at: null, + last_user_matched_at: new Date('2024-02-13T03:10:49.432011+00:00'), + matched_expense_ids: ['txmF3wgfj0Bs'], + matched_expenses: [ + { + amount: 260.37, + category_display_name: 'Unspecified', + currency: 'USD', + foreign_amount: null, + foreign_currency: null, + id: 'txmF3wgfj0Bs', + merchant: 'test description', + no_of_files: 0, + purpose: null, + seq_num: 'E/2024/01/T/39', + spent_at: new Date('2018-07-04T00:00:00+00:00'), + state: 'DRAFT', + }, + ], + mcc: null, + merchant: 'test description', + metadata: { + merchant_category_code: '', + flight_merchant_category_code: '', + flight_supplier_name: '', + flight_travel_agency_name: '', + flight_ticket_number: '', + flight_total_fare: 0, + flight_travel_date: undefined, + flight_service_class: '', + flight_carrier_code: '', + flight_fare_base_code: '', + flight_trip_leg_number: '', + hotel_merchant_category_code: '', + hotel_supplier_name: '', + hotel_checked_in_at: undefined, + hotel_nights: 0, + hotel_checked_out_at: undefined, + hotel_country: '', + hotel_city: '', + hotel_total_fare: 0, + fleet_product_merchant_category_code: '', + fleet_product_supplier_name: '', + fleet_service_merchant_category_code: '', + fleet_service_supplier_name: '', + car_rental_merchant_category_code: '', + car_rental_supplier_name: '', + car_rental_started_at: undefined, + car_rental_days: 0, + car_rental_ended_at: undefined, + general_ticket_issued_at: undefined, + general_ticket_number: '', + general_issuing_carrier: '', + general_travel_agency_name: '', + general_travel_agency_code: '', + general_ticket_total_fare: 0, + general_ticket_total_tax: 0, + merchant_address: '', + }, + org_id: 'oroLKHBYQVvj', + post_date: null, + settlement_id: null, + spent_at: '2018-07-04T00:00:00+00:00', + statement_id: 'stmt2K9aLunGU4', + transaction_status: TransactionStatus.PENDING, + updated_at: '2024-02-13T03:10:49.432028+00:00', + user: { + email: 'devendra.r@fyle.in', + full_name: 'Devendra Singh Rana', + id: 'usvMoPfCC9Xw', + }, + user_id: 'usvMoPfCC9Xw', +}; + +export const ccTransactionData1: corporateCardTransaction = { + amount: 205.21, + assignor_user: null, + assignor_user_id: null, + auto_suggested_expense_ids: [], + can_delete: false, + category: null, + code: '6c4a6dcb15a94c0e976dcd1a507dcfd0', + corporate_card: { + bank_name: 'DSR', + card_number: '7620', + id: 'bacck9WlgA11Uh', + masked_number: '7620', + user_email: 'devendra.r@fyle.in', + user_full_name: 'Devendra Singh Rana', + }, + corporate_card_id: 'bacck9WlgA11Uh', + created_at: '2024-01-23T12:17:34.473632+00:00', + currency: 'USD', + description: null, + foreign_amount: null, + foreign_currency: null, + id: 'btxnBdS2Kpvzhy', + is_assigned: true, + is_auto_matched: true, + is_dismissed: false, + is_exported: false, + is_marked_personal: true, + last_assigned_at: new Date('2024-01-23T12:18:51.470532+00:00'), + last_auto_matched_at: new Date('2024-01-23T12:20:06.279340+00:00'), + last_dismissed_at: null, + last_marked_personal_at: new Date('2024-02-12T12:36:16.437731+00:00'), + last_user_matched_at: null, + matched_expense_ids: [], + matched_expenses: [], + mcc: null, + merchant: 'test description', + metadata: { + merchant_category_code: '', + flight_merchant_category_code: '', + flight_supplier_name: '', + flight_travel_agency_name: '', + flight_ticket_number: '', + flight_total_fare: 0, + flight_travel_date: undefined, + flight_service_class: '', + flight_carrier_code: '', + flight_fare_base_code: '', + flight_trip_leg_number: '', + hotel_merchant_category_code: '', + hotel_supplier_name: '', + hotel_checked_in_at: undefined, + hotel_nights: 0, + hotel_checked_out_at: undefined, + hotel_country: '', + hotel_city: '', + hotel_total_fare: 0, + fleet_product_merchant_category_code: '', + fleet_product_supplier_name: '', + fleet_service_merchant_category_code: '', + fleet_service_supplier_name: '', + car_rental_merchant_category_code: '', + car_rental_supplier_name: '', + car_rental_started_at: undefined, + car_rental_days: 0, + car_rental_ended_at: undefined, + general_ticket_issued_at: undefined, + general_ticket_number: '', + general_issuing_carrier: '', + general_travel_agency_name: '', + general_travel_agency_code: '', + general_ticket_total_fare: 0, + general_ticket_total_tax: 0, + merchant_address: '', + }, + org_id: 'oroLKHBYQVvj', + post_date: null, + settlement_id: null, + spent_at: '2018-06-06T00:00:00+00:00', + statement_id: 'stmt2K9aLunGU4', + updated_at: '2024-02-12T12:36:16.437742+00:00', + user: { + email: 'devendra.r@fyle.in', + full_name: 'Devendra Singh Rana', + id: 'usvMoPfCC9Xw', + }, + user_id: 'usvMoPfCC9Xw', +}; diff --git a/src/app/core/mock-data/matchedCCTransaction.data.ts b/src/app/core/mock-data/matchedCCTransaction.data.ts index 68da126798..8706805b22 100644 --- a/src/app/core/mock-data/matchedCCTransaction.data.ts +++ b/src/app/core/mock-data/matchedCCTransaction.data.ts @@ -32,3 +32,22 @@ export const matchedCCTransactionData2: Partial = { status: TransactionStatus.PENDING, displayObject: 'Jun 6, 2018 - test description205.21', }; + +export const matchedCCTransactionData3: Partial = { + id: 'btxnBdS2Kpvzhy', + group_id: 'btxnBdS2Kpvzhy', + created_at: '2024-01-23T12:17:34.473632+00:00', + creator_id: 'usvMoPfCC9Xw', + settlement_id: null, + updated_at: '2024-02-12T12:36:16.437742+00:00', + amount: 205.21, + vendor: 'test description', + txn_dt: '2018-06-06T00:00:00+00:00', + currency: 'USD', + description: null, + card_or_account_number: '7620', + corporate_credit_card_account_number: '7620', + orig_amount: null, + orig_currency: null, + status: undefined, +}; diff --git a/src/app/core/mock-data/transformed-expense.data.ts b/src/app/core/mock-data/transformed-expense.data.ts index 1d2c9463f1..f9ed386f80 100644 --- a/src/app/core/mock-data/transformed-expense.data.ts +++ b/src/app/core/mock-data/transformed-expense.data.ts @@ -430,6 +430,74 @@ export const transformedExpenseWithMatchCCCData3: Partial = { + tx: { + id: 'txmF3wgfj0Bs', + created_at: new Date('2024-01-23T01:19:49.370Z'), + txn_dt: new Date('2018-07-03T13:00:00.000Z'), + categoryDisplayName: 'Unspecified', + num_files: 0, + org_category: 'Unspecified', + fyle_category: 'Unspecified', + state: 'DRAFT', + admin_amount: null, + policy_amount: null, + skip_reimbursement: true, + amount: 260.37, + currency: 'USD', + user_amount: 260.37, + orig_amount: null, + orig_currency: null, + from_dt: null, + to_dt: null, + vendor: 'test description', + distance: null, + distance_unit: null, + locations: [], + verification_state: null, + org_user_id: 'ouokfwl9OEdl', + expense_number: 'E/2024/01/T/39', + hotel_is_breakfast_provided: null, + tax_group_id: null, + creator_id: 'ouokfwl9OEdl', + report_id: null, + org_category_id: 283907, + cost_center_id: null, + project_id: null, + custom_properties: [], + purpose: null, + billable: null, + sub_category: null, + tax_amount: null, + corporate_credit_card_expense_group_id: 'btxnSte7sVQCM8', + split_group_id: 'txmF3wgfj0Bs', + split_group_user_amount: null, + receipt_required: null, + per_diem_rate_id: null, + num_days: null, + mileage_rate_id: null, + mileage_is_round_trip: null, + mileage_calculated_distance: null, + mileage_calculated_amount: null, + manual_flag: null, + policy_flag: null, + extracted_data: null, + matched_corporate_card_transactions: [], + source_account_id: 'acc7F6bwRa52p', + org_category_code: null, + physical_bill: null, + physical_bill_at: null, + }, + source: { + account_id: 'acc7F6bwRa52p', + account_type: 'PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT', + }, + ou: { + id: 'ouokfwl9OEdl', + org_id: 'oroLKHBYQVvj', + }, +}; + export const mileageCategoryTransformedExpenseData: Partial = { ...transformedExpenseData, tx: { ...transformedExpenseData.tx, org_category: 'MILEAGE' }, diff --git a/src/app/core/mock-data/unflattened-txn.data.ts b/src/app/core/mock-data/unflattened-txn.data.ts index 61652dda29..5f4aa9484b 100644 --- a/src/app/core/mock-data/unflattened-txn.data.ts +++ b/src/app/core/mock-data/unflattened-txn.data.ts @@ -1819,6 +1819,15 @@ export const unflattenedExpWithCCCExpn1: UnflattenedTransaction = { }, }; +export const unflattenedExpWithoutCCExpnSync: UnflattenedTransaction = { + ...unflattenedExpWithCCCExpn, + tx: { + ...unflattenedExpWithCCCExpn.tx, + matched_corporate_card_transactions: [], + split_group_id: 'tx6I9xcOZFU6', + }, +}; + export const trackCreateExpData: UnflattenedTransaction = { ...unflattenedExp2, tx: { diff --git a/src/app/core/services/corporate-credit-card-expense.service.spec.ts b/src/app/core/services/corporate-credit-card-expense.service.spec.ts index dc4cb5be5a..0e631cbfbe 100644 --- a/src/app/core/services/corporate-credit-card-expense.service.spec.ts +++ b/src/app/core/services/corporate-credit-card-expense.service.spec.ts @@ -24,6 +24,7 @@ import { ccTransactionResponseData1, } from '../mock-data/corporate-card-transaction-response.data'; import { statementUploadedCardDetail } from '../mock-data/platform-corporate-card-detail.data'; +import { matchedCCTransactionData3 } from '../mock-data/matchedCCTransaction.data'; describe('CorporateCreditCardExpenseService', () => { let cccExpenseService: CorporateCreditCardExpenseService; @@ -107,6 +108,19 @@ describe('CorporateCreditCardExpenseService', () => { }); }); + it('getMatchedTransactionById(): should return the matched corporate card transaction with id', (done) => { + spenderPlatformV1ApiService.get.and.returnValue(of(ccTransactionResponseData)); + const id = 'btxnBdS2Kpvzhy'; + const params = { + id: 'eq.' + id, + }; + + cccExpenseService.getMatchedTransactionById(id).subscribe(() => { + expect(spenderPlatformV1ApiService.get).toHaveBeenCalledOnceWith('/corporate_card_transactions', { params }); + done(); + }); + }); + it('getAssignedCards(): should get all assigned cards', (done) => { const queryParams = 'in.(COMPLETE,DRAFT)'; authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); @@ -183,4 +197,9 @@ describe('CorporateCreditCardExpenseService', () => { const res = cccExpenseService.getBankFeedSources(); expect(res).toEqual(bankFeedSourcesData); }); + + it('transformCCTransaction(): should transform the corporate card transaction response to matched corporate card transaction', () => { + const res = cccExpenseService.transformCCTransaction(ccTransactionResponseData.data[0]); + expect(res).toEqual(matchedCCTransactionData3); + }); }); diff --git a/src/app/core/services/transaction.service.ts b/src/app/core/services/transaction.service.ts index 81bf2c7217..ffddfa274e 100644 --- a/src/app/core/services/transaction.service.ts +++ b/src/app/core/services/transaction.service.ts @@ -34,7 +34,6 @@ import { CurrencySummary } from '../models/currency-summary.model'; import { FilterQueryParams } from '../models/filter-query-params.model'; import { SortFiltersParams } from '../models/sort-filters-params.model'; import { PaymentModeSummary } from '../models/payment-mode-summary.model'; -import { Datum, StatsResponse } from '../models/v2/stats-response.model'; import { TxnCustomProperties } from '../models/txn-custom-properties.model'; import { PlatformMissingMandatoryFields } from '../models/platform/platform-missing-mandatory-fields.model'; import { PlatformMissingMandatoryFieldsResponse } from '../models/platform/platform-missing-mandatory-fields-response.model'; diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-6.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-6.spec.ts index 8658d9f381..3732552bb5 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-6.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-6.spec.ts @@ -30,7 +30,7 @@ import { checkSplitExpData1, checkSplitExpData2, unflattenedExpWithCCCExpn, - unflattenedExpWithCCCExpn1, + unflattenedExpWithoutCCExpnSync, } from 'src/app/core/mock-data/unflattened-txn.data'; import { BackButtonActionPriority } from 'src/app/core/models/back-button-action-priority.enum'; import { AccountsService } from 'src/app/core/services/accounts.service'; @@ -76,8 +76,11 @@ import { expenseData } from 'src/app/core/mock-data/platform/v1/expense.data'; import { transformedExpenseWithMatchCCCData, transformedExpenseWithMatchCCCData3, + transformedExpenseWithMatchCCCData4, } from 'src/app/core/mock-data/transformed-expense.data'; import { matchedCCTransactionData, matchedCCTransactionData2 } from 'src/app/core/mock-data/matchedCCTransaction.data'; +import { ccTransactionData, ccTransactionData1 } from 'src/app/core/mock-data/cc-transaction.data'; +import { ccTransactionResponseData } from 'src/app/core/mock-data/corporate-card-transaction-response.data'; export function TestCases6(getTestBed) { describe('AddEditExpensePage-6', () => { @@ -452,7 +455,8 @@ export function TestCases6(getTestBed) { component.initSplitTxn(of(orgSettingsData)); expect(expensesService.getSplitExpenses).toHaveBeenCalledOnceWith('tx3qHxFNgRcZ'); - expect(component.handleCCCExpenses).toHaveBeenCalledOnceWith(unflattenedExpWithCCCExpn); + expect(component.handleCCCExpenses).toHaveBeenCalledOnceWith(unflattenedExpWithCCCExpn, undefined); + expect(corporateCreditCardExpenseService.getMatchedTransactionById).not.toHaveBeenCalled(); expect(component.getSplitExpenses).toHaveBeenCalledOnceWith([expenseData, expenseData]); }); @@ -465,16 +469,47 @@ export function TestCases6(getTestBed) { component.initSplitTxn(of(orgSettingsParamWoCCC)); expect(expensesService.getSplitExpenses).toHaveBeenCalledOnceWith('tx3qHxFNgRcZ'); - expect(component.handleCCCExpenses).toHaveBeenCalledOnceWith(unflattenedExpWithCCCExpn); + expect(component.handleCCCExpenses).toHaveBeenCalledOnceWith(unflattenedExpWithCCCExpn, undefined); + expect(corporateCreditCardExpenseService.getMatchedTransactionById).not.toHaveBeenCalled(); + expect(component.getSplitExpenses).not.toHaveBeenCalledOnceWith([expenseData, expenseData]); + }); + + it('should initialize CCC expenses with group Id if not synced up', () => { + expensesService.getSplitExpenses.and.returnValue(of(null)); + corporateCreditCardExpenseService.getMatchedTransactionById.and.returnValue(of(ccTransactionResponseData)); + component.etxn$ = of(unflattenedExpWithoutCCExpnSync); + spyOn(component, 'handleCCCExpenses'); + spyOn(component, 'getSplitExpenses'); + fixture.detectChanges(); + + component.initSplitTxn(of(orgSettingsParamWoCCC)); + expect(expensesService.getSplitExpenses).toHaveBeenCalledOnceWith('tx6I9xcOZFU6'); + expect(component.handleCCCExpenses).toHaveBeenCalledOnceWith( + unflattenedExpWithoutCCExpnSync, + ccTransactionData1 + ); + expect(corporateCreditCardExpenseService.getMatchedTransactionById).toHaveBeenCalledOnceWith( + unflattenedExpWithoutCCExpnSync.tx.corporate_credit_card_expense_group_id + ); expect(component.getSplitExpenses).not.toHaveBeenCalledOnceWith([expenseData, expenseData]); }); }); describe('handleCCCExpenses():', () => { - it('should handle CCC expenses', () => { + it('should handle CCC expenses if expenses have matched_corporate_card_transaction synced', () => { + const date = new Date('2018-07-03T13:00:00.000Z'); + jasmine.clock().mockDate(date); + component.handleCCCExpenses(transformedExpenseWithMatchCCCData, null); + expect(component.cardNumber).toEqual('7620'); + expect(component.matchedCCCTransaction).toEqual(matchedCCTransactionData); + }); + + it('should handle CCC expenses if expense does not have matched_corporate_card_transaction synced', () => { const date = new Date('2018-07-03T13:00:00.000Z'); jasmine.clock().mockDate(date); - component.handleCCCExpenses(transformedExpenseWithMatchCCCData); + corporateCreditCardExpenseService.transformCCTransaction.and.returnValue(matchedCCTransactionData); + component.handleCCCExpenses(transformedExpenseWithMatchCCCData4, ccTransactionData); + expect(corporateCreditCardExpenseService.transformCCTransaction).toHaveBeenCalledOnceWith(ccTransactionData); expect(component.cardNumber).toEqual('7620'); expect(component.matchedCCCTransaction).toEqual(matchedCCTransactionData); }); @@ -482,7 +517,7 @@ export function TestCases6(getTestBed) { it('should show card digits and vendor description', () => { const date = new Date('2018-06-06T08:30:00.000Z'); jasmine.clock().mockDate(date); - component.handleCCCExpenses(transformedExpenseWithMatchCCCData3); + component.handleCCCExpenses(transformedExpenseWithMatchCCCData3, null); expect(component.cardNumber).toEqual('9891'); expect(component.matchedCCCTransaction).toEqual(matchedCCTransactionData2); }); diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts index 9748414c96..5bd9cc1fa8 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts @@ -147,6 +147,8 @@ describe('AddEditExpensePage', () => { const corporateCreditCardExpenseServiceSpy = jasmine.createSpyObj('CorporateCreditCardExpenseService', [ 'markPersonal', 'dismissCreditTransaction', + 'transformCCTransaction', + 'getMatchedTransactionById', ]); const trackingServiceSpy = jasmine.createSpyObj('TrackingService', [ 'viewExpense', From b28363aed0920e73a5ae63681a390cd45319cfd6 Mon Sep 17 00:00:00 2001 From: suyashpatil78 Date: Thu, 14 Mar 2024 14:44:09 +0530 Subject: [PATCH 2/3] removed false from my-profile to make commute visible --- src/app/fyle/my-profile/my-profile.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/fyle/my-profile/my-profile.page.html b/src/app/fyle/my-profile/my-profile.page.html index a24dc2d1b6..5a8b27134f 100644 --- a/src/app/fyle/my-profile/my-profile.page.html +++ b/src/app/fyle/my-profile/my-profile.page.html @@ -37,7 +37,7 @@ - +
Commute Details
Date: Thu, 14 Mar 2024 15:37:17 +0530 Subject: [PATCH 3/3] adjusted height for some devices --- src/global.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global.scss b/src/global.scss index fe5e121a3a..43cd702593 100644 --- a/src/global.scss +++ b/src/global.scss @@ -1006,7 +1006,7 @@ ion-modal.add-location-modal { &::part(content) { border-radius: 16px 16px 0 0 !important; position: absolute; - max-height: 40%; + max-height: 50%; bottom: 0; } }