Skip to content

Commit

Permalink
test: fixing eslint issues for resolveTo
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashpatil78 committed May 4, 2024
1 parent 0cc9da8 commit 36e635f
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 148 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/new-password/popup/popup.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/app/auth/request-invitation/request-invitation.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';
component.fg.controls.email.setValue(ipEmail);

Expand All @@ -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);
Expand All @@ -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);
Expand Down
42 changes: 21 additions & 21 deletions src/app/auth/sign-in/sign-in.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,}')])],
Expand All @@ -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);
Expand All @@ -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('[email protected]');
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -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);

Expand Down
60 changes: 28 additions & 32 deletions src/app/auth/switch-org/switch-org.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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');

Expand All @@ -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]);
Expand All @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/services/app-version.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
24 changes: 11 additions & 13 deletions src/app/core/services/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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([]);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 36e635f

Please sign in to comment.