Skip to content

Commit

Permalink
feat: added trackers for mobile number verification (#2894)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
suyashpatil78 committed Apr 29, 2024
1 parent 8d91126 commit 0dffe16
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/app/core/services/payment-modes.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
});
});
});
15 changes: 13 additions & 2 deletions src/app/core/services/payment-modes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PaymentModesService {
private trackingService: TrackingService
) {}

checkIfPaymentModeConfigurationsIsEnabled() {
checkIfPaymentModeConfigurationsIsEnabled(): Observable<boolean> {
return this.orgUserSettingsService
.get()
.pipe(
Expand Down Expand Up @@ -92,12 +92,23 @@ 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 }),
panelClass: ['msb-failure-with-report-btn'],
});
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';
}
}
}
4 changes: 2 additions & 2 deletions src/app/core/services/tracking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions src/app/fyle/my-profile/my-profile.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +56,7 @@ describe('MyProfilePage', () => {
let matSnackBar: jasmine.SpyObj<MatSnackBar>;
let snackbarProperties: jasmine.SpyObj<SnackbarPropertiesService>;
let activatedRoute: jasmine.SpyObj<ActivatedRoute>;
let paymentModeService: jasmine.SpyObj<PaymentModesService>;

beforeEach(waitForAsync(() => {
const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou', 'logout', 'refreshEou']);
Expand All @@ -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],
Expand Down Expand Up @@ -156,6 +160,10 @@ describe('MyProfilePage', () => {
provide: SnackbarPropertiesService,
useValue: snackbarPropertiesSpy,
},
{
provide: PaymentModesService,
useValue: paymentModeServiceSpy,
},
SpenderService,
],
}).compileComponents();
Expand All @@ -180,6 +188,7 @@ describe('MyProfilePage', () => {
matSnackBar = TestBed.inject(MatSnackBar) as jasmine.SpyObj<MatSnackBar>;
snackbarProperties = TestBed.inject(SnackbarPropertiesService) as jasmine.SpyObj<SnackbarPropertiesService>;
activatedRoute = TestBed.inject(ActivatedRoute) as jasmine.SpyObj<ActivatedRoute>;
paymentModeService = TestBed.inject(PaymentModesService) as jasmine.SpyObj<PaymentModesService>;

component.loadEou$ = new BehaviorSubject(null);
component.eou$ = of(apiEouRes);
Expand Down Expand Up @@ -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();
Expand All @@ -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', () => {
Expand Down
29 changes: 27 additions & 2 deletions src/app/fyle/my-profile/my-profile.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -214,6 +227,8 @@ export class MyProfilePage {

this.mileageDistanceUnit = this.orgSettings.mileage?.unit;

this.defaultPaymentMode = this.getDefaultPaymentMode();

if (this.isMileageEnabled && this.isCommuteDeductionEnabled) {
this.setCommuteDetails();
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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,
});
}

Expand Down

0 comments on commit 0dffe16

Please sign in to comment.