Skip to content

Commit

Permalink
Merge branch 'master' into Fyle-85ztzt5y6
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunaj5 authored Oct 4, 2023
2 parents b877a5a + 273febf commit d7d4fa3
Show file tree
Hide file tree
Showing 7 changed files with 659 additions and 117 deletions.
10 changes: 9 additions & 1 deletion src/app/core/mock-data/org-settings.data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AllowedPaymentModes } from '../models/allowed-payment-modes.enum';
import { OrgSettings, TaxSettings } from '../models/org-settings.model';
import { EmailEvents, OrgSettings, TaxSettings } from '../models/org-settings.model';
import { orgSettingsData } from '../test-data/accounts.service.spec.data';

export const orgSettingsRes: OrgSettings = {
Expand Down Expand Up @@ -1346,3 +1346,11 @@ export const orgSettingsWoMileage: OrgSettings = {
...orgSettingsParams2,
mileage: null,
};

export const orgSettingsWithUnsubscribeEvent: OrgSettings = {
...orgSettingsRes,
admin_email_settings: {
...orgSettingsRes.admin_email_settings,
unsubscribed_events: [EmailEvents.DELEGATOR_SUBSCRIPTION, EmailEvents.EADVANCES_CREATED],
},
};
27 changes: 27 additions & 0 deletions src/app/core/mock-data/org-user-settings.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,30 @@ export const orgUserSettingsWoProjects: OrgUserSettings = {
...orgUserSettingsData,
project_ids: null,
};

export const notificationDelegateeSettings1: OrgUserSettings = {
...orgUserSettingsData,
notification_settings: {
...orgUserSettingsData.notification_settings,
notify_delegatee: true,
notify_user: false,
},
};

export const notificationDelegateeSettings2: OrgUserSettings = {
...orgUserSettingsData,
notification_settings: {
...orgUserSettingsData.notification_settings,
notify_delegatee: false,
notify_user: true,
},
};

export const notificationDelegateeSettings3: OrgUserSettings = {
...orgUserSettingsData,
notification_settings: {
...orgUserSettingsData.notification_settings,
notify_delegatee: true,
notify_user: true,
},
};
17 changes: 15 additions & 2 deletions src/app/core/models/notification-events.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { EmailEvents as EE } from './org-settings.model';

export type EmailEvents = {
email: {
selected: boolean;
};
eventType: string;
eventType: string | EE;
feature: string;
push: {
selected: boolean;
Expand All @@ -14,7 +16,7 @@ export type EmailEvents = {
export interface NotificationEvents {
events: EmailEvents[];
features: {
advances: {
advances?: {
selected: boolean;
textLabel: string;
};
Expand All @@ -24,3 +26,14 @@ export interface NotificationEvents {
};
};
}

export interface NotificationEventFeatures {
advances: {
selected: boolean;
textLabel: string;
};
expensesAndReports: {
selected: boolean;
textLabel: string;
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
import { IonicModule, PopoverController } from '@ionic/angular';

import { AddCorporateCardComponent } from './add-corporate-card.component';
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('AddCorporateCardComponent', () => {
});

describe('card number validation errors', () => {
it('should show an error message when the user has entered an invalid card number', () => {
it('should show an error message when the user has entered an invalid card number', fakeAsync(() => {
realTimeFeedService.isCardNumberValid.and.returnValue(false);
realTimeFeedService.getCardTypeFromNumber.and.returnValue(CardNetworkType.OTHERS);

Expand All @@ -180,14 +180,15 @@ describe('AddCorporateCardComponent', () => {
cardNumberInput.dispatchEvent(new Event('input'));
cardNumberInput.dispatchEvent(new Event('blur'));

fixture.detectChanges();
tick(500);
fixture.detectChanges();

const errorMessage = getElementBySelector(fixture, '[data-testid="error-message"]') as HTMLElement;

expect(errorMessage.innerText).toBe('Please enter a valid card number.');
});
}));

it('should show an error message if only mastercard rtf is enabled but the user has entered a non-mastercard number', () => {
it('should show an error message if only mastercard rtf is enabled but the user has entered a non-mastercard number', fakeAsync(() => {
component.isMastercardRTFEnabled = true;
component.isVisaRTFEnabled = false;
component.isYodleeEnabled = false;
Expand All @@ -203,16 +204,18 @@ describe('AddCorporateCardComponent', () => {
cardNumberInput.dispatchEvent(new Event('input'));
cardNumberInput.dispatchEvent(new Event('blur'));

fixture.detectChanges();
tick(500);
fixture.detectChanges();

const errorMessage = getElementBySelector(fixture, '[data-testid="error-message"]') as HTMLElement;

expect(errorMessage.innerText).toBe(
'Enter a valid Mastercard number. If you have other cards, please contact your admin.'
);
});
}));

it('should show an error message if only visa rtf is enabled but the user has entered a non-visa number', () => {
it('should show an error message if only visa rtf is enabled but the user has entered a non-visa number', fakeAsync(() => {
component.isVisaRTFEnabled = true;
component.isMastercardRTFEnabled = false;
component.isYodleeEnabled = false;
Expand All @@ -228,16 +231,18 @@ describe('AddCorporateCardComponent', () => {
cardNumberInput.dispatchEvent(new Event('input'));
cardNumberInput.dispatchEvent(new Event('blur'));

fixture.detectChanges();
tick(500);
fixture.detectChanges();

const errorMessage = getElementBySelector(fixture, '[data-testid="error-message"]') as HTMLElement;

expect(errorMessage.innerText).toBe(
'Enter a valid Visa number. If you have other cards, please contact your admin.'
);
});
}));

it('should show an error message if user has entered a non visa/mastercard card number and yodlee is disabled in the org', () => {
it('should show an error message if user has entered a non visa/mastercard card number and yodlee is disabled in the org', fakeAsync(() => {
component.isVisaRTFEnabled = true;
component.isMastercardRTFEnabled = true;
component.isYodleeEnabled = false;
Expand All @@ -253,13 +258,15 @@ describe('AddCorporateCardComponent', () => {
cardNumberInput.dispatchEvent(new Event('input'));
cardNumberInput.dispatchEvent(new Event('blur'));

fixture.detectChanges();
tick(500);
fixture.detectChanges();

const errorMessage = getElementBySelector(fixture, '[data-testid="error-message"]') as HTMLElement;
expect(errorMessage.innerText).toBe(
'Enter a valid Visa or Mastercard number. If you have other cards, please contact your admin.'
);
});
}));
});

describe('card enrollment flow', () => {
Expand Down Expand Up @@ -313,7 +320,7 @@ describe('AddCorporateCardComponent', () => {
expect(trackingService.cardEnrolled).toHaveBeenCalledOnceWith(cardEnrolledProperties2);
});

it('should show the error message received from backend when we face api errors while enrolling the card', () => {
it('should show the error message received from backend when we face api errors while enrolling the card', fakeAsync(() => {
realTimeFeedService.isCardNumberValid.and.returnValue(true);
realTimeFeedService.getCardTypeFromNumber.and.returnValue(CardNetworkType.VISA);
realTimeFeedService.enroll.and.returnValue(throwError(() => new Error('This card already exists in the system')));
Expand All @@ -331,16 +338,18 @@ describe('AddCorporateCardComponent', () => {
const addCorporateCardBtn = getElementBySelector(fixture, '[data-testid="add-btn"]') as HTMLButtonElement;
addCorporateCardBtn.click();

fixture.detectChanges();
tick(500);
fixture.detectChanges();

const errorMessage = getElementBySelector(fixture, '[data-testid="error-message"]') as HTMLElement;

expect(realTimeFeedService.enroll).toHaveBeenCalledOnceWith('4555555555555555', null);
expect(errorMessage.innerText).toBe('This card already exists in the system');
expect(trackingService.cardEnrollmentErrors).toHaveBeenCalledWith(cardEnrollmentErrorsProperties1);
});
}));

it('should show a default error message when we face api errors from backend but we dont have the error message', () => {
it('should show a default error message when we face api errors from backend but we dont have the error message', fakeAsync(() => {
realTimeFeedService.isCardNumberValid.and.returnValue(true);
realTimeFeedService.getCardTypeFromNumber.and.returnValue(CardNetworkType.VISA);
realTimeFeedService.enroll.and.returnValue(throwError(() => new Error()));
Expand All @@ -358,14 +367,16 @@ describe('AddCorporateCardComponent', () => {
const addCorporateCardBtn = getElementBySelector(fixture, '[data-testid="add-btn"]') as HTMLButtonElement;
addCorporateCardBtn.click();

fixture.detectChanges();
tick(500);
fixture.detectChanges();

const errorMessage = getElementBySelector(fixture, '[data-testid="error-message"]') as HTMLElement;

expect(realTimeFeedService.enroll).toHaveBeenCalledOnceWith('4555555555555555', null);
expect(errorMessage.innerText).toBe('Something went wrong. Please try after some time.');
expect(trackingService.cardEnrollmentErrors).toHaveBeenCalledOnceWith(cardEnrollmentErrorsProperties2);
});
}));

it('should disallow card enrollment if the entered card number is invalid', () => {
realTimeFeedService.isCardNumberValid.and.returnValue(false);
Expand Down
Loading

0 comments on commit d7d4fa3

Please sign in to comment.