Skip to content

Commit

Permalink
test: fixed unit tests for handle_ccc_expense method (#2827)
Browse files Browse the repository at this point in the history
* fixed unit tests for handle_ccc_expense method

* fixed the unit test for the changes
  • Loading branch information
devendrafyle authored Mar 14, 2024
1 parent cd07d7d commit ea4ce2e
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 7 deletions.
196 changes: 196 additions & 0 deletions src/app/core/mock-data/cc-transaction.data.ts
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
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: '[email protected]',
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: '[email protected]',
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: '[email protected]',
full_name: 'Devendra Singh Rana',
id: 'usvMoPfCC9Xw',
},
user_id: 'usvMoPfCC9Xw',
};
19 changes: 19 additions & 0 deletions src/app/core/mock-data/matchedCCTransaction.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ export const matchedCCTransactionData2: Partial<MatchedCCCTransaction> = {
status: TransactionStatus.PENDING,
displayObject: 'Jun 6, 2018 - test description205.21',
};

export const matchedCCTransactionData3: Partial<MatchedCCCTransaction> = {
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,
};
68 changes: 68 additions & 0 deletions src/app/core/mock-data/transformed-expense.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,74 @@ export const transformedExpenseWithMatchCCCData3: Partial<UnflattenedTransaction
},
};

export const transformedExpenseWithMatchCCCData4: Partial<UnflattenedTransaction> = {
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<UnflattenedTransaction> = {
...transformedExpenseData,
tx: { ...transformedExpenseData.tx, org_category: 'MILEAGE' },
Expand Down
9 changes: 9 additions & 0 deletions src/app/core/mock-data/unflattened-txn.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
});
});
1 change: 0 additions & 1 deletion src/app/core/services/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading

0 comments on commit ea4ce2e

Please sign in to comment.