diff --git a/src/app/auth/new-password/popup/popup.component.spec.ts b/src/app/auth/new-password/popup/popup.component.spec.ts index 7830738183..755cd7f5d5 100644 --- a/src/app/auth/new-password/popup/popup.component.spec.ts +++ b/src/app/auth/new-password/popup/popup.component.spec.ts @@ -51,7 +51,7 @@ describe('ErrorComponent', () => { // @ts-ignore component.popoverController.dismiss.and.returnValue(of(null)); // @ts-ignore - component.router.navigate.and.returnValue(Promise.resolve(true)); + component.router.navigate.and.resolveTo(true); component.closeClicked(); // @ts-ignore expect(component.popoverController.dismiss).toHaveBeenCalledTimes(1); diff --git a/src/app/auth/request-invitation/request-invitation.page.spec.ts b/src/app/auth/request-invitation/request-invitation.page.spec.ts index acbfdf075b..d40f5ec2e9 100644 --- a/src/app/auth/request-invitation/request-invitation.page.spec.ts +++ b/src/app/auth/request-invitation/request-invitation.page.spec.ts @@ -65,8 +65,8 @@ describe('RequestInvitationPage', () => { describe('sendRequestInvitation', () => { it('should call the upsertRouter method with the correct email', fakeAsync(() => { invitationRequestsService.upsertRouter.and.returnValue(of(null)); - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); const ipEmail = 'ajain1234@fyle.in'; component.fg.controls.email.setValue(ipEmail); @@ -85,8 +85,8 @@ describe('RequestInvitationPage', () => { }; component.fg.controls.email.setValue(''); invitationRequestsService.upsertRouter.and.returnValue(throwError(() => error)); - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); component.sendRequestInvitation(); tick(500); @@ -103,8 +103,8 @@ describe('RequestInvitationPage', () => { }; component.fg.controls.email.setValue(''); invitationRequestsService.upsertRouter.and.returnValue(throwError(() => error)); - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); component.sendRequestInvitation(); tick(500); diff --git a/src/app/auth/sign-in/sign-in.page.spec.ts b/src/app/auth/sign-in/sign-in.page.spec.ts index b5a7b0edef..03410917ed 100644 --- a/src/app/auth/sign-in/sign-in.page.spec.ts +++ b/src/app/auth/sign-in/sign-in.page.spec.ts @@ -157,7 +157,7 @@ describe('SignInPage', () => { loaderService.showLoader.and.returnValue(new Promise(() => {})); router.navigate.and.stub(); - routerAuthService.isLoggedIn.and.returnValue(Promise.resolve(false)); + routerAuthService.isLoggedIn.and.resolveTo(false); component.fg = formBuilder.group({ email: [Validators.compose([Validators.required, Validators.pattern('\\S+@\\S+\\.\\S{2,}')])], @@ -173,7 +173,7 @@ describe('SignInPage', () => { it('handleSamlSignIn(): should handle saml sign in ', fakeAsync(() => { const browserSpy = jasmine.createSpyObj('InAppBrowserObject', ['on', 'executeScript', 'close']); browserSpy.on.and.returnValue(of(new Event('event'))); - browserSpy.executeScript.and.returnValue(Promise.resolve([JSON.stringify(samlResData1)])); + browserSpy.executeScript.and.resolveTo([JSON.stringify(samlResData1)]); browserSpy.close.and.returnValue(null); spyOn(component, 'checkSAMLResponseAndSignInUser'); inAppBrowserService.create.and.returnValue(browserSpy); @@ -189,10 +189,10 @@ describe('SignInPage', () => { describe('checkSAMLResponseAndSignInUser():', () => { it('should check saml response and sign in user', async () => { - routerAuthService.handleSignInResponse.and.returnValue(Promise.resolve(authResData1)); + routerAuthService.handleSignInResponse.and.resolveTo(authResData1); spyOn(component, 'trackLoginInfo'); pushNotificationService.initPush.and.callThrough(); - router.navigate.and.returnValue(Promise.resolve(true)); + router.navigate.and.resolveTo(true); authService.refreshEou.and.returnValue(of(apiEouRes)); component.fg.controls.email.setValue('ajain@fyle.in'); @@ -362,7 +362,7 @@ describe('SignInPage', () => { authService.refreshEou.and.returnValue(of(apiEouRes)); trackingService.onSignin.and.callThrough(); pushNotificationService.initPush.and.callThrough(); - router.navigate.and.returnValue(Promise.resolve(true)); + router.navigate.and.resolveTo(true); component.fg.controls.password.setValue('password'); component.fg.controls.email.setValue('email'); fixture.detectChanges(); @@ -385,7 +385,7 @@ describe('SignInPage', () => { authService.refreshEou.and.returnValue(of(apiEouRes)); trackingService.onSignin.and.callThrough(); pushNotificationService.initPush.and.callThrough(); - router.navigate.and.returnValue(Promise.resolve(true)); + router.navigate.and.resolveTo(true); spyOn(component, 'handleError'); fixture.detectChanges(); @@ -411,13 +411,13 @@ describe('SignInPage', () => { it('should sign in user with google', async () => { spyOn(component, 'trackLoginInfo'); - googleAuthService.login.and.returnValue(Promise.resolve(authResData2)); - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); + googleAuthService.login.and.resolveTo(authResData2); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); routerAuthService.googleSignin.and.returnValue(of(authResData2)); trackingService.onSignin.and.callThrough(); pushNotificationService.initPush.and.callThrough(); - router.navigate.and.returnValue(Promise.resolve(true)); + router.navigate.and.resolveTo(true); authService.refreshEou.and.returnValue(of(apiEouRes)); await component.googleSignIn(); @@ -436,7 +436,7 @@ describe('SignInPage', () => { }); it("should throw an error if google reponse doesn't contain access token", async () => { - googleAuthService.login.and.returnValue(Promise.resolve(authResData1)); + googleAuthService.login.and.resolveTo(authResData1); spyOn(component, 'handleError'); await component.googleSignIn(); @@ -458,20 +458,20 @@ describe('SignInPage', () => { }); it('ionViewWillEnter(): should set email', () => { - expect(component.emailSet).toEqual(false); + expect(component.emailSet).toBeFalse(); component.fg.controls.email.setValue('email'); component.ionViewWillEnter(); - expect(component.emailSet).toEqual(true); + expect(component.emailSet).toBeTrue(); }); describe('ngOnInit(): ', () => { it('should navigate to switch org page if logged in ', fakeAsync(() => { - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); - routerAuthService.isLoggedIn.and.returnValue(Promise.resolve(true)); - router.navigate.and.returnValue(Promise.resolve(true)); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); + routerAuthService.isLoggedIn.and.resolveTo(true); + router.navigate.and.resolveTo(true); component.ngOnInit(); tick(100); @@ -483,10 +483,10 @@ describe('SignInPage', () => { it('should set fg when email is not present in URl', fakeAsync(() => { activatedRoute.snapshot.params.email = null; - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); - routerAuthService.isLoggedIn.and.returnValue(Promise.resolve(true)); - router.navigate.and.returnValue(Promise.resolve(true)); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); + routerAuthService.isLoggedIn.and.resolveTo(true); + router.navigate.and.resolveTo(true); component.ngOnInit(); tick(1000); diff --git a/src/app/auth/switch-org/switch-org.page.spec.ts b/src/app/auth/switch-org/switch-org.page.spec.ts index b6af9c13f4..599f0ed2af 100644 --- a/src/app/auth/switch-org/switch-org.page.spec.ts +++ b/src/app/auth/switch-org/switch-org.page.spec.ts @@ -265,11 +265,11 @@ describe('SwitchOrgPage', () => { beforeEach(() => { orgService.getOrgs.and.returnValue(of(orgData1)); spyOn(component, 'getOrgsWhichContainSearchText').and.returnValue(orgData1); - spyOn(component, 'proceed').and.returnValue(Promise.resolve()); + spyOn(component, 'proceed').and.resolveTo(); spyOn(component, 'redirectToExpensePage').and.returnValue(); orgService.getCurrentOrg.and.returnValue(of(orgData1[0])); orgService.getPrimaryOrg.and.returnValue(of(orgData2[1])); - loaderService.showLoader.and.returnValue(Promise.resolve()); + loaderService.showLoader.and.resolveTo(); spyOn(component, 'trackSwitchOrgLaunchTime').and.returnValue(null); }); @@ -474,15 +474,13 @@ describe('SwitchOrgPage', () => { it('should show email not verified alert', fakeAsync(() => { spyOn(component, 'handleDismissPopup').and.returnValue(null); const popoverSpy = jasmine.createSpyObj('popover', ['present', 'onWillDismiss']); - popoverSpy.onWillDismiss.and.returnValue( - Promise.resolve({ - data: { - action: 'action', - }, - }) - ); - popoverController.create.and.returnValue(Promise.resolve(popoverSpy)); - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + popoverSpy.onWillDismiss.and.resolveTo({ + data: { + action: 'action', + }, + }); + popoverController.create.and.resolveTo(popoverSpy); + authService.getEou.and.resolveTo(apiEouRes); component.orgs$ = of(orgData1); fixture.detectChanges(); @@ -512,13 +510,11 @@ describe('SwitchOrgPage', () => { it('should show appropiate popup if action is not provided', fakeAsync(() => { spyOn(component, 'handleDismissPopup').and.returnValue(null); const popoverSpy = jasmine.createSpyObj('popover', ['present', 'onWillDismiss']); - popoverSpy.onWillDismiss.and.returnValue( - Promise.resolve({ - data: undefined, - }) - ); - popoverController.create.and.returnValue(Promise.resolve(popoverSpy)); - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + popoverSpy.onWillDismiss.and.resolveTo({ + data: undefined, + }); + popoverController.create.and.resolveTo(popoverSpy); + authService.getEou.and.resolveTo(apiEouRes); component.orgs$ = of(orgData1); fixture.detectChanges(); @@ -561,8 +557,8 @@ describe('SwitchOrgPage', () => { }); it('markUserActive(): should mark the user as active and return the org', (done) => { - loaderService.showLoader.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); + loaderService.showLoader.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); orgUserService.markActive.and.returnValue(of(apiEouRes)); component @@ -629,7 +625,7 @@ describe('SwitchOrgPage', () => { }); it('should show email verification alert if the user has not come through invite link', (done) => { - spyOn(component, 'showEmailNotVerifiedAlert').and.returnValue(Promise.resolve()); + spyOn(component, 'showEmailNotVerifiedAlert').and.resolveTo(); component.handlePendingDetails(roles, false).subscribe((res) => { expect(res).toBeNull(); @@ -687,7 +683,7 @@ describe('SwitchOrgPage', () => { it('proceed(): should proceed to other page as per user status', fakeAsync(() => { userService.isPendingDetails.and.returnValue(of(true)); - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); authService.getRoles.and.returnValue(of(roles)); spyOn(component, 'setSentryUser').and.callThrough(); spyOn(component, 'navigateBasedOnUserStatus').and.returnValue(of(apiEouRes)); @@ -731,7 +727,7 @@ describe('SwitchOrgPage', () => { })); it('trackSwitchOrg(): tracking switch orgs', fakeAsync(() => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); component.trackSwitchOrg(orgData1[0], apiEouRes); tick(500); @@ -753,12 +749,12 @@ describe('SwitchOrgPage', () => { describe('switchOrg(): ', () => { it('should catch error and clear all caches', fakeAsync(() => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); - loaderService.showLoader.and.returnValue(Promise.resolve()); + authService.getEou.and.resolveTo(apiEouRes); + loaderService.showLoader.and.resolveTo(); orgService.switchOrg.and.returnValue(throwError(() => {})); - secureStorageService.clearAll.and.returnValue(Promise.resolve({ value: true })); - storageService.clearAll.and.returnValue(Promise.resolve()); - loaderService.hideLoader.and.returnValue(Promise.resolve()); + secureStorageService.clearAll.and.resolveTo({ value: true }); + storageService.clearAll.and.resolveTo(); + loaderService.hideLoader.and.resolveTo(); userEventService.logout.and.returnValue(null); spyOn(globalCacheBusterNotifier, 'next'); @@ -777,11 +773,11 @@ describe('SwitchOrgPage', () => { })); it('should switch org', fakeAsync(() => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); - loaderService.showLoader.and.returnValue(Promise.resolve()); + authService.getEou.and.resolveTo(apiEouRes); + loaderService.showLoader.and.resolveTo(); orgService.switchOrg.and.returnValue(of(apiEouRes)); spyOn(component, 'trackSwitchOrg').and.returnValue(null); - spyOn(component, 'proceed').and.returnValue(Promise.resolve(null)); + spyOn(component, 'proceed').and.resolveTo(null); spyOn(globalCacheBusterNotifier, 'next'); component.switchOrg(orgData1[0]); @@ -800,7 +796,7 @@ describe('SwitchOrgPage', () => { describe('signOut(): ', () => { it('should sign out the user', fakeAsync(() => { deviceService.getDeviceInfo.and.returnValue(of(extendedDeviceInfoMockData)); - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); authService.logout.and.returnValue(of(null)); spyOn(globalCacheBusterNotifier, 'next'); diff --git a/src/app/core/services/app-version.service.spec.ts b/src/app/core/services/app-version.service.spec.ts index 1a878a97fd..27f2d203ad 100644 --- a/src/app/core/services/app-version.service.spec.ts +++ b/src/app/core/services/app-version.service.spec.ts @@ -161,7 +161,7 @@ describe('AppVersionService', () => { beforeEach(() => { spyOn(appVersionService, 'isSupported').and.returnValue(of({ supported: true })); loginInfoService.getLastLoggedInVersion.and.returnValue(of('5.50.0')); - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); }); it("getUserAppVersionDetails(): should get user's app version details", (done) => { diff --git a/src/app/core/services/auth.service.spec.ts b/src/app/core/services/auth.service.spec.ts index 49639de762..40c3a7a31d 100644 --- a/src/app/core/services/auth.service.spec.ts +++ b/src/app/core/services/auth.service.spec.ts @@ -73,7 +73,7 @@ describe('AuthService', () => { }); it('getEou(): should get extended org user', (done) => { - storageService.get.and.returnValue(Promise.resolve(apiEouRes)); + storageService.get.and.resolveTo(apiEouRes); authService.getEou().then((res) => { expect(res).toEqual(apiEouRes); @@ -85,7 +85,7 @@ describe('AuthService', () => { it('refreshEou(): should refresh extended org user in memory', (done) => { apiService.get.and.returnValue(of(eouFlattended)); dataTransformService.unflatten.and.returnValue(eouRes3); - storageService.set.and.returnValue(Promise.resolve(null)); + storageService.set.and.resolveTo(null); authService.refreshEou().subscribe((res) => { expect(res).toEqual(eouRes3); @@ -99,7 +99,7 @@ describe('AuthService', () => { describe('getRoles():', () => { it('should get roles from access token', (done) => { const roles = ['ADMIN', 'APPROVER', 'FYLER', 'HOP', 'HOD', 'OWNER']; - tokenService.getAccessToken.and.returnValue(Promise.resolve(access_token)); + tokenService.getAccessToken.and.resolveTo(access_token); jwtHelperService.decodeToken.and.returnValue(apiAccessTokenRes); spyOn(JSON, 'parse').and.returnValue(roles); @@ -113,7 +113,7 @@ describe('AuthService', () => { }); it('return empty array if token no received', (done) => { - tokenService.getAccessToken.and.returnValue(Promise.resolve(null)); + tokenService.getAccessToken.and.resolveTo(null); authService.getRoles().subscribe((res) => { expect(res).toEqual([]); @@ -122,7 +122,7 @@ describe('AuthService', () => { }); it('should return empty array if roles not present', (done) => { - tokenService.getAccessToken.and.returnValue(Promise.resolve(access_token)); + tokenService.getAccessToken.and.resolveTo(access_token); jwtHelperService.decodeToken.and.returnValue(apiTokenWithoutRoles); authService.getRoles().subscribe((res) => { @@ -177,15 +177,13 @@ describe('AuthService', () => { }); it('newRefreshToken(): should refresh new token', (done) => { - storageService.delete.withArgs('user').and.returnValue(Promise.resolve(null)); - storageService.delete.withArgs('role').and.returnValue(Promise.resolve(null)); - tokenService.resetAccessToken.and.returnValue(Promise.resolve({ value: true })); - tokenService.setRefreshToken.withArgs(access_token_2).and.returnValue(Promise.resolve({ value: true })); - tokenService.getAccessToken.and.returnValue(Promise.resolve(access_token)); + storageService.delete.withArgs('user').and.resolveTo(null); + storageService.delete.withArgs('role').and.resolveTo(null); + tokenService.resetAccessToken.and.resolveTo({ value: true }); + tokenService.setRefreshToken.withArgs(access_token_2).and.resolveTo({ value: true }); + tokenService.getAccessToken.and.resolveTo(access_token); apiService.post.and.returnValue(of(apiAuthResponseRes)); - tokenService.setAccessToken - .withArgs(apiAuthResponseRes.access_token) - .and.returnValue(Promise.resolve({ value: true })); + tokenService.setAccessToken.withArgs(apiAuthResponseRes.access_token).and.resolveTo({ value: true }); spyOn(authService, 'refreshEou').and.returnValue(of(eouRes3)); authService.newRefreshToken(access_token_2).subscribe((res) => { diff --git a/src/app/core/services/config.service.spec.ts b/src/app/core/services/config.service.spec.ts index cdcf1464a1..b9717b40fb 100644 --- a/src/app/core/services/config.service.spec.ts +++ b/src/app/core/services/config.service.spec.ts @@ -40,14 +40,14 @@ describe('ConfigService', () => { describe('loadConfigurationData', () => { it('should call setClusterDomain if clusterDomain is present', async () => { const clusterDomain = 'https://staging.fyle.tech'; - tokenService.getClusterDomain.and.returnValue(Promise.resolve(clusterDomain)); + tokenService.getClusterDomain.and.resolveTo(clusterDomain); await configService.loadConfigurationData(); expect(routerAuthService.setClusterDomain).toHaveBeenCalledOnceWith(clusterDomain); expect(tokenService.getClusterDomain).toHaveBeenCalledTimes(1); }); it('should clear all stored data if clusterDomain is not present', async () => { - tokenService.getClusterDomain.and.returnValue(Promise.resolve(null)); + tokenService.getClusterDomain.and.resolveTo(null); await configService.loadConfigurationData(); expect(storageService.clearAll).toHaveBeenCalledTimes(1); expect(secureStorageService.clearAll).toHaveBeenCalledTimes(1); diff --git a/src/app/core/services/corporate-credit-card-expense.service.spec.ts b/src/app/core/services/corporate-credit-card-expense.service.spec.ts index b6b41c6128..dd07c8dfec 100644 --- a/src/app/core/services/corporate-credit-card-expense.service.spec.ts +++ b/src/app/core/services/corporate-credit-card-expense.service.spec.ts @@ -123,7 +123,7 @@ describe('CorporateCreditCardExpenseService', () => { it('getAssignedCards(): should get all assigned cards', (done) => { const queryParams = 'in.(COMPLETE,DRAFT)'; - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); apiV2Service.getStats.and.returnValue(of(new StatsResponse(apiAssignedCardDetailsRes))); spyOn(cccExpenseService, 'constructInQueryParamStringForV2').and.returnValue(queryParams); diff --git a/src/app/core/services/currency.service.spec.ts b/src/app/core/services/currency.service.spec.ts index a02537a1fb..cdae8ca576 100644 --- a/src/app/core/services/currency.service.spec.ts +++ b/src/app/core/services/currency.service.spec.ts @@ -48,7 +48,7 @@ describe('CurrencyService', () => { }); it('getAll(): should return all currencies', (done) => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); apiService.get.and.returnValue(of(apiAllCurrencies)); currencyService.getAll().subscribe((res) => { diff --git a/src/app/core/services/custom-inputs.service.spec.ts b/src/app/core/services/custom-inputs.service.spec.ts index 4086030ac1..541d7882dd 100644 --- a/src/app/core/services/custom-inputs.service.spec.ts +++ b/src/app/core/services/custom-inputs.service.spec.ts @@ -269,7 +269,7 @@ describe('CustomInputsService', () => { }); it('should fill dependent field properties', (done) => { - authService.getEou.and.returnValue(Promise.resolve(authRespone)); + authService.getEou.and.resolveTo(authRespone); spenderPlatformV1ApiService.get.and.returnValue(of(platformApiResponse)); const result = customInputsService.fillDependantFieldProperties(expensesWithDependentFields[0]); result.subscribe((res) => { @@ -279,7 +279,7 @@ describe('CustomInputsService', () => { }); it('should fill custom properties', (done) => { - authService.getEou.and.returnValue(Promise.resolve(authRespone)); + authService.getEou.and.resolveTo(authRespone); spenderPlatformV1ApiService.get.and.returnValue(of(platformApiResponse)); const result = customInputsService.fillCustomProperties(orgCatId, customProperties, false); result.subscribe((res) => { diff --git a/src/app/core/services/google-auth.service.spec.ts b/src/app/core/services/google-auth.service.spec.ts index 1a58aff4fc..2c1b6de2b6 100644 --- a/src/app/core/services/google-auth.service.spec.ts +++ b/src/app/core/services/google-auth.service.spec.ts @@ -29,8 +29,8 @@ describe('GoogleAuthService', () => { describe('login():', () => { it('should login in a user via goolge', (done) => { - googlePlus.login.and.returnValue(Promise.resolve(apiAuthRes)); - googlePlus.logout.and.returnValue(Promise.resolve(apiLogoutRes)); + googlePlus.login.and.resolveTo(apiAuthRes); + googlePlus.logout.and.resolveTo(apiLogoutRes); googleAuthService.login().then((res) => { expect(res).toEqual(apiAuthRes); @@ -44,7 +44,7 @@ describe('GoogleAuthService', () => { }); it('should throw an error', (done) => { - googlePlus.login.and.returnValue(Promise.reject(new Error())); + googlePlus.login.and.rejectWith(new Error()); googleAuthService.login().then((res) => { expect(res).toEqual(new Error()); diff --git a/src/app/core/services/launch-darkly.service.spec.ts b/src/app/core/services/launch-darkly.service.spec.ts index 3d378847e6..9a8b9eefad 100644 --- a/src/app/core/services/launch-darkly.service.spec.ts +++ b/src/app/core/services/launch-darkly.service.spec.ts @@ -46,7 +46,7 @@ describe('LaunchDarklyService', () => { describe('getVariation():', () => { it('should get variation', (done) => { const key = 'keyboard_plugin_enabled'; - storageService.get.and.returnValue(Promise.resolve(ldAllFlagsRes)); + storageService.get.and.resolveTo(ldAllFlagsRes); launchDarklyService.getVariation(key, true).subscribe((res) => { expect(res).toBeTrue(); @@ -56,7 +56,7 @@ describe('LaunchDarklyService', () => { it('should return default value when flags are not available', (done) => { const key = 'keyboard_plugin_enabled'; - storageService.get.and.returnValue(Promise.resolve(null)); + storageService.get.and.resolveTo(null); launchDarklyService.getVariation(key, true).subscribe((res) => { expect(res).toBeTrue(); diff --git a/src/app/core/services/loader.service.spec.ts b/src/app/core/services/loader.service.spec.ts index 72c89121a5..3b2ed63a5b 100644 --- a/src/app/core/services/loader.service.spec.ts +++ b/src/app/core/services/loader.service.spec.ts @@ -29,7 +29,7 @@ describe('LoaderService', () => { const message = 'Please wait...'; const duration = 1000; const loadingElementSpy = jasmine.createSpyObj('HTMLIonLoadingElement', ['present']); - loadingController.create.and.returnValue(Promise.resolve(loadingElementSpy)); + loadingController.create.and.resolveTo(loadingElementSpy); loaderService.showLoader(message, duration); tick(); @@ -42,7 +42,7 @@ describe('LoaderService', () => { it('showLoader(): should show loader without args', fakeAsync(() => { const loadingElementSpy = jasmine.createSpyObj('HTMLIonLoadingElement', ['present']); - loadingController.create.and.returnValue(Promise.resolve(loadingElementSpy)); + loadingController.create.and.resolveTo(loadingElementSpy); loaderService.showLoader(); tick(); @@ -53,7 +53,7 @@ describe('LoaderService', () => { it('hideLoader(): should hide loader', fakeAsync(() => { const loadingElementSpy = jasmine.createSpyObj('HTMLIonLoadingElement', ['dismiss']); - loadingController.dismiss.and.returnValue(Promise.resolve(loadingElementSpy)); + loadingController.dismiss.and.resolveTo(loadingElementSpy); loaderService.hideLoader(); tick(); @@ -62,7 +62,7 @@ describe('LoaderService', () => { it('hideLoader(): should catch errors in hide loader', fakeAsync(() => { const error = 'Something went wrong'; - loadingController.dismiss.and.returnValue(Promise.reject(error)); + loadingController.dismiss.and.rejectWith(error); loaderService.hideLoader(); tick(); diff --git a/src/app/core/services/login-info.service.spec.ts b/src/app/core/services/login-info.service.spec.ts index 5d5d85f8ed..e65c1213a8 100644 --- a/src/app/core/services/login-info.service.spec.ts +++ b/src/app/core/services/login-info.service.spec.ts @@ -35,7 +35,7 @@ describe('LoginInfoService', () => { describe('addLoginInfo():', () => { it('should add login info', async () => { - storageService.get.and.returnValue(Promise.resolve(null)); + storageService.get.and.resolveTo(null); storageService.set.and.callThrough(); loginInfoService.addLoginInfo(version, time); @@ -51,7 +51,7 @@ describe('LoginInfoService', () => { lastLoggedInTime: 'Fri, 17 Mar 2023 12:24:26 GMT', }; - storageService.get.and.returnValue(Promise.resolve(newLoginInfo)); + storageService.get.and.resolveTo(newLoginInfo); storageService.set.and.callThrough(); loginInfoService.addLoginInfo(version, newTime); @@ -62,7 +62,7 @@ describe('LoginInfoService', () => { describe('getLastLoggedInVersion():', () => { it('should get last logged in version', (done) => { - storageService.get.and.returnValue(Promise.resolve(null)); + storageService.get.and.resolveTo(null); loginInfoService.getLastLoggedInVersion().subscribe((res) => { expect(res).toBeUndefined(); @@ -72,7 +72,7 @@ describe('LoginInfoService', () => { }); it('should return null if last logged in version not present', (done) => { - storageService.get.and.returnValue(Promise.resolve(loginInfo)); + storageService.get.and.resolveTo(loginInfo); loginInfoService.getLastLoggedInVersion().subscribe((res) => { expect(res).toEqual(loginInfo.lastLoggedInVersion); diff --git a/src/app/core/services/org-user.service.spec.ts b/src/app/core/services/org-user.service.spec.ts index 255fed61d7..a983489fce 100644 --- a/src/app/core/services/org-user.service.spec.ts +++ b/src/app/core/services/org-user.service.spec.ts @@ -224,10 +224,10 @@ describe('OrgUserService', () => { // This token contains the user details such as user id, org id, org user id, roles, scopes, etc. const token = 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzI5MTcyMDAsImlzcyI6IkZ5bGVBcHAiLCJ1c2VyX2lkIjoidXNNakxpYm15ZTdzIiwib3JnX3VzZXJfaWQiOiJvdXJ3N0hpNG1tcE8iLCJvcmdfaWQiOiJvck5WdGhUbzJaeW8iLCJyb2xlcyI6IltcIkZZTEVSXCIsXCJGSU5BTkNFXCIsXCJBRE1JTlwiLFwiQVBQUk9WRVJcIixcIlZFUklGSUVSXCIsXCJQQVlNRU5UX1BST0NFU1NPUlwiLFwiSE9QXCJdIiwic2NvcGVzIjoiW10iLCJhbGxvd2VkX0NJRFJzIjoiW10iLCJ2ZXJzaW9uIjoiMyIsImNsdXN0ZXJfZG9tYWluIjoiXCJodHRwczovL3N0YWdpbmcuZnlsZS50ZWNoXCIiLCJleHAiOjE2NzI5MjA4MDB9.hTMJ56cPH_HgKhZSKNCOIEGAzaAXCfIgbEYcaudhXwk'; - tokenService.getAccessToken.and.returnValue(Promise.resolve(token)); + tokenService.getAccessToken.and.resolveTo(token); orgUserService.isSwitchedToDelegator().then((res) => { - expect(res).toEqual(false); + expect(res).toBeFalse(); done(); }); }); @@ -237,10 +237,10 @@ describe('OrgUserService', () => { // This token contains the user details such as user id, org id, org user id, roles, scopes, etc. const token = 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzI5MTcxNTgsImlzcyI6IkZ5bGVBcHAiLCJ1c2VyX2lkIjoidXNCa0pEMVVtMTc0Iiwib3JnX3VzZXJfaWQiOiJvdTVxclBKYkdmV00iLCJvcmdfaWQiOiJvck5WdGhUbzJaeW8iLCJyb2xlcyI6IltcIkZZTEVSXCIsXCJWRVJJRklFUlwiXSIsInNjb3BlcyI6IltdIiwicHJveHlfb3JnX3VzZXJfaWQiOiJvdXJ3N0hpNG1tcE8iLCJhbGxvd2VkX0NJRFJzIjoiW10iLCJ2ZXJzaW9uIjoiMyIsImNsdXN0ZXJfZG9tYWluIjoiXCJodHRwczovL3N0YWdpbmcuZnlsZS50ZWNoXCIiLCJleHAiOjE2NzI5MjA3NTh9.VqpiTmEd_Kp-fK11gBV-VfjEkPhCja-diu-TGDGPeKA'; - tokenService.getAccessToken.and.returnValue(Promise.resolve(token)); + tokenService.getAccessToken.and.resolveTo(token); orgUserService.isSwitchedToDelegator().then((res) => { - expect(res).toEqual(true); + expect(res).toBeTrue(); done(); }); }); diff --git a/src/app/core/services/refiner.service.spec.ts b/src/app/core/services/refiner.service.spec.ts index 8f6b99c709..c3dd41a675 100644 --- a/src/app/core/services/refiner.service.spec.ts +++ b/src/app/core/services/refiner.service.spec.ts @@ -75,7 +75,7 @@ describe('RefinerService', () => { it('should return true for non-demo orgs and when not switched to delegator', (done) => { spyOn(refinerService, 'isNonDemoOrg').and.returnValue(true); const switchedToDelegator = false; - orgUserService.isSwitchedToDelegator.and.returnValue(Promise.resolve(switchedToDelegator)); + orgUserService.isSwitchedToDelegator.and.resolveTo(switchedToDelegator); const homeCurrency = 'INR'; const eou = apiEouRes; refinerService.canStartSurvey(homeCurrency, eou).subscribe((res) => { @@ -96,7 +96,7 @@ describe('RefinerService', () => { }; spyOn(refinerService, 'isNonDemoOrg').and.returnValue(false); const switchedToDelegator = true; - orgUserService.isSwitchedToDelegator.and.returnValue(Promise.resolve(switchedToDelegator)); + orgUserService.isSwitchedToDelegator.and.resolveTo(switchedToDelegator); const homeCurrency = 'INR'; const eou = demoOrgRes; refinerService.canStartSurvey(homeCurrency, eou).subscribe((res) => { diff --git a/src/app/core/services/router-auth.service.spec.ts b/src/app/core/services/router-auth.service.spec.ts index efbe4f7296..7775e080e2 100644 --- a/src/app/core/services/router-auth.service.spec.ts +++ b/src/app/core/services/router-auth.service.spec.ts @@ -183,8 +183,8 @@ describe('RouterAuthService', () => { }); it('isLoggedIn(): should check if user is logged in', (done) => { - tokenService.getAccessToken.and.returnValue(Promise.resolve(access_token)); - tokenService.getRefreshToken.and.returnValue(Promise.resolve(refresh_token)); + tokenService.getAccessToken.and.resolveTo(access_token); + tokenService.getRefreshToken.and.resolveTo(refresh_token); routerAuthService.isLoggedIn().then((res) => { expect(res).toBeTrue(); @@ -195,7 +195,7 @@ describe('RouterAuthService', () => { }); it('newRefreshToken(): should set new refresh token', async () => { - tokenService.setRefreshToken.and.returnValue(Promise.resolve(null)); + tokenService.setRefreshToken.and.resolveTo(null); const deleteUser = await storageService.delete('user'); const deleteRole = await storageService.delete('role'); @@ -207,7 +207,7 @@ describe('RouterAuthService', () => { }); it('newAccessToken(): should set new access token', fakeAsync(() => { - tokenService.setAccessToken.and.returnValue(Promise.resolve(null)); + tokenService.setAccessToken.and.resolveTo(null); tick(); routerAuthService.newAccessToken(access_token).then((res) => { @@ -220,7 +220,7 @@ describe('RouterAuthService', () => { it('fetchAccessToken(): should fetch access token', fakeAsync(() => { routerApiService.post.and.returnValue(of(apiAuthRes)); - tokenService.getAccessToken.and.returnValue(Promise.resolve(access_token)); + tokenService.getAccessToken.and.resolveTo(access_token); tick(); @@ -236,7 +236,7 @@ describe('RouterAuthService', () => { it('handleSignInResponse(): should handle sign in response', (done) => { spyOn(routerAuthService, 'newRefreshToken').and.callThrough(); spyOn(routerAuthService, 'setClusterDomain').and.callThrough(); - spyOn(routerAuthService, 'fetchAccessToken').and.returnValue(Promise.resolve(apiAuthRes)); + spyOn(routerAuthService, 'fetchAccessToken').and.resolveTo(apiAuthRes); spyOn(routerAuthService, 'newAccessToken').and.callThrough(); routerAuthService.handleSignInResponse(authResData1).then((res) => { @@ -267,7 +267,7 @@ describe('RouterAuthService', () => { it('basicSignin(): should sign in the user with email and password', (done) => { routerApiService.post.and.returnValue(of(authResData1)); - spyOn(routerAuthService, 'handleSignInResponse').and.returnValue(Promise.resolve(authResData1)); + spyOn(routerAuthService, 'handleSignInResponse').and.resolveTo(authResData1); const password = 'KalaChashma'; routerAuthService.basicSignin(email, password).subscribe((res) => { @@ -283,7 +283,7 @@ describe('RouterAuthService', () => { it('googleSignin(): should sign in the user with google', (done) => { routerApiService.post.and.returnValue(of(authResData1)); - spyOn(routerAuthService, 'handleSignInResponse').and.returnValue(Promise.resolve(authResData1)); + spyOn(routerAuthService, 'handleSignInResponse').and.resolveTo(authResData1); routerAuthService.googleSignin(access_token).subscribe((res) => { expect(res).toEqual(authResData1); @@ -297,7 +297,7 @@ describe('RouterAuthService', () => { it('resetPassword(): should reset user passord', (done) => { routerApiService.post.and.returnValue(of(authResData1)); - spyOn(routerAuthService, 'handleSignInResponse').and.returnValue(Promise.resolve(authResData1)); + spyOn(routerAuthService, 'handleSignInResponse').and.resolveTo(authResData1); const newPassword = 'New_Password'; @@ -314,7 +314,7 @@ describe('RouterAuthService', () => { it('emailVerify(): should verify email', (done) => { routerApiService.post.and.returnValue(of(authResData1)); - spyOn(routerAuthService, 'handleSignInResponse').and.returnValue(Promise.resolve(authResData1)); + spyOn(routerAuthService, 'handleSignInResponse').and.resolveTo(authResData1); const verification_code = 'orNVthTo2Zyo'; diff --git a/src/app/core/services/storage.service.spec.ts b/src/app/core/services/storage.service.spec.ts index 09cf0e08e3..c52336b3bc 100644 --- a/src/app/core/services/storage.service.spec.ts +++ b/src/app/core/services/storage.service.spec.ts @@ -21,7 +21,7 @@ describe('StorageService', () => { it('should set a key-value pair', async () => { const key = 'etxncCount'; const value = 150; - spyOn(Preferences, 'set').and.returnValue(Promise.resolve()); + spyOn(Preferences, 'set').and.resolveTo(); await storageService.set(key, value); @@ -39,10 +39,10 @@ describe('StorageService', () => { const key = 'isFirstReportCreated'; const value = true; // Setting the value to fetch it later - spyOn(Preferences, 'set').and.returnValue(Promise.resolve()); + spyOn(Preferences, 'set').and.resolveTo(); await storageService.set(key, value); - spyOn(Preferences, 'get').and.returnValue(Promise.resolve({ value: JSON.stringify(value) })); + spyOn(Preferences, 'get').and.resolveTo({ value: JSON.stringify(value) }); const result = await storageService.get(key); @@ -64,7 +64,7 @@ describe('StorageService', () => { describe('delete():', () => { it('should delete a value for a given key', async () => { const key = 'user'; - spyOn(Preferences, 'remove').and.returnValue(Promise.resolve()); + spyOn(Preferences, 'remove').and.resolveTo(); await storageService.delete(key); @@ -75,7 +75,7 @@ describe('StorageService', () => { describe('clearAll():', () => { it('should clear all key-value pairs', async () => { - spyOn(Preferences, 'clear').and.returnValue(Promise.resolve()); + spyOn(Preferences, 'clear').and.resolveTo(); await storageService.clearAll(); diff --git a/src/app/core/services/tasks.service.spec.ts b/src/app/core/services/tasks.service.spec.ts index c01832b8bc..95bff9679f 100644 --- a/src/app/core/services/tasks.service.spec.ts +++ b/src/app/core/services/tasks.service.spec.ts @@ -1016,7 +1016,7 @@ describe('TasksService', () => { describe('getMobileNumberVerificationTasks(): ', () => { it('should not return any task if user has verified mobile number', (done) => { - authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse)); + authService.getEou.and.resolveTo(extendedOrgUserResponse); corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([mastercardRTFCard])); const mapMobileNumberVerificationTaskSpy = spyOn(tasksService, 'mapMobileNumberVerificationTask'); tasksService.getMobileNumberVerificationTasks().subscribe((res) => { @@ -1031,7 +1031,7 @@ describe('TasksService', () => { it('should not return any task if user has not enrolled for RTF', (done) => { const eou = cloneDeep(extendedOrgUserResponse); eou.ou.mobile_verified = false; - authService.getEou.and.returnValue(Promise.resolve(eou)); + authService.getEou.and.resolveTo(eou); corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([])); const mapMobileNumberVerificationTaskSpy = spyOn(tasksService, 'mapMobileNumberVerificationTask'); tasksService.getMobileNumberVerificationTasks().subscribe((res) => { @@ -1047,7 +1047,7 @@ describe('TasksService', () => { const eou = cloneDeep(extendedOrgUserResponse); eou.ou.mobile_verified = false; eou.ou.mobile = null; - authService.getEou.and.returnValue(Promise.resolve(eou)); + authService.getEou.and.resolveTo(eou); corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([mastercardRTFCard])); const mapMobileNumberVerificationTaskSpy = spyOn(tasksService, 'mapMobileNumberVerificationTask').and.returnValue( [addMobileNumberTask] @@ -1063,7 +1063,7 @@ describe('TasksService', () => { it('should return verify number task if user has verified mobile number', (done) => { const eou = cloneDeep(extendedOrgUserResponse); eou.ou.mobile_verified = false; - authService.getEou.and.returnValue(Promise.resolve(eou)); + authService.getEou.and.resolveTo(eou); corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([mastercardRTFCard])); const mapMobileNumberVerificationTaskSpy = spyOn(tasksService, 'mapMobileNumberVerificationTask').and.returnValue( [addMobileNumberTask] @@ -1080,7 +1080,7 @@ describe('TasksService', () => { describe('getCommuteDetailsTasks():', () => { it('should return commute details task if commute details response data is not defined', (done) => { employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData2)); - authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse)); + authService.getEou.and.resolveTo(extendedOrgUserResponse); orgSettingsService.get.and.returnValue(of(orgSettingsWithCommuteDeductionsEnabled)); tasksService.getCommuteDetailsTasks().subscribe((res) => { @@ -1094,7 +1094,7 @@ describe('TasksService', () => { it('should return commute details task if home location is not present', (done) => { employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData3)); - authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse)); + authService.getEou.and.resolveTo(extendedOrgUserResponse); orgSettingsService.get.and.returnValue(of(orgSettingsWithCommuteDeductionsEnabled)); tasksService.getCommuteDetailsTasks().subscribe((res) => { @@ -1108,7 +1108,7 @@ describe('TasksService', () => { it('should not return commute details task if mileage is disabled for org', (done) => { employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData3)); - authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse)); + authService.getEou.and.resolveTo(extendedOrgUserResponse); orgSettingsService.get.and.returnValue(of(orgSettingsWoMileage)); tasksService.getCommuteDetailsTasks().subscribe((res) => { @@ -1122,7 +1122,7 @@ describe('TasksService', () => { it('should not return commute details task if commute deduction settings is disabled for org', (done) => { employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData3)); - authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse)); + authService.getEou.and.resolveTo(extendedOrgUserResponse); orgSettingsService.get.and.returnValue(of(orgSettingsRes)); tasksService.getCommuteDetailsTasks().subscribe((res) => { @@ -1136,7 +1136,7 @@ describe('TasksService', () => { it('should not return commute details task if home location is present in commute details', (done) => { employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData)); - authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse)); + authService.getEou.and.resolveTo(extendedOrgUserResponse); orgSettingsService.get.and.returnValue(of(orgSettingsWithCommuteDeductionsDisabled)); tasksService.getCommuteDetailsTasks().subscribe((res) => { diff --git a/src/app/core/services/token.service.spec.ts b/src/app/core/services/token.service.spec.ts index 350b22d1e2..20d33d304b 100644 --- a/src/app/core/services/token.service.spec.ts +++ b/src/app/core/services/token.service.spec.ts @@ -30,7 +30,7 @@ describe('TokenService', () => { }); it('getAccessToken(): should get access token from secure storage', fakeAsync(() => { - secureStorageService.get.and.returnValue(Promise.resolve('token')); + secureStorageService.get.and.resolveTo('token'); tick(); tokenService.getAccessToken().then((token) => { expect(token).toEqual('token'); @@ -40,7 +40,7 @@ describe('TokenService', () => { it('setAccessToken(): should set access token to secure storage', fakeAsync(() => { userEventService.setToken.and.returnValue(null); - secureStorageService.set.and.returnValue(Promise.resolve({ value: true })); + secureStorageService.set.and.resolveTo({ value: true }); tick(); tokenService.setAccessToken('token').then(() => { expect(secureStorageService.set).toHaveBeenCalledOnceWith('X-AUTH-TOKEN', 'token'); @@ -48,7 +48,7 @@ describe('TokenService', () => { })); it('resetAccessToken(): should reset access token from secure storage', fakeAsync(() => { - secureStorageService.delete.and.returnValue(Promise.resolve({ value: true })); + secureStorageService.delete.and.resolveTo({ value: true }); tick(); tokenService.resetAccessToken().then(() => { expect(secureStorageService.delete).toHaveBeenCalledOnceWith('X-AUTH-TOKEN'); @@ -56,7 +56,7 @@ describe('TokenService', () => { })); it('getRefreshToken(): should get refresh token from secure storage', fakeAsync(() => { - secureStorageService.get.and.returnValue(Promise.resolve('token')); + secureStorageService.get.and.resolveTo('token'); tick(); tokenService.getRefreshToken().then((token) => { expect(token).toEqual('token'); @@ -65,7 +65,7 @@ describe('TokenService', () => { })); it('setRefreshToken(): should set refresh token to secure storage', fakeAsync(() => { - secureStorageService.set.and.returnValue(Promise.resolve({ value: true })); + secureStorageService.set.and.resolveTo({ value: true }); tick(); tokenService.setRefreshToken('token').then(() => { expect(secureStorageService.set).toHaveBeenCalledOnceWith('X-REFRESH-TOKEN', 'token'); @@ -73,7 +73,7 @@ describe('TokenService', () => { })); it('resetRefreshToken(): should reset refresh token from secure storage', fakeAsync(() => { - secureStorageService.delete.and.returnValue(Promise.resolve({ value: true })); + secureStorageService.delete.and.resolveTo({ value: true }); tick(); tokenService.resetRefreshToken().then(() => { expect(secureStorageService.delete).toHaveBeenCalledOnceWith('X-REFRESH-TOKEN'); @@ -81,7 +81,7 @@ describe('TokenService', () => { })); it('getClusterDomain(): should get cluster domain from secure storage', fakeAsync(() => { - secureStorageService.get.and.returnValue(Promise.resolve('domain')); + secureStorageService.get.and.resolveTo('domain'); tick(); tokenService.getClusterDomain().then((domain) => { expect(domain).toEqual('domain'); @@ -90,7 +90,7 @@ describe('TokenService', () => { })); it('setClusterDomain(): should set cluster domain to secure storage', fakeAsync(() => { - secureStorageService.set.and.returnValue(Promise.resolve({ value: true })); + secureStorageService.set.and.resolveTo({ value: true }); tick(); tokenService.setClusterDomain('domain').then(() => { expect(secureStorageService.set).toHaveBeenCalledOnceWith('CLUSTER-DOMAIN', 'domain'); @@ -98,7 +98,7 @@ describe('TokenService', () => { })); it('resetClusterDomain(): should reset cluster domain from secure storage', fakeAsync(() => { - secureStorageService.delete.and.returnValue(Promise.resolve({ value: true })); + secureStorageService.delete.and.resolveTo({ value: true }); tick(); tokenService.resetClusterDomain().then(() => { expect(secureStorageService.delete).toHaveBeenCalledOnceWith('CLUSTER-DOMAIN'); diff --git a/src/app/core/services/transactions-outbox.service.spec.ts b/src/app/core/services/transactions-outbox.service.spec.ts index a8d8137491..4bf0baaa7b 100644 --- a/src/app/core/services/transactions-outbox.service.spec.ts +++ b/src/app/core/services/transactions-outbox.service.spec.ts @@ -101,7 +101,7 @@ describe('TransactionsOutboxService', () => { it('saveQueue(): should save queue', () => { const mockQueue = cloneDeep(outboxQueueData1); transactionsOutboxService.queue = mockQueue; - storageService.set.and.returnValue(Promise.resolve(null)); + storageService.set.and.resolveTo(null); transactionsOutboxService.saveQueue(); expect(storageService.set).toHaveBeenCalledOnceWith('outbox', transactionsOutboxService.queue); }); @@ -109,7 +109,7 @@ describe('TransactionsOutboxService', () => { it('saveDataExtractionQueue(): should save data extraction queue', () => { const mockQueue = cloneDeep(outboxQueueData1); transactionsOutboxService.dataExtractionQueue = mockQueue; - storageService.set.and.returnValue(Promise.resolve(null)); + storageService.set.and.resolveTo(null); transactionsOutboxService.saveDataExtractionQueue(); expect(storageService.set).toHaveBeenCalledOnceWith( 'data_extraction_queue', @@ -164,7 +164,7 @@ describe('TransactionsOutboxService', () => { it('removeDataExtractionEntry():', async () => { const mockQueue = cloneDeep(outboxQueueData1); transactionsOutboxService.dataExtractionQueue = mockQueue; - spyOn(transactionsOutboxService, 'saveDataExtractionQueue').and.returnValue(Promise.resolve()); + spyOn(transactionsOutboxService, 'saveDataExtractionQueue').and.resolveTo(); await transactionsOutboxService.removeDataExtractionEntry(txnData2, [ { url: '2023-02-08/orNVthTo2Zyo/receipts/fi6PQ6z4w6ET.000.jpeg', type: 'image/jpeg' }, ]); @@ -173,7 +173,7 @@ describe('TransactionsOutboxService', () => { }); it('addDataExtractionEntry():', () => { - spyOn(transactionsOutboxService, 'saveDataExtractionQueue').and.returnValue(Promise.resolve()); + spyOn(transactionsOutboxService, 'saveDataExtractionQueue').and.resolveTo(); transactionsOutboxService.addDataExtractionEntry(txnData2, [ { url: '2023-02-08/orNVthTo2Zyo/receipts/fi6PQ6z4w6ET.000.jpeg', type: 'image/jpeg' }, ]); @@ -201,14 +201,14 @@ describe('TransactionsOutboxService', () => { it('removeEntry(): should remove entry from queue', () => { const mockQueue = cloneDeep(outboxQueueData1); transactionsOutboxService.queue = mockQueue; - spyOn(transactionsOutboxService, 'saveQueue').and.returnValue(Promise.resolve()); + spyOn(transactionsOutboxService, 'saveQueue').and.resolveTo(); transactionsOutboxService.removeEntry(outboxQueueData1[0]); expect(transactionsOutboxService.saveQueue).toHaveBeenCalledTimes(1); expect(transactionsOutboxService.queue.length).toEqual(0); }); it('addEntry(): should add entry to queue', () => { - spyOn(transactionsOutboxService, 'saveQueue').and.returnValue(Promise.resolve()); + spyOn(transactionsOutboxService, 'saveQueue').and.resolveTo(); transactionsOutboxService.addEntry(txnData2, [ { url: '2023-02-08/orNVthTo2Zyo/receipts/fi6PQ6z4w6ET.000.jpeg', type: 'image/jpeg' }, ]); @@ -220,8 +220,8 @@ describe('TransactionsOutboxService', () => { beforeEach(() => { const mockQueue = cloneDeep(outboxQueueData1); transactionsOutboxService.queue = mockQueue; - spyOn(transactionsOutboxService, 'addEntry').and.returnValue(Promise.resolve()); - spyOn(transactionsOutboxService, 'syncEntry').and.returnValue(Promise.resolve(outboxQueueData1[0])); + spyOn(transactionsOutboxService, 'addEntry').and.resolveTo(); + spyOn(transactionsOutboxService, 'syncEntry').and.resolveTo(outboxQueueData1[0]); }); it('should add entry to queue and sync', () => { @@ -275,7 +275,7 @@ describe('TransactionsOutboxService', () => { it('deleteOfflineExpense(): should delete offline expense', () => { const mockQueue = cloneDeep(outboxQueueData1); transactionsOutboxService.queue = mockQueue; - spyOn(transactionsOutboxService, 'saveQueue').and.returnValue(Promise.resolve()); + spyOn(transactionsOutboxService, 'saveQueue').and.resolveTo(); transactionsOutboxService.deleteOfflineExpense(0); expect(transactionsOutboxService.saveQueue).toHaveBeenCalledTimes(1); expect(transactionsOutboxService.queue.length).toEqual(0); diff --git a/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts b/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts index 6fa18958b8..8af983b1c7 100644 --- a/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts +++ b/src/app/deep-link-redirection/deep-link-redirection.page.spec.ts @@ -77,7 +77,7 @@ describe('DeepLinkRedirectionPage', () => { activeroutemock = TestBed.inject(ActivatedRoute); reportService.getERpt.and.returnValue(of(expectedSingleErpt)); - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); fixture = TestBed.createComponent(DeepLinkRedirectionPage); component = fixture.componentInstance; fixture.detectChanges(); @@ -122,7 +122,7 @@ describe('DeepLinkRedirectionPage', () => { }, }; - authService.getEou.and.returnValue(Promise.resolve(updatedApiEouRes)); + authService.getEou.and.resolveTo(updatedApiEouRes); const updatedErpt = { ...expectedSingleErpt, @@ -159,7 +159,7 @@ describe('DeepLinkRedirectionPage', () => { spyOn(component, 'switchOrg'); const error = 'Something went wrong'; - authService.getEou.and.returnValue(Promise.resolve(updatedApiEouRes)); + authService.getEou.and.resolveTo(updatedApiEouRes); reportService.getERpt.and.returnValue(throwError(() => error)); component.redirectToReportModule(); fixture.detectChanges(); @@ -273,7 +273,7 @@ describe('DeepLinkRedirectionPage', () => { }, }; - authService.getEou.and.returnValue(Promise.resolve(updatedApiEouRes)); + authService.getEou.and.resolveTo(updatedApiEouRes); activeroutemock.snapshot.params = { sub_module: 'advReq', @@ -299,7 +299,7 @@ describe('DeepLinkRedirectionPage', () => { })); it('should redirect to my_view_advance_request page if non of the conditions match', fakeAsync(() => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); activeroutemock.snapshot.params = { sub_module: 'advReq', diff --git a/src/app/shared/components/fy-view-attachment/fy-view-attachment.component.spec.ts b/src/app/shared/components/fy-view-attachment/fy-view-attachment.component.spec.ts index 821afcbf34..5ad12b5ea5 100644 --- a/src/app/shared/components/fy-view-attachment/fy-view-attachment.component.spec.ts +++ b/src/app/shared/components/fy-view-attachment/fy-view-attachment.component.spec.ts @@ -85,8 +85,8 @@ describe('FyViewAttachmentComponent', () => { url: 'http://example.com/attachment3.pdf', }, ]; - loaderService.hideLoader.and.returnValue(Promise.resolve()); - loaderService.showLoader.and.returnValue(Promise.resolve()); + loaderService.hideLoader.and.resolveTo(); + loaderService.showLoader.and.resolveTo(); component.attachments = mockAttachments; fixture.detectChanges();