From 7da25a21ec2e749225fab855442330dc9c9f6113 Mon Sep 17 00:00:00 2001 From: Sumrender Singh <78428003+sumrender@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:37:41 +0530 Subject: [PATCH] fix: migrate postAccounts personal card to platform (#3294) --- .../services/personal-cards.service.spec.ts | 29 +++++++++++++++++++ .../core/services/personal-cards.service.ts | 11 ++++++- .../personal-cards.page.spec.ts | 6 ++-- .../personal-cards/personal-cards.page.ts | 2 +- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/app/core/services/personal-cards.service.spec.ts b/src/app/core/services/personal-cards.service.spec.ts index 930b32f1bd..89edb5070c 100644 --- a/src/app/core/services/personal-cards.service.spec.ts +++ b/src/app/core/services/personal-cards.service.spec.ts @@ -310,6 +310,35 @@ describe('PersonalCardsService', () => { }); }); + describe('postBankAccounts()', () => { + it('should link personal cards using public api', (done) => { + const requestIds = ['bacc0dtQ3ESjjQ']; + const usePlatformApi = false; + expenseAggregationService.post.and.returnValue(of(requestIds)); + + personalCardsService.postBankAccounts(requestIds, usePlatformApi).subscribe((res) => { + expect(res).toEqual(requestIds); + expect(expenseAggregationService.post).toHaveBeenCalledOnceWith('/yodlee/personal/bank_accounts', { + aggregator: 'yodlee', + request_ids: requestIds, + }); + done(); + }); + }); + + it('should link personal cards using platform api', (done) => { + const requestIds = ['bacc0dtQ3ESjjQ']; + const usePlatformApi = true; + spenderPlatformV1ApiService.post.and.returnValue(of(platformApiLinkedAccRes)); + + personalCardsService.postBankAccounts(requestIds, usePlatformApi).subscribe((res) => { + expect(res).toEqual(platformApiLinkedAccRes.data); + expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/personal_cards', { data: {} }); + done(); + }); + }); + }); + it('convertFilters(): should convert selected filters', () => { expect(personalCardsService.convertFilters(selectedFilters1)).toEqual(filterData1); }); diff --git a/src/app/core/services/personal-cards.service.ts b/src/app/core/services/personal-cards.service.ts index caef7afe86..e0bf6feb85 100644 --- a/src/app/core/services/personal-cards.service.ts +++ b/src/app/core/services/personal-cards.service.ts @@ -187,7 +187,16 @@ export class PersonalCardsService { return pageContentUrl; } - postBankAccounts(requestIds: string[]): Observable { + postBankAccountsPlatform(): Observable { + return this.spenderPlatformV1ApiService + .post>('/personal_cards', { data: {} }) + .pipe(map((res) => res.data)); + } + + postBankAccounts(requestIds: string[], usePlatformApi: boolean): Observable { + if (usePlatformApi) { + return this.postBankAccountsPlatform(); + } return this.expenseAggregationService.post('/yodlee/personal/bank_accounts', { aggregator: 'yodlee', request_ids: requestIds, diff --git a/src/app/fyle/personal-cards/personal-cards.page.spec.ts b/src/app/fyle/personal-cards/personal-cards.page.spec.ts index 7540fc8b93..b0770366ba 100644 --- a/src/app/fyle/personal-cards/personal-cards.page.spec.ts +++ b/src/app/fyle/personal-cards/personal-cards.page.spec.ts @@ -269,6 +269,7 @@ describe('PersonalCardsPage', () => { describe('postAccounts():', () => { it('should post account data with 1 card', fakeAsync(() => { + const usePlatformApi = false; const message = '1 card successfully added to Fyle!'; const props = { data: { @@ -289,7 +290,7 @@ describe('PersonalCardsPage', () => { expect(loaderService.showLoader).toHaveBeenCalledTimes(1); expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); - expect(personalCardsService.postBankAccounts).toHaveBeenCalledOnceWith(['id123']); + expect(personalCardsService.postBankAccounts).toHaveBeenCalledOnceWith(['id123'], usePlatformApi); expect(component.loadCardData$.next).toHaveBeenCalledOnceWith({}); expect(matSnackBar.openFromComponent).toHaveBeenCalledOnceWith(ToastMessageComponent, { ...props, @@ -300,6 +301,7 @@ describe('PersonalCardsPage', () => { })); it('should post account data for multiple cards', fakeAsync(() => { + const usePlatformApi = false; const message = '2 cards successfully added to Fyle!'; const props = { data: { @@ -320,7 +322,7 @@ describe('PersonalCardsPage', () => { expect(loaderService.showLoader).toHaveBeenCalledTimes(1); expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); - expect(personalCardsService.postBankAccounts).toHaveBeenCalledOnceWith(['id123']); + expect(personalCardsService.postBankAccounts).toHaveBeenCalledOnceWith(['id123'], usePlatformApi); expect(component.loadCardData$.next).toHaveBeenCalledOnceWith({}); expect(matSnackBar.openFromComponent).toHaveBeenCalledOnceWith(ToastMessageComponent, { ...props, diff --git a/src/app/fyle/personal-cards/personal-cards.page.ts b/src/app/fyle/personal-cards/personal-cards.page.ts index 0217395f69..38f3bb65b8 100644 --- a/src/app/fyle/personal-cards/personal-cards.page.ts +++ b/src/app/fyle/personal-cards/personal-cards.page.ts @@ -384,7 +384,7 @@ export class PersonalCardsPage implements OnInit, AfterViewInit { postAccounts(requestIds: string[]): void { from(this.loaderService.showLoader('Linking your card with Fyle...', 30000)) .pipe( - switchMap(() => this.personalCardsService.postBankAccounts(requestIds)), + switchMap(() => this.personalCardsService.postBankAccounts(requestIds, this.usePlatformApi)), finalize(async () => { await this.loaderService.hideLoader(); })