Skip to content

Commit

Permalink
fix: make extra call for getting ccc status (#3118)
Browse files Browse the repository at this point in the history
* fix: make extra call for getting ccc status

* feat: added filter for other comps

* minor

* test: tests for newly added extra api call (#3119)

* test: tests for newly added extra api call

* test: component and page tests
  • Loading branch information
suyashpatil78 authored Jun 28, 2024
1 parent 51a50bb commit 30c5ab6
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 96 deletions.
181 changes: 181 additions & 0 deletions src/app/core/mock-data/corporate-card-transaction-response.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,184 @@ export const matchCCCExpenseResponseData: CorporateCardTransactionRes = deepFree
},
],
});

export const ccTransactionResponseData3: CorporateCardTransactionRes = deepFreeze({
data: [
{
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: 'btxn7DbV1VYnmT',
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,
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',
transaction_status: TransactionStatus.POSTED,
},
{
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,
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',
transaction_status: TransactionStatus.PENDING,
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export const unreportedExpensesQueryParams: ExpensesQueryParams = deepFreeze({
state: 'in.(COMPLETE)',
or: '(policy_amount.is.null,policy_amount.gt.0.0001)',
report_id: 'is.null',
and: '(or(matched_corporate_card_transactions.eq.[],matched_corporate_card_transactions->0->status.neq.PENDING))',
},
});
133 changes: 114 additions & 19 deletions src/app/core/services/platform/v1/spender/expenses.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ import {
import { splitPayloadData1 } from 'src/app/core/mock-data/split-payload.data';
import { splitPolicyExp1 } from 'src/app/core/mock-data/split-expense-policy.data';
import { SplitExpenseMissingFieldsData } from 'src/app/core/models/split-expense-missing-fields.data';
import { CorporateCreditCardExpenseService } from '../../../corporate-credit-card-expense.service';
import {
ccTransactionResponseData,
ccTransactionResponseData3,
} from 'src/app/core/mock-data/corporate-card-transaction-response.data';
import { cloneDeep } from 'lodash';
import { TransactionStatus } from 'src/app/core/models/platform/v1/expense.model';

describe('ExpensesService', () => {
let service: ExpensesService;
let spenderService: jasmine.SpyObj<SpenderService>;
let sharedExpenseService: jasmine.SpyObj<SharedExpenseService>;
let corporateCreditCardExpenseService: jasmine.SpyObj<CorporateCreditCardExpenseService>;

beforeEach(() => {
const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['get', 'post']);
const sharedExpenseServiceSpy = jasmine.createSpyObj('SharedExpenseService', ['generateStatsQueryParams']);
const corporateCreditCardExpenseServiceSpy = jasmine.createSpyObj('CorporateCreditCardExpenseService', [
'getMatchedTransactionById',
]);

TestBed.configureTestingModule({
providers: [
Expand All @@ -40,31 +51,71 @@ describe('ExpensesService', () => {
provide: PAGINATION_SIZE,
useValue: 2,
},
{
provide: CorporateCreditCardExpenseService,
useValue: corporateCreditCardExpenseServiceSpy,
},
],
});
service = TestBed.inject(ExpensesService);
spenderService = TestBed.inject(SpenderService) as jasmine.SpyObj<SpenderService>;
sharedExpenseService = TestBed.inject(SharedExpenseService) as jasmine.SpyObj<SharedExpenseService>;
corporateCreditCardExpenseService = TestBed.inject(
CorporateCreditCardExpenseService
) as jasmine.SpyObj<CorporateCreditCardExpenseService>;
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('getExpenseById(): should return expense with the given id', (done) => {
spenderService.get.and.returnValue(of({ data: [expenseData] }));
const expenseId = 'txOJVaaPxo9O';
describe('getExpenseById():', () => {
it('should return expense with the given id', (done) => {
spenderService.get.and.returnValue(of({ data: [expenseData] }));
const expenseId = 'txOJVaaPxo9O';

service.getExpenseById(expenseId).subscribe((response) => {
expect(response).toBeTruthy();
expect(response).toEqual(expenseData);
service.getExpenseById(expenseId).subscribe((response) => {
expect(response).toBeTruthy();
expect(response).toEqual(expenseData);

expect(spenderService.get).toHaveBeenCalledOnceWith(`/expenses`, {
params: {
id: `eq.${expenseId}`,
},
expect(spenderService.get).toHaveBeenCalledOnceWith(`/expenses`, {
params: {
id: `eq.${expenseId}`,
},
});
done();
});
});

it('should return expense with the given id and fill matched_corporate_card_transactions by making API call', (done) => {
const mockExpenseData = cloneDeep(expenseData);
mockExpenseData.matched_corporate_card_transactions = [];
mockExpenseData.matched_corporate_card_transaction_ids = ['btxnBdS2Kpvzhy'];
spenderService.get.and.returnValue(of({ data: [mockExpenseData] }));

const mockCCTransactionRes = cloneDeep(ccTransactionResponseData);
mockCCTransactionRes.data[0].transaction_status = TransactionStatus.PENDING;
corporateCreditCardExpenseService.getMatchedTransactionById.and.returnValue(of(mockCCTransactionRes));

const expenseId = 'txOJVaaPxo9O';

service.getExpenseById(expenseId).subscribe((response) => {
expect(response).toBeTruthy();

expect(spenderService.get).toHaveBeenCalledOnceWith(`/expenses`, {
params: {
id: `eq.${expenseId}`,
},
});

expect(corporateCreditCardExpenseService.getMatchedTransactionById).toHaveBeenCalledOnceWith('btxnBdS2Kpvzhy');

expect(response).toEqual(mockExpenseData);

expect(response.matched_corporate_card_transactions[0].status).toEqual(TransactionStatus.PENDING);

done();
});
done();
});
});

Expand All @@ -82,17 +133,61 @@ describe('ExpensesService', () => {
});
});

it('getExpenses(): should return the expenses', (done) => {
spenderService.get.and.returnValue(of(expensesResponse));
describe('getExpenses():', () => {
it('should return the expenses', (done) => {
spenderService.get.and.returnValue(of(expensesResponse));

service.getExpenses(getExpensesQueryParams).subscribe((response) => {
expect(response).toBeTruthy();
expect(response).toEqual(expensesResponse.data);
service.getExpenses(getExpensesQueryParams).subscribe((response) => {
expect(response).toBeTruthy();
expect(response).toEqual(expensesResponse.data);

expect(spenderService.get).toHaveBeenCalledOnceWith('/expenses', {
params: getExpensesQueryParams,
expect(spenderService.get).toHaveBeenCalledOnceWith('/expenses', {
params: getExpensesQueryParams,
});
done();
});
});

it('should return expenses with matched_corporate_card_transactions filled by calling API', (done) => {
const mockExpensesResponse = cloneDeep(expensesResponse);

const expenseWithUnmatchedCCTransactions = cloneDeep(expenseData);
expenseWithUnmatchedCCTransactions.matched_corporate_card_transactions = [];

const expenseWithUnmatchedCCTransactions2 = cloneDeep(expenseData);
expenseWithUnmatchedCCTransactions2.matched_corporate_card_transaction_ids = ['btxnBdS2Kpvzhy'];
expenseWithUnmatchedCCTransactions2.matched_corporate_card_transactions = [];

mockExpensesResponse.data = [
expenseWithUnmatchedCCTransactions,
expenseData,
expenseWithUnmatchedCCTransactions2,
];

spenderService.get.and.returnValues(of(mockExpensesResponse), of(ccTransactionResponseData3));

service.getExpenses(getExpensesQueryParams).subscribe((response) => {
expect(response).toBeTruthy();
expect(response).toEqual(mockExpensesResponse.data);

expect(spenderService.get).toHaveBeenCalledTimes(2);

expect(spenderService.get).toHaveBeenCalledWith('/expenses', {
params: getExpensesQueryParams,
});

expect(spenderService.get).toHaveBeenCalledWith('/corporate_card_transactions', {
params: {
id: 'in.(btxn7DbV1VYnmT,btxnBdS2Kpvzhy)',
},
});

expect(response[0].matched_corporate_card_transactions[0].status).toEqual(TransactionStatus.POSTED);
expect(response[1].matched_corporate_card_transactions[0].status).toEqual(TransactionStatus.PENDING);
expect(response[2].matched_corporate_card_transactions[0].status).toEqual(TransactionStatus.PENDING);

done();
});
done();
});
});

Expand Down
Loading

0 comments on commit 30c5ab6

Please sign in to comment.