Skip to content

Commit

Permalink
fix: Fixing 400 error in POST /platform/v1/spender/expenses/stats (#3011
Browse files Browse the repository at this point in the history
)

* Fixing expense/stats api error

* Changing tests

* Adding test for
  • Loading branch information
neohacker18 authored May 22, 2024
1 parent 50c74e3 commit 7fde337
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
28 changes: 26 additions & 2 deletions src/app/fyle/my-expenses/my-expenses.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ describe('MyExpensesV2Page', () => {
expect(expensesService.getExpenseStats).toHaveBeenCalledOnceWith({
report_id: 'is.null',
state: 'in.(COMPLETE,DRAFT)',
or: ['(matched_corporate_card_transactions->0->corporate_card_number.8698)'],
'matched_corporate_card_transactions->0->corporate_card_number': '8698',
});
expect(allExpenseStats).toEqual({
count: 3,
Expand Down Expand Up @@ -1196,7 +1196,31 @@ describe('MyExpensesV2Page', () => {
expect(expensesService.getExpenseStats).toHaveBeenCalledOnceWith({
report_id: 'is.null',
state: 'in.(COMPLETE,DRAFT)',
or: ['(matched_corporate_card_transactions->0->corporate_card_number.8698)'],
'matched_corporate_card_transactions->0->corporate_card_number': '8698',
});
});

it('should delete queryParams.state if queryParams.or contains an element with state', () => {
component.loadExpenses$ = new BehaviorSubject({
queryParams: {
or: ['state->DRAFT'],
'matched_corporate_card_transactions->0->corporate_card_number': '8698',
state: 'in.(COMPLETE,DRAFT)',
},
});

expensesService.getExpenseStats.and.returnValue(of(completeStats));
component.setAllExpensesCountAndAmount();
component.allExpensesStats$.subscribe((allExpenseStats) => {
expect(expensesService.getExpenseStats).toHaveBeenCalledOnceWith({
report_id: 'is.null',
or: ['state->DRAFT'],
'matched_corporate_card_transactions->0->corporate_card_number': '8698',
});
expect(allExpenseStats).toEqual({
count: 3,
amount: 30,
});
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/app/fyle/my-expenses/my-expenses.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ export class MyExpensesPage implements OnInit {
queryParams.report_id = (queryParams.report_id || 'is.null') as string;
queryParams.state = 'in.(COMPLETE,DRAFT)';

if (queryParams['matched_corporate_card_transactions->0->corporate_card_number']) {
const cardParamsCopy = queryParams['matched_corporate_card_transactions->0->corporate_card_number'] as string;

queryParams.or = (queryParams.or || []) as string[];
queryParams.or.push('(matched_corporate_card_transactions->0->corporate_card_number.' + cardParamsCopy + ')');
delete queryParams['matched_corporate_card_transactions->0->corporate_card_number'];
if (queryParams.or) {
const hasExpenseState =
Array.isArray(queryParams.or) && queryParams.or.some((element) => element.includes('state'));
if (hasExpenseState) {
delete queryParams.state;
}
}

return this.expenseService.getExpenseStats(queryParams).pipe(
Expand Down

0 comments on commit 7fde337

Please sign in to comment.