Fixed unit tests

This commit is contained in:
VitoAlbano
2024-10-15 13:15:03 +01:00
parent 349b3c197d
commit b5dd7c23fc
11 changed files with 17 additions and 29 deletions

View File

@@ -27,8 +27,6 @@ import { EMPTY, of } from 'rxjs';
import { OidcAuthenticationService } from '../oidc/oidc-authentication.service'; import { OidcAuthenticationService } from '../oidc/oidc-authentication.service';
import { AuthGuardService } from './auth-guard.service'; import { AuthGuardService } from './auth-guard.service';
import { NoopTranslateModule } from '../../testing/noop-translate.module'; import { NoopTranslateModule } from '../../testing/noop-translate.module';
import { JWT_STORAGE_SERVICE } from '../public-api';
import { StorageService } from '../../common';
describe('AuthGuardService BPM', () => { describe('AuthGuardService BPM', () => {
let authGuard: Promise<boolean>; let authGuard: Promise<boolean>;
@@ -47,7 +45,6 @@ describe('AuthGuardService BPM', () => {
providers: [ providers: [
AuthGuardService, AuthGuardService,
{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }, { provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } },
{ provide: JWT_STORAGE_SERVICE, useClass: StorageService },
{ {
provide: OidcAuthenticationService, provide: OidcAuthenticationService,
useValue: { useValue: {

View File

@@ -27,8 +27,7 @@ import { RedirectAuthService } from '../oidc/redirect-auth.service';
import { EMPTY, of } from 'rxjs'; import { EMPTY, of } from 'rxjs';
import { OidcAuthenticationService } from '../oidc/oidc-authentication.service'; import { OidcAuthenticationService } from '../oidc/oidc-authentication.service';
import { NoopTranslateModule } from '../../testing/noop-translate.module'; import { NoopTranslateModule } from '../../testing/noop-translate.module';
import { JWT_STORAGE_SERVICE } from '../public-api';
import { StorageService } from '../../common';
describe('AuthGuardService ECM', () => { describe('AuthGuardService ECM', () => {
let authGuard: Promise<boolean>; let authGuard: Promise<boolean>;
@@ -56,8 +55,7 @@ describe('AuthGuardService ECM', () => {
shouldPerformSsoLogin$: of(true) shouldPerformSsoLogin$: of(true)
} }
}, },
{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }, { provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }
{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }
] ]
}); });
localStorage.clear(); localStorage.clear();

View File

@@ -18,10 +18,9 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'; import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service'; import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service';
import { JwtHelperService, JWT_STORAGE_SERVICE } from '../services/jwt-helper.service'; import { JwtHelperService } from '../services/jwt-helper.service';
import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { NoopTranslateModule } from '../../testing/noop-translate.module'; import { NoopTranslateModule } from '../../testing/noop-translate.module';
import { StorageService } from '../../common';
describe('Auth Guard SSO role service', () => { describe('Auth Guard SSO role service', () => {
let jwtHelperService: JwtHelperService; let jwtHelperService: JwtHelperService;
@@ -30,8 +29,7 @@ describe('Auth Guard SSO role service', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [NoopTranslateModule, MatDialogModule], imports: [NoopTranslateModule, MatDialogModule]
providers: [{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }]
}); });
localStorage.clear(); localStorage.clear();
jwtHelperService = TestBed.inject(JwtHelperService); jwtHelperService = TestBed.inject(JwtHelperService);

View File

@@ -28,7 +28,6 @@ import { EMPTY, of } from 'rxjs';
import { MatDialogModule } from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { NoopTranslateModule } from '../../testing/noop-translate.module'; import { NoopTranslateModule } from '../../testing/noop-translate.module';
import { JWT_STORAGE_SERVICE } from '../public-api';
describe('AuthGuardService', () => { describe('AuthGuardService', () => {
let state: RouterStateSnapshot; let state: RouterStateSnapshot;
@@ -46,7 +45,6 @@ describe('AuthGuardService', () => {
imports: [NoopTranslateModule, MatDialogModule, RouterTestingModule], imports: [NoopTranslateModule, MatDialogModule, RouterTestingModule],
providers: [ providers: [
AppConfigService, AppConfigService,
{ provide: JWT_STORAGE_SERVICE, useClass: StorageService },
{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }, { provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } },
{ {
provide: OidcAuthenticationService, provide: OidcAuthenticationService,

View File

@@ -65,6 +65,7 @@ describe('OidcAuthenticationService', () => {
{ provide: OAuthService, useClass: MockOAuthService }, { provide: OAuthService, useClass: MockOAuthService },
{ provide: OAuthStorage, useValue: {} }, { provide: OAuthStorage, useValue: {} },
{ provide: AUTH_MODULE_CONFIG, useValue: {} }, { provide: AUTH_MODULE_CONFIG, useValue: {} },
{ provide: AuthService, useValue: {} }
] ]
}); });
service = TestBed.inject(OidcAuthenticationService); service = TestBed.inject(OidcAuthenticationService);

View File

@@ -29,7 +29,7 @@ import {
} from '../mock/identity-user.mock'; } from '../mock/identity-user.mock';
import { mockGroups, mockJoinGroupRequest } from '../mock/identity-group.mock'; import { mockGroups, mockJoinGroupRequest } from '../mock/identity-group.mock';
import { IdentityUserService } from './identity-user.service'; import { IdentityUserService } from './identity-user.service';
import { JwtHelperService, JWT_STORAGE_SERVICE } from './jwt-helper.service'; import { JwtHelperService } from './jwt-helper.service';
import { mockToken } from '../mock/jwt-helper.service.spec'; import { mockToken } from '../mock/jwt-helper.service.spec';
import { IdentityRoleModel } from '../models/identity-role.model'; import { IdentityRoleModel } from '../models/identity-role.model';
import { AdfHttpClient } from '../../../../api/src'; import { AdfHttpClient } from '../../../../api/src';
@@ -53,7 +53,7 @@ describe('IdentityUserService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [NoopTranslateModule], imports: [NoopTranslateModule],
providers: [{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }, AdfHttpClient] providers: [AdfHttpClient]
}); });
storageService = TestBed.inject(StorageService); storageService = TestBed.inject(StorageService);
service = TestBed.inject(IdentityUserService); service = TestBed.inject(IdentityUserService);

View File

@@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
import { JWT_STORAGE_SERVICE, JwtHelperService } from './jwt-helper.service'; import { JwtHelperService } from './jwt-helper.service';
import { mockToken } from '../mock/jwt-helper.service.spec'; import { mockToken } from '../mock/jwt-helper.service.spec';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { StorageService } from '../../common'; import { StorageService } from '../../common';
import { OAuthStorage } from 'angular-oauth2-oidc'; import { OAuthStorage } from 'angular-oauth2-oidc';
import { JWT_STORAGE_SERVICE } from '../oidc/auth.module';
const mockStorage = { const mockStorage = {
access_token: 'my-access_token', access_token: 'my-access_token',

View File

@@ -17,7 +17,7 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { UserAccessService } from './user-access.service'; import { UserAccessService } from './user-access.service';
import { JwtHelperService, JWT_STORAGE_SERVICE } from './jwt-helper.service'; import { JwtHelperService } from './jwt-helper.service';
import { AppConfigService } from '../../app-config'; import { AppConfigService } from '../../app-config';
import { HttpClientTestingModule } from '@angular/common/http/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing';
import { StorageService } from '../../common'; import { StorageService } from '../../common';
@@ -30,7 +30,7 @@ describe('UserAccessService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [HttpClientTestingModule], imports: [HttpClientTestingModule],
providers: [{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }, UserAccessService] providers: [UserAccessService]
}); });
userAccessService = TestBed.inject(UserAccessService); userAccessService = TestBed.inject(UserAccessService);
jwtHelperService = TestBed.inject(JwtHelperService); jwtHelperService = TestBed.inject(JwtHelperService);

View File

@@ -22,7 +22,6 @@ import { TranslateModule } from '@ngx-translate/core';
import { CoreModule } from '../core.module'; import { CoreModule } from '../core.module';
import { AuthModule } from '../auth/oidc/auth.module'; import { AuthModule } from '../auth/oidc/auth.module';
import { StorageService } from '../common'; import { StorageService } from '../common';
import { JWT_STORAGE_SERVICE } from '../auth/services/jwt-helper.service';
declare let jasmine: any; declare let jasmine: any;
@@ -33,7 +32,7 @@ describe('TranslateLoader', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [AuthModule.forRoot({ useHash: true }), TranslateModule.forRoot(), CoreModule.forRoot()], imports: [AuthModule.forRoot({ useHash: true }), TranslateModule.forRoot(), CoreModule.forRoot()],
providers: [TranslationService, { provide: JWT_STORAGE_SERVICE, useClass: StorageService }] providers: [TranslationService]
}); });
translationService = TestBed.inject(TranslationService); translationService = TestBed.inject(TranslationService);
customLoader = translationService.translate.currentLoader as TranslateLoaderService; customLoader = translationService.translate.currentLoader as TranslateLoaderService;

View File

@@ -32,9 +32,7 @@ import {
WidgetVisibilityService, WidgetVisibilityService,
provideTranslations, provideTranslations,
AuthModule, AuthModule,
FormFieldEvent, FormFieldEvent
StorageService,
JWT_STORAGE_SERVICE
} from '@alfresco/adf-core'; } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
import { ESCAPE } from '@angular/cdk/keycodes'; import { ESCAPE } from '@angular/cdk/keycodes';
@@ -1474,7 +1472,7 @@ describe('Multilingual Form', () => {
CoreModule.forRoot(), CoreModule.forRoot(),
ProcessServicesCloudModule.forRoot() ProcessServicesCloudModule.forRoot()
], ],
providers: [{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }, provideTranslations('app', 'resources')] providers: [provideTranslations('app', 'resources')]
}); });
translateService = TestBed.inject(TranslateService); translateService = TestBed.inject(TranslateService);
formCloudService = TestBed.inject(FormCloudService); formCloudService = TestBed.inject(FormCloudService);
@@ -1547,8 +1545,7 @@ describe('retrieve metadata on submit', () => {
{ {
provide: VersionCompatibilityService, provide: VersionCompatibilityService,
useValue: {} useValue: {}
}, }
{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }
] ]
}); });
const apiService = TestBed.inject(AlfrescoApiService); const apiService = TestBed.inject(AlfrescoApiService);

View File

@@ -16,7 +16,7 @@
*/ */
import { AlfrescoApiService } from '@alfresco/adf-content-services'; import { AlfrescoApiService } from '@alfresco/adf-content-services';
import { ADF_DATE_FORMATS, FullNamePipe, JWT_STORAGE_SERVICE, NoopTranslateModule, StorageService, UserPreferencesService } from '@alfresco/adf-core'; import { ADF_DATE_FORMATS, FullNamePipe, NoopTranslateModule, UserPreferencesService } from '@alfresco/adf-core';
import { HarnessLoader } from '@angular/cdk/testing'; import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { SimpleChange } from '@angular/core'; import { SimpleChange } from '@angular/core';
@@ -121,8 +121,7 @@ describe('EditProcessFilterCloudComponent', () => {
{ provide: DateAdapter, useClass: DateFnsAdapter }, { provide: DateAdapter, useClass: DateFnsAdapter },
{ provide: NotificationCloudService, useValue: { makeGQLQuery: () => of([]) } }, { provide: NotificationCloudService, useValue: { makeGQLQuery: () => of([]) } },
{ provide: MAT_DATE_FORMATS, useValue: ADF_DATE_FORMATS }, { provide: MAT_DATE_FORMATS, useValue: ADF_DATE_FORMATS },
{ provide: IDENTITY_USER_SERVICE_TOKEN, useExisting: IdentityUserServiceMock }, { provide: IDENTITY_USER_SERVICE_TOKEN, useExisting: IdentityUserServiceMock }
{ provide: JWT_STORAGE_SERVICE, useClass: StorageService }
], ],
declarations: [PeopleCloudComponent, DateRangeFilterComponent] declarations: [PeopleCloudComponent, DateRangeFilterComponent]
}); });