From 0dffe16b5565a5b84df1bf9544df082fcd9e8cc3 Mon Sep 17 00:00:00 2001 From: Suyash Patil <127177049+suyashpatil78@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:48:57 +0530 Subject: [PATCH] feat: added trackers for mobile number verification (#2894) * feat: added trackers for mobile number verification * pr comments * minor * test: added test for trackers for mobile verification (#2896) * test: added test for trackers for mobile verification * minor * minor --- .../services/payment-modes.service.spec.ts | 18 ++++++++++++ .../core/services/payment-modes.service.ts | 15 ++++++++-- src/app/core/services/tracking.service.ts | 4 +-- .../fyle/my-profile/my-profile.page.spec.ts | 14 +++++++++ src/app/fyle/my-profile/my-profile.page.ts | 29 +++++++++++++++++-- 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/app/core/services/payment-modes.service.spec.ts b/src/app/core/services/payment-modes.service.spec.ts index 12fbee2f38..6d478f420f 100644 --- a/src/app/core/services/payment-modes.service.spec.ts +++ b/src/app/core/services/payment-modes.service.spec.ts @@ -21,6 +21,7 @@ import { cccOnlyPaymentModeSettingsParam, reimbursableOnlyPaymentModeSettingsParam, } from '../mock-data/org-payment-mode-settings.data'; +import { AllowedPaymentModes } from '../models/allowed-payment-modes.enum'; describe('PaymentModesService', () => { let paymentModesService: PaymentModesService; @@ -196,4 +197,21 @@ describe('PaymentModesService', () => { expect(paymentModesService.isNonReimbursableOrg(cccAndReimbursablePaymentModeSettingsParam)).toBeFalse(); }); }); + + describe('getPaymentModeDisplayName():', () => { + it('should return Personal Advances if payment mode is PERSONAL_ADVANCE_ACCOUNT', () => { + const paymentMode = AllowedPaymentModes.PERSONAL_ADVANCE_ACCOUNT; + expect(paymentModesService.getPaymentModeDisplayName(paymentMode)).toEqual('Personal Advances'); + }); + + it('should return Corporate Credit Card if payment mode is PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT', () => { + const paymentMode = AllowedPaymentModes.PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT; + expect(paymentModesService.getPaymentModeDisplayName(paymentMode)).toEqual('Corporate Credit Card'); + }); + + it('should return Personal Cash/Card if payment mode is not PERSONAL_ADVANCE_ACCOUNT or PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT', () => { + const paymentMode = AllowedPaymentModes.PERSONAL_ACCOUNT; + expect(paymentModesService.getPaymentModeDisplayName(paymentMode)).toEqual('Personal Cash/Card'); + }); + }); }); diff --git a/src/app/core/services/payment-modes.service.ts b/src/app/core/services/payment-modes.service.ts index c077054203..6b9997b9b3 100644 --- a/src/app/core/services/payment-modes.service.ts +++ b/src/app/core/services/payment-modes.service.ts @@ -26,7 +26,7 @@ export class PaymentModesService { private trackingService: TrackingService ) {} - checkIfPaymentModeConfigurationsIsEnabled() { + checkIfPaymentModeConfigurationsIsEnabled(): Observable { return this.orgUserSettingsService .get() .pipe( @@ -92,7 +92,7 @@ export class PaymentModesService { return false; } - showInvalidPaymentModeToast() { + showInvalidPaymentModeToast(): void { const message = 'Insufficient balance in the selected account. Please choose a different payment mode.'; this.matSnackBar.openFromComponent(ToastMessageComponent, { ...this.snackbarProperties.setSnackbarProperties('failure', { message }), @@ -100,4 +100,15 @@ export class PaymentModesService { }); this.trackingService.showToastMessage({ ToastContent: message }); } + + getPaymentModeDisplayName(paymentMode: AllowedPaymentModes): string { + switch (paymentMode) { + case AllowedPaymentModes.PERSONAL_ADVANCE_ACCOUNT: + return 'Personal Advances'; + case AllowedPaymentModes.PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT: + return 'Corporate Credit Card'; + default: + return 'Personal Cash/Card'; + } + } } diff --git a/src/app/core/services/tracking.service.ts b/src/app/core/services/tracking.service.ts index 2052d885bd..8c4abee614 100644 --- a/src/app/core/services/tracking.service.ts +++ b/src/app/core/services/tracking.service.ts @@ -645,8 +645,8 @@ export class TrackingService { this.eventTrack('Verify Mobile Number'); } - mobileNumberVerified(): void { - this.eventTrack('Mobile Number Verified'); + mobileNumberVerified(properties = {}): void { + this.eventTrack('Mobile Number Verified', properties); } smsDeepLinkOpened(properties = {}): void { diff --git a/src/app/fyle/my-profile/my-profile.page.spec.ts b/src/app/fyle/my-profile/my-profile.page.spec.ts index b892bc07a8..1875dfc593 100644 --- a/src/app/fyle/my-profile/my-profile.page.spec.ts +++ b/src/app/fyle/my-profile/my-profile.page.spec.ts @@ -34,6 +34,8 @@ import { orgData1 } from 'src/app/core/mock-data/org.data'; import { SpenderService } from 'src/app/core/services/platform/v1/spender/spender.service'; import { HttpClient } from '@angular/common/http'; import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { PaymentModesService } from 'src/app/core/services/payment-modes.service'; +import { AllowedPaymentModes } from 'src/app/core/models/allowed-payment-modes.enum'; describe('MyProfilePage', () => { let component: MyProfilePage; @@ -54,6 +56,7 @@ describe('MyProfilePage', () => { let matSnackBar: jasmine.SpyObj; let snackbarProperties: jasmine.SpyObj; let activatedRoute: jasmine.SpyObj; + let paymentModeService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou', 'logout', 'refreshEou']); @@ -77,6 +80,7 @@ describe('MyProfilePage', () => { const popoverControllerSpy = jasmine.createSpyObj('PopoverController', ['create']); const matSnackBarSpy = jasmine.createSpyObj('MatSnackBar', ['openFromComponent']); const snackbarPropertiesSpy = jasmine.createSpyObj('SnackbarPropertiesService', ['setSnackbarProperties']); + const paymentModeServiceSpy = jasmine.createSpyObj('PaymentModesService', ['getPaymentModeDisplayName']); TestBed.configureTestingModule({ declarations: [MyProfilePage], @@ -156,6 +160,10 @@ describe('MyProfilePage', () => { provide: SnackbarPropertiesService, useValue: snackbarPropertiesSpy, }, + { + provide: PaymentModesService, + useValue: paymentModeServiceSpy, + }, SpenderService, ], }).compileComponents(); @@ -180,6 +188,7 @@ describe('MyProfilePage', () => { matSnackBar = TestBed.inject(MatSnackBar) as jasmine.SpyObj; snackbarProperties = TestBed.inject(SnackbarPropertiesService) as jasmine.SpyObj; activatedRoute = TestBed.inject(ActivatedRoute) as jasmine.SpyObj; + paymentModeService = TestBed.inject(PaymentModesService) as jasmine.SpyObj; component.loadEou$ = new BehaviorSubject(null); component.eou$ = of(apiEouRes); @@ -379,6 +388,7 @@ describe('MyProfilePage', () => { spyOn(component, 'setInfoCardsData'); spyOn(component, 'setPreferenceSettings'); spyOn(component, 'setCCCFlags'); + paymentModeService.getPaymentModeDisplayName.and.returnValue('Personal Cash/Card'); fixture.detectChanges(); component.reset(); @@ -395,6 +405,10 @@ describe('MyProfilePage', () => { expect(component.orgUserSettings).toEqual(orgUserSettingsData); expect(component.orgSettings).toEqual(orgSettingsData); + expect(paymentModeService.getPaymentModeDisplayName).toHaveBeenCalledOnceWith( + orgSettingsData.payment_mode_settings.payment_modes_order[0] + ); + expect(component.defaultPaymentMode).toEqual('Personal Cash/Card'); })); it('setCCCFlags(): should set ccc flags as per the org and org user settings', () => { diff --git a/src/app/fyle/my-profile/my-profile.page.ts b/src/app/fyle/my-profile/my-profile.page.ts index 07064f3e51..e83437d800 100644 --- a/src/app/fyle/my-profile/my-profile.page.ts +++ b/src/app/fyle/my-profile/my-profile.page.ts @@ -39,6 +39,7 @@ import { ModalPropertiesService } from 'src/app/core/services/modal-properties.s import { ToastType } from 'src/app/core/enums/toast-type.enum'; import { EmployeesService } from 'src/app/core/services/platform/v1/spender/employees.service'; import { CommuteDetailsResponse } from 'src/app/core/models/platform/commute-details-response.model'; +import { PaymentModesService } from 'src/app/core/services/payment-modes.service'; @Component({ selector: 'app-my-profile', @@ -84,10 +85,16 @@ export class MyProfilePage { isMastercardRTFEnabled: boolean; + isAmexFeedEnabled: boolean; + isMileageEnabled: boolean; isCommuteDeductionEnabled: boolean; + isRTFEnabled: boolean; + + defaultPaymentMode: string; + constructor( private authService: AuthService, private orgUserSettingsService: OrgUserSettingsService, @@ -108,7 +115,8 @@ export class MyProfilePage { private activatedRoute: ActivatedRoute, private modalController: ModalController, private modalProperties: ModalPropertiesService, - private employeesService: EmployeesService + private employeesService: EmployeesService, + private paymentModeService: PaymentModesService ) {} setupNetworkWatcher(): void { @@ -187,6 +195,11 @@ export class MyProfilePage { } } + getDefaultPaymentMode(): string { + const paymentMode = this.orgSettings.payment_mode_settings?.payment_modes_order?.[0]; + return this.paymentModeService.getPaymentModeDisplayName(paymentMode); + } + reset(): void { const orgUserSettings$ = this.orgUserSettingsService.get().pipe(shareReplay(1)); this.org$ = this.orgService.getCurrentOrg(); @@ -214,6 +227,8 @@ export class MyProfilePage { this.mileageDistanceUnit = this.orgSettings.mileage?.unit; + this.defaultPaymentMode = this.getDefaultPaymentMode(); + if (this.isMileageEnabled && this.isCommuteDeductionEnabled) { this.setCommuteDetails(); } @@ -243,6 +258,11 @@ export class MyProfilePage { this.isMastercardRTFEnabled = this.orgSettings.mastercard_enrollment_settings.allowed && this.orgSettings.mastercard_enrollment_settings.enabled; + + this.isAmexFeedEnabled = + this.orgSettings.amex_feed_enrollment_settings.allowed && this.orgSettings.amex_feed_enrollment_settings.enabled; + + this.isRTFEnabled = this.isVisaRTFEnabled || this.isMastercardRTFEnabled || this.isAmexFeedEnabled; } setPreferenceSettings(): void { @@ -340,7 +360,10 @@ export class MyProfilePage { await verificationSuccessfulPopover.present(); await verificationSuccessfulPopover.onWillDismiss(); - this.trackingService.mobileNumberVerified(); + this.trackingService.mobileNumberVerified({ + isRtfEnabled: this.isRTFEnabled, + defaultPaymentMode: this.defaultPaymentMode, + }); } async verifyMobileNumber(eou: ExtendedOrgUser): Promise { @@ -415,6 +438,8 @@ export class MyProfilePage { this.trackingService.updateMobileNumber({ popoverTitle: (eou.ou.mobile?.length ? 'Edit' : 'Add') + ' Mobile Number', + isRtfEnabled: this.isRTFEnabled, + defaultPaymentMode: this.defaultPaymentMode, }); }