diff --git a/npm/ng-packs/packages/oauth/jest.config.ts b/npm/ng-packs/packages/oauth/jest.config.ts index eb598713d5..1ff693025e 100644 --- a/npm/ng-packs/packages/oauth/jest.config.ts +++ b/npm/ng-packs/packages/oauth/jest.config.ts @@ -1,4 +1,8 @@ /* eslint-disable */ +/** + * @deprecated use vitest instead of jest + * @see https://vitest.dev/guide/migration.html#jest + */ export default { displayName: 'oauth', preset: '../../jest.preset.js', diff --git a/npm/ng-packs/packages/oauth/src/lib/tests/api.interceptor.spec.ts b/npm/ng-packs/packages/oauth/src/lib/tests/api.interceptor.spec.ts index 04a7652300..247b79b798 100644 --- a/npm/ng-packs/packages/oauth/src/lib/tests/api.interceptor.spec.ts +++ b/npm/ng-packs/packages/oauth/src/lib/tests/api.interceptor.spec.ts @@ -1,8 +1,8 @@ import { HttpRequest } from '@angular/common/http'; import { SpyObject } from '@ngneat/spectator'; -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService } from '@ngneat/spectator/vitest'; import { OAuthService } from 'angular-oauth2-oidc'; -import { Subject, timer } from 'rxjs'; +import { Subject } from 'rxjs'; import { HttpWaitService, SessionStateService, TENANT_KEY } from '@abp/ng.core'; import { OAuthApiInterceptor } from '../interceptors'; @@ -29,7 +29,7 @@ describe('ApiInterceptor', () => { httpWaitService = spectator.inject(HttpWaitService); }); - it('should add headers to http request', done => { + it('should add headers to http request', () => { oauthService.getAccessToken.andReturn('ey892mkwa8^2jk'); sessionState.getLanguage.andReturn('tr'); sessionState.getTenant.andReturn({ id: 'Volosoft', name: 'Volosoft' }); @@ -42,7 +42,6 @@ describe('ApiInterceptor', () => { expect(req.headers.get('Authorization')).toEqual('Bearer ey892mkwa8^2jk'); expect(req.headers.get('Accept-Language')).toEqual('tr'); expect(req.headers.get(testTenantKey)).toEqual('Volosoft'); - done(); return handleRes$; }, }; @@ -53,9 +52,9 @@ describe('ApiInterceptor', () => { handleRes$.complete(); }); - it('should call http wait services add request and delete request', done => { - const spyAddRequest = jest.spyOn(httpWaitService, 'addRequest'); - const spyDeleteRequest = jest.spyOn(httpWaitService, 'deleteRequest'); + it('should call http wait services add request and delete request', () => { + const spyAddRequest = vi.spyOn(httpWaitService, 'addRequest'); + const spyDeleteRequest = vi.spyOn(httpWaitService, 'deleteRequest'); const request = new HttpRequest('GET', 'https://abp.io'); const handleRes$ = new Subject(); @@ -71,10 +70,7 @@ describe('ApiInterceptor', () => { handleRes$.next(); handleRes$.complete(); - timer(0).subscribe(() => { - expect(spyAddRequest).toHaveBeenCalled(); - expect(spyDeleteRequest).toHaveBeenCalled(); - done(); - }); + expect(spyAddRequest).toHaveBeenCalled(); + expect(spyDeleteRequest).toHaveBeenCalled(); }); }); diff --git a/npm/ng-packs/packages/oauth/src/lib/tests/auth.guard.spec.ts b/npm/ng-packs/packages/oauth/src/lib/tests/auth.guard.spec.ts index 2b6603f39c..ccb4658999 100644 --- a/npm/ng-packs/packages/oauth/src/lib/tests/auth.guard.spec.ts +++ b/npm/ng-packs/packages/oauth/src/lib/tests/auth.guard.spec.ts @@ -1,4 +1,4 @@ -import { createServiceFactory, SpectatorService, createSpyObject } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, createSpyObject } from '@ngneat/spectator/vitest'; import { OAuthService } from 'angular-oauth2-oidc'; import { AbpOAuthGuard, abpOAuthGuard } from '../guards/oauth.guard'; import { AuthService } from '@abp/ng.core'; @@ -40,7 +40,7 @@ describe('AuthGuard', () => { it('should execute the navigateToLogin method of the authService', () => { const authService = spectator.inject(AuthService); spectator.inject(OAuthService).hasValidAccessToken.andReturn(false); - const navigateToLoginSpy = jest.spyOn(authService, 'navigateToLogin'); + const navigateToLoginSpy = vi.spyOn(authService, 'navigateToLogin'); expect(guard.canActivate(route, state)).toBe(false); expect(navigateToLoginSpy).toHaveBeenCalled(); diff --git a/npm/ng-packs/packages/oauth/src/lib/tests/initial-utils.spec.ts b/npm/ng-packs/packages/oauth/src/lib/tests/initial-utils.spec.ts index cd2dfbcac5..a8a4372817 100644 --- a/npm/ng-packs/packages/oauth/src/lib/tests/initial-utils.spec.ts +++ b/npm/ng-packs/packages/oauth/src/lib/tests/initial-utils.spec.ts @@ -1,6 +1,6 @@ import { Component, Injector } from '@angular/core'; -import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; -import { OAuthService } from 'angular-oauth2-oidc'; +import { createComponentFactory, Spectator } from '@ngneat/spectator/vitest'; +import { OAuthService, OAuthStorage } from 'angular-oauth2-oidc'; import { CORE_OPTIONS, @@ -42,6 +42,15 @@ describe('InitialUtils', () => { skipGetAppConfiguration: false, }, }, + { + provide: OAuthStorage, + useValue: { + getItem: vi.fn(), + setItem: vi.fn(), + removeItem: vi.fn(), + clear: vi.fn(), + }, + }, ], }); @@ -53,8 +62,8 @@ describe('InitialUtils', () => { let clearOAuthStorageSpy; beforeEach(() => { injector = spectator.inject(Injector); - injectorSpy = jest.spyOn(injector, 'get'); - clearOAuthStorageSpy = jest.spyOn(clearOAuthStorageDefault, 'clearOAuthStorage'); + injectorSpy = vi.spyOn(injector, 'get'); + clearOAuthStorageSpy = vi.spyOn(clearOAuthStorageDefault, 'clearOAuthStorage'); clearOAuthStorageSpy.mockReset(); }); diff --git a/npm/ng-packs/packages/oauth/src/lib/utils/check-access-token.ts b/npm/ng-packs/packages/oauth/src/lib/utils/check-access-token.ts index 84457c4c3c..38111dc3e9 100644 --- a/npm/ng-packs/packages/oauth/src/lib/utils/check-access-token.ts +++ b/npm/ng-packs/packages/oauth/src/lib/utils/check-access-token.ts @@ -7,6 +7,6 @@ export const checkAccessToken: CheckAuthenticationStateFn = function (injector: const configState = injector.get(ConfigStateService); const oAuth = injector.get(OAuthService); if (oAuth.hasValidAccessToken() && !configState.getDeep('currentUser.id')) { - clearOAuthStorage(this.injector); + clearOAuthStorage(injector); } };