From dbda331088e4750770a91286799c398791a1e789 Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Tue, 15 Oct 2024 14:45:49 +0100 Subject: [PATCH] Fixed unit tests --- .../auth/guard/auth-guard-sso-role.service.spec.ts | 3 ++- .../src/lib/auth/guard/auth-guard.service.spec.ts | 5 +++-- .../lib/auth/services/identity-user.service.spec.ts | 3 ++- .../src/lib/auth/services/jwt-helper.service.spec.ts | 11 +++-------- .../src/lib/auth/services/user-access.service.spec.ts | 7 ++++--- lib/core/src/lib/translation/translate-loader.spec.ts | 1 - .../edit-process-filter-cloud.component.spec.ts | 3 ++- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts index 8b7c0fb2cfc..d3d1fb86301 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts @@ -21,6 +21,7 @@ import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service'; import { JwtHelperService } from '../services/jwt-helper.service'; import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { NoopTranslateModule } from '../../testing/noop-translate.module'; +import { AuthModule } from '../oidc/auth.module'; describe('Auth Guard SSO role service', () => { let jwtHelperService: JwtHelperService; @@ -29,7 +30,7 @@ describe('Auth Guard SSO role service', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [NoopTranslateModule, MatDialogModule] + imports: [NoopTranslateModule, MatDialogModule, AuthModule.forRoot({ useHash: true })] }); localStorage.clear(); jwtHelperService = TestBed.inject(JwtHelperService); diff --git a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts index b8a7b4c88dd..46b4ada6680 100644 --- a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts @@ -28,6 +28,7 @@ import { EMPTY, of } from 'rxjs'; import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { NoopTranslateModule } from '../../testing/noop-translate.module'; +import { NoopAuthModule } from '../../testing'; describe('AuthGuardService', () => { let state: RouterStateSnapshot; @@ -42,10 +43,10 @@ describe('AuthGuardService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [NoopTranslateModule, MatDialogModule, RouterTestingModule], + imports: [NoopTranslateModule, MatDialogModule, RouterTestingModule, NoopAuthModule], providers: [ AppConfigService, - { provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }, + { provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of(), init: () => {} } }, { provide: OidcAuthenticationService, useValue: { diff --git a/lib/core/src/lib/auth/services/identity-user.service.spec.ts b/lib/core/src/lib/auth/services/identity-user.service.spec.ts index dffe037b8e2..31bdcbf62ad 100644 --- a/lib/core/src/lib/auth/services/identity-user.service.spec.ts +++ b/lib/core/src/lib/auth/services/identity-user.service.spec.ts @@ -35,6 +35,7 @@ import { IdentityRoleModel } from '../models/identity-role.model'; import { AdfHttpClient } from '../../../../api/src'; import { StorageService } from '../../common/services/storage.service'; import { NoopTranslateModule } from '../../testing/noop-translate.module'; +import { OAuthStorage } from 'angular-oauth2-oidc'; describe('IdentityUserService', () => { const mockRoles = [ @@ -53,7 +54,7 @@ describe('IdentityUserService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [NoopTranslateModule], - providers: [AdfHttpClient] + providers: [AdfHttpClient, { provide: OAuthStorage, useClass: StorageService }] }); storageService = TestBed.inject(StorageService); service = TestBed.inject(IdentityUserService); diff --git a/lib/core/src/lib/auth/services/jwt-helper.service.spec.ts b/lib/core/src/lib/auth/services/jwt-helper.service.spec.ts index a1c7c702c1f..fd35d20f1b2 100644 --- a/lib/core/src/lib/auth/services/jwt-helper.service.spec.ts +++ b/lib/core/src/lib/auth/services/jwt-helper.service.spec.ts @@ -20,7 +20,6 @@ import { mockToken } from '../mock/jwt-helper.service.spec'; import { TestBed } from '@angular/core/testing'; import { StorageService } from '../../common'; import { OAuthStorage } from 'angular-oauth2-oidc'; -import { JWT_STORAGE_SERVICE } from '../oidc/auth.module'; const mockStorage = { access_token: 'my-access_token', @@ -43,7 +42,7 @@ describe('JwtHelperService', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [JwtHelperService, { provide: JWT_STORAGE_SERVICE, useValue: mockStorage }] + providers: [JwtHelperService, { provide: OAuthStorage, useValue: mockStorage }] }); jwtHelperService = TestBed.inject(JwtHelperService); }); @@ -141,15 +140,11 @@ describe('JwtHelperService with custom storage service', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [ - JwtHelperService, - { provide: StorageService, useValue: mockStorage }, - { provide: JWT_STORAGE_SERVICE, useValue: mockCustomStorage } - ] + providers: [JwtHelperService, { provide: StorageService, useValue: mockStorage }, { provide: OAuthStorage, useValue: mockCustomStorage }] }); jwtHelperService = TestBed.inject(JwtHelperService); defaultStorage = TestBed.inject(StorageService); - customStorage = TestBed.inject(JWT_STORAGE_SERVICE); + customStorage = TestBed.inject(OAuthStorage); }); it('should use the custom storage service', () => { diff --git a/lib/core/src/lib/auth/services/user-access.service.spec.ts b/lib/core/src/lib/auth/services/user-access.service.spec.ts index efc49018f8e..764f6715eba 100644 --- a/lib/core/src/lib/auth/services/user-access.service.spec.ts +++ b/lib/core/src/lib/auth/services/user-access.service.spec.ts @@ -20,7 +20,8 @@ import { UserAccessService } from './user-access.service'; import { JwtHelperService } from './jwt-helper.service'; import { AppConfigService } from '../../app-config'; import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { StorageService } from '../../common'; +import { AuthModule, JWT_STORAGE_SERVICE } from '../oidc/auth.module'; +import { StorageService } from '../../common/services/storage.service'; describe('UserAccessService', () => { let userAccessService: UserAccessService; @@ -29,8 +30,8 @@ describe('UserAccessService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], - providers: [UserAccessService] + imports: [HttpClientTestingModule, AuthModule.forRoot({ useHash: true })], + providers: [{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }, UserAccessService] }); userAccessService = TestBed.inject(UserAccessService); jwtHelperService = TestBed.inject(JwtHelperService); diff --git a/lib/core/src/lib/translation/translate-loader.spec.ts b/lib/core/src/lib/translation/translate-loader.spec.ts index 08e4e55b522..3fcd9be64bc 100644 --- a/lib/core/src/lib/translation/translate-loader.spec.ts +++ b/lib/core/src/lib/translation/translate-loader.spec.ts @@ -21,7 +21,6 @@ import { TranslationService } from './translation.service'; import { TranslateModule } from '@ngx-translate/core'; import { CoreModule } from '../core.module'; import { AuthModule } from '../auth/oidc/auth.module'; -import { StorageService } from '../common'; declare let jasmine: any; diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts index d94aa24dc8c..af281965d85 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts @@ -16,7 +16,7 @@ */ import { AlfrescoApiService } from '@alfresco/adf-content-services'; -import { ADF_DATE_FORMATS, FullNamePipe, NoopTranslateModule, UserPreferencesService } from '@alfresco/adf-core'; +import { ADF_DATE_FORMATS, FullNamePipe, NoopAuthModule, NoopTranslateModule, UserPreferencesService } from '@alfresco/adf-core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { SimpleChange } from '@angular/core'; @@ -101,6 +101,7 @@ describe('EditProcessFilterCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ + NoopAuthModule, MatIconTestingModule, MatDialogModule, NoopTranslateModule,