Skip to content

Commit

Permalink
fix: migrate postAccounts personal card to platform (#3294)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumrender authored Dec 4, 2024
1 parent e66e806 commit 7da25a2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/app/core/services/personal-cards.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
11 changes: 10 additions & 1 deletion src/app/core/services/personal-cards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,16 @@ export class PersonalCardsService {
return pageContentUrl;
}

postBankAccounts(requestIds: string[]): Observable<string[]> {
postBankAccountsPlatform(): Observable<PlatformPersonalCard[]> {
return this.spenderPlatformV1ApiService
.post<PlatformApiResponse<PlatformPersonalCard[]>>('/personal_cards', { data: {} })
.pipe(map((res) => res.data));
}

postBankAccounts(requestIds: string[], usePlatformApi: boolean): Observable<string[] | PlatformPersonalCard[]> {
if (usePlatformApi) {
return this.postBankAccountsPlatform();
}
return this.expenseAggregationService.post('/yodlee/personal/bank_accounts', {
aggregator: 'yodlee',
request_ids: requestIds,
Expand Down
6 changes: 4 additions & 2 deletions src/app/fyle/personal-cards/personal-cards.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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: {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/app/fyle/personal-cards/personal-cards.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
Expand Down

0 comments on commit 7da25a2

Please sign in to comment.