diff --git a/src/app/core/services/tasks.service.spec.ts b/src/app/core/services/tasks.service.spec.ts index 8670123d2f..aa744cb117 100644 --- a/src/app/core/services/tasks.service.spec.ts +++ b/src/app/core/services/tasks.service.spec.ts @@ -40,7 +40,7 @@ import { sentBackReportTaskSingularSample, verifyMobileNumberTask2, } from '../mock-data/task.data'; -import { mastercardRTFCard } from '../mock-data/platform-corporate-card.data'; +import { mastercardRTFCard, statementUploadedCard, visaRTFCard } from '../mock-data/platform-corporate-card.data'; import { OrgSettingsService } from './org-settings.service'; import { ExpensesService } from './platform/v1/spender/expenses.service'; import { expenseDuplicateSets } from '../mock-data/platform/v1/expense-duplicate-sets.data'; @@ -66,7 +66,6 @@ import { expectedSentBackResponse, expectedSentBackResponseSingularReport, } from '../mock-data/report-stats.data'; -import { expectedReportsSinglePage } from '../mock-data/platform-report.data'; import { OrgService } from './org.service'; import { orgData1 } from '../mock-data/org.data'; import { UtilityService } from './utility.service'; @@ -421,6 +420,30 @@ describe('TasksService', () => { }); }); + describe('getAddCorporateCardTask(): ', () => { + it('should return add corporate card task when no cards are enrolled', (done) => { + orgSettingsService.get.and.returnValue(of(orgSettingsRes)); + corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([statementUploadedCard])); + const addCcSpy = spyOn(tasksService, 'mapAddCorporateCardTask'); + + tasksService.getAddCorporateCardTask().subscribe((tasks) => { + expect(corporateCreditCardExpenseService.getCorporateCards).toHaveBeenCalled(); + expect(tasksService.mapAddCorporateCardTask).toHaveBeenCalled(); + expect(addCcSpy).toHaveBeenCalledOnceWith(); + done(); + }); + }); + + it('should return undefined when there are enrolled cards', (done) => { + corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([mastercardRTFCard, visaRTFCard])); + tasksService.getAddCorporateCardTask().subscribe((tasks) => { + expect(corporateCreditCardExpenseService.getCorporateCards).toHaveBeenCalled(); + expect(tasks).toEqual([]); + done(); + }); + }); + }); + it('should be able to fetch advancesTaskCount', (done) => { tasksService.advancesTaskCount$.next(10); tasksService @@ -780,6 +803,7 @@ describe('TasksService', () => { corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([mastercardRTFCard])); orgSettingsService.get.and.returnValue(of(orgSettingsRes)); employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData)); + corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([mastercardRTFCard])); } it('should be able to fetch tasks with no filters', (done) => { diff --git a/src/app/core/services/tasks.service.ts b/src/app/core/services/tasks.service.ts index db75d7ebf4..abe31f437c 100644 --- a/src/app/core/services/tasks.service.ts +++ b/src/app/core/services/tasks.service.ts @@ -532,11 +532,18 @@ export class TasksService { } getAddCorporateCardTask(): Observable { - return this.corporateCreditCardExpenseService.getCorporateCards().pipe( - map((cards) => { + return forkJoin([this.orgSettingsService.get(), this.corporateCreditCardExpenseService.getCorporateCards()]).pipe( + map(([orgSettings, cards]) => { + const isRtfEnabled = + (orgSettings.visa_enrollment_settings.allowed && orgSettings.visa_enrollment_settings.enabled) || + (orgSettings.mastercard_enrollment_settings.allowed && orgSettings.mastercard_enrollment_settings.enabled); + const isCCCEnabled = + orgSettings.corporate_credit_card_settings.allowed && orgSettings.corporate_credit_card_settings.enabled; const rtfCards = cards.filter((card) => card.is_visa_enrolled || card.is_mastercard_enrolled); - if (rtfCards.length === 0) { + if (isRtfEnabled && isCCCEnabled && rtfCards.length === 0) { return this.mapAddCorporateCardTask(); + } else { + return [] as DashboardTask[]; } }) ); diff --git a/src/app/fyle/dashboard/tasks/tasks-1.component.spec.ts b/src/app/fyle/dashboard/tasks/tasks-1.component.spec.ts index 2a46d98304..3b4fe5e605 100644 --- a/src/app/fyle/dashboard/tasks/tasks-1.component.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks-1.component.spec.ts @@ -41,6 +41,8 @@ import { taskCtaData8, taskCtaData9, } from 'src/app/core/mock-data/task-cta.data'; +import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; +import { orgSettingsPendingRestrictions } from 'src/app/core/mock-data/org-settings.data'; export function TestCases1(getTestBed) { return describe('test case set 1', () => { @@ -60,6 +62,7 @@ export function TestCases1(getTestBed) { let router: jasmine.SpyObj; let activatedRoute: jasmine.SpyObj; let networkService: jasmine.SpyObj; + let orgSettingsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const TestBed = getTestBed(); @@ -79,6 +82,7 @@ export function TestCases1(getTestBed) { router = TestBed.inject(Router) as jasmine.SpyObj; activatedRoute = TestBed.inject(ActivatedRoute) as jasmine.SpyObj; networkService = TestBed.inject(NetworkService) as jasmine.SpyObj; + orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; })); it('should create', () => { @@ -86,6 +90,10 @@ export function TestCases1(getTestBed) { }); it('ngOnInit(): should call setupNetworkWatcher once', () => { + orgSettingsService.get.and.returnValue(of(orgSettingsPendingRestrictions)); + component.isVisaRTFEnabled$ = of(true); + component.isMastercardRTFEnabled$ = of(true); + component.isYodleeEnabled$ = of(true); spyOn(component, 'setupNetworkWatcher'); fixture.detectChanges(); diff --git a/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts b/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts index 24b14558fa..5d9b781bfb 100644 --- a/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts @@ -1,5 +1,5 @@ import { ComponentFixture, fakeAsync, tick, waitForAsync } from '@angular/core/testing'; -import { ModalController } from '@ionic/angular'; +import { ModalController, PopoverController } from '@ionic/angular'; import { TasksComponent } from './tasks.component'; import { TasksService } from 'src/app/core/services/tasks.service'; @@ -48,6 +48,12 @@ import { apiEouRes } from 'src/app/core/mock-data/extended-org-user.data'; import { OrgService } from 'src/app/core/services/org.service'; import { orgData1 } from 'src/app/core/mock-data/org.data'; import { FyOptInComponent } from 'src/app/shared/components/fy-opt-in/fy-opt-in.component'; +import { Component, Input } from '@angular/core'; +import { AddCorporateCardComponent } from '../../manage-corporate-cards/add-corporate-card/add-corporate-card.component'; +import { By } from '@angular/platform-browser'; +import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; +import { CorporateCreditCardExpenseService } from 'src/app/core/services/corporate-credit-card-expense.service'; +import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; export function TestCases2(getTestBed) { return describe('test case set 2', () => { @@ -71,6 +77,10 @@ export function TestCases2(getTestBed) { let spenderReportsService: jasmine.SpyObj; let approverReportsService: jasmine.SpyObj; let orgService: jasmine.SpyObj; + let popoverController: jasmine.SpyObj; + let orgUserSettingsService: jasmine.SpyObj; + let corporateCreditCardExpenseService: jasmine.SpyObj; + let orgSettingsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const TestBed = getTestBed(); @@ -94,6 +104,14 @@ export function TestCases2(getTestBed) { spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; approverReportsService = TestBed.inject(ApproverReportsService) as jasmine.SpyObj; orgService = TestBed.inject(OrgService) as jasmine.SpyObj; + popoverController = TestBed.inject(PopoverController) as jasmine.SpyObj; + orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; + corporateCreditCardExpenseService = TestBed.inject( + CorporateCreditCardExpenseService + ) as jasmine.SpyObj; + let addCardPopoverSpy: jasmine.SpyObj; + popoverController.create.and.returnValues(Promise.resolve(addCardPopoverSpy)); + orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; })); describe('init():', () => { @@ -182,6 +200,37 @@ export function TestCases2(getTestBed) { }); }); + it('onAddCorporateCardClick(): should open card popover', fakeAsync(() => { + // Mock the observables + component.isVisaRTFEnabled$ = of(true); + component.isMastercardRTFEnabled$ = of(true); + component.isYodleeEnabled$ = of(true); + + // Mock the PopoverController + const addCardPopoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present', 'onDidDismiss']); + addCardPopoverSpy.present.and.resolveTo(); + addCardPopoverSpy.onDidDismiss.and.resolveTo({}); + + popoverController.create.and.resolveTo(addCardPopoverSpy); + + // Call the method + component.onAddCorporateCardClick(); + tick(); + + // Assert popover creation + expect(popoverController.create).toHaveBeenCalledOnceWith({ + component: AddCorporateCardComponent, + cssClass: 'fy-dialog-popover', + componentProps: { + isVisaRTFEnabled: true, + isMastercardRTFEnabled: true, + isYodleeEnabled: true, + }, + }); + + expect(addCardPopoverSpy.present).toHaveBeenCalledTimes(1); + })); + it('onMobileNumberVerificationTaskClick(): should open opt in modal', fakeAsync(() => { authService.getEou.and.resolveTo(apiEouRes); const optInModalSpy = jasmine.createSpyObj('optInModal', ['present', 'onWillDismiss']); diff --git a/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts b/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts index 96b05289b1..548a9a02c7 100644 --- a/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@angular/core/testing'; -import { IonicModule, ModalController } from '@ionic/angular'; +import { IonicModule, ModalController, PopoverController } from '@ionic/angular'; import { TasksComponent } from './tasks.component'; import { TasksService } from 'src/app/core/services/tasks.service'; @@ -24,6 +24,8 @@ import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; import { OrgService } from 'src/app/core/services/org.service'; +import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; +import { CorporateCreditCardExpenseService } from 'src/app/core/services/corporate-credit-card-expense.service'; describe('TasksComponent', () => { const getTestBed = () => { @@ -65,6 +67,10 @@ describe('TasksComponent', () => { 'getAllReportsByParams', ]); const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['getAllReportsByParams']); + const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']); + const corporateCreditCardExpenseServiceSpy = jasmine.createSpyObj('CorporateCreditCardExpenseService', [ + 'getCorporateCards', + ]); const matSnackBarSpy = jasmine.createSpyObj('MatSnackBar', ['openFromComponent']); const snackbarPropertiesSpy = jasmine.createSpyObj('SnackbarPropertiesService', ['setSnackbarProperties']); const orgServiceSpy = jasmine.createSpyObj('OrgService', ['getPrimaryOrg', 'getCurrentOrg']); @@ -77,8 +83,10 @@ describe('TasksComponent', () => { }, }, }; + const popoverControllerSpy = jasmine.createSpyObj('PopoverController', ['create', 'onDidDismiss']); const networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); + const addCardPopoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present', 'onDidDismiss']); TestBed.configureTestingModule({ declarations: [TasksComponent], imports: [IonicModule.forRoot(), RouterTestingModule], @@ -102,6 +110,9 @@ describe('TasksComponent', () => { { provide: SpenderReportsService, useValue: spenderReportsServiceSpy }, { provide: ApproverReportsService, useValue: approverReportsServiceSpy }, { provide: OrgService, useValue: orgServiceSpy }, + { provide: PopoverController, useValue: popoverControllerSpy }, + { provide: OrgUserSettingsService, useValue: orgUserSettingsServiceSpy }, + { provide: CorporateCreditCardExpenseService, useValue: corporateCreditCardExpenseServiceSpy }, ], schemas: [NO_ERRORS_SCHEMA], }).compileComponents();