Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoAlbano committed Oct 15, 2024
1 parent 84986e8 commit dbda331
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions lib/core/src/lib/auth/guard/auth-guard.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion lib/core/src/lib/auth/services/identity-user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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);
Expand Down
11 changes: 3 additions & 8 deletions lib/core/src/lib/auth/services/jwt-helper.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
});
Expand Down Expand Up @@ -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', () => {
Expand Down
7 changes: 4 additions & 3 deletions lib/core/src/lib/auth/services/user-access.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion lib/core/src/lib/translation/translate-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -101,6 +101,7 @@ describe('EditProcessFilterCloudComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAuthModule,
MatIconTestingModule,
MatDialogModule,
NoopTranslateModule,
Expand Down

0 comments on commit dbda331

Please sign in to comment.