Skip to content

Commit

Permalink
NAS-128920: Adding empty class for missing ws.service.ts and `auth.…
Browse files Browse the repository at this point in the history
…service.ts` (#10305)
  • Loading branch information
RehanY147 authored Jul 10, 2024
1 parent c9854bc commit 08e6b4e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class AuthService {
* time of a token generated with auth.generate_token. The 10 seconds
* difference is to allow for delays in request send/receive
*/
readonly tokenRegenerationTimeMillis = 290 * 1000;
private readonly tokenRegenerationTimeMillis = 290 * 1000;

private latestTokenGenerated$ = new ReplaySubject<string>(1);
get authToken$(): Observable<string> {
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/ws.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { WebSocketConnectionService } from 'app/services/websocket-connection.se
})
export class WebSocketService {
private readonly eventSubscribers = new Map<ApiEventMethod, Observable<ApiEventTyped>>();
clearSubscriptions$ = new Subject<void>();
readonly clearSubscriptions$ = new Subject<void>();

constructor(
protected router: Router,
Expand Down
16 changes: 15 additions & 1 deletion src/setup-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import {
import failOnConsole from 'jest-fail-on-console';
import { MockProvider } from 'ng-mocks';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
import { Observable } from 'rxjs';
import {
Observable,
} from 'rxjs';
import { EmptyAuthService } from 'test-utils/empty-auth.service';
import { EmptyWebsocketService } from 'test-utils/empty-ws.service';
import { IcuMissingTranslationHandler } from 'app/core/classes/icu-missing-translation-handler';
import { CommonDirectivesModule } from 'app/directives/common/common-directives.module';
import { WINDOW } from 'app/helpers/window.helper';
Expand All @@ -40,7 +44,9 @@ import { AppLoaderModule } from 'app/modules/loader/app-loader.module';
import { AppLoaderService } from 'app/modules/loader/app-loader.service';
import { SnackbarModule } from 'app/modules/snackbar/snackbar.module';
import { TestIdModule } from 'app/modules/test-id/test-id.module';
import { AuthService } from 'app/services/auth/auth.service';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { WebSocketService } from 'app/services/ws.service';

failOnConsole();

Expand Down Expand Up @@ -113,6 +119,14 @@ defineGlobalsInjections({
mockProvider(ErrorHandlerService, {
catchError: () => (source$: Observable<unknown>) => source$,
}),
{
provide: AuthService,
useClass: EmptyAuthService,
},
{
provide: WebSocketService,
useClass: EmptyWebsocketService,
},
],
});

Expand Down
18 changes: 18 additions & 0 deletions src/test-utils/empty-auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getMissingInjectionErrorFactory, getMissingInjectionErrorObservable } from 'test-utils/missing-injection-factories';
import { AuthService } from 'app/services/auth/auth.service';

export class EmptyAuthService {
readonly authToken$ = getMissingInjectionErrorObservable(AuthService.name);
readonly isAuthenticated$ = getMissingInjectionErrorObservable(AuthService.name);
readonly user$ = getMissingInjectionErrorObservable(AuthService.name);
readonly isSysAdmin$ = getMissingInjectionErrorObservable(AuthService.name);
readonly userTwoFactorConfig$ = getMissingInjectionErrorObservable(AuthService.name);
getGlobalTwoFactorConfig = getMissingInjectionErrorFactory(AuthService.name);
globalTwoFactorConfigUpdated = getMissingInjectionErrorFactory(AuthService.name);
clearAuthToken = getMissingInjectionErrorFactory(AuthService.name);
login = getMissingInjectionErrorFactory(AuthService.name);
hasRole = getMissingInjectionErrorFactory(AuthService.name);
logout = getMissingInjectionErrorFactory(AuthService.name);
refreshUser = getMissingInjectionErrorFactory(AuthService.name);
loginWithToken = getMissingInjectionErrorFactory(AuthService.name);
}
13 changes: 13 additions & 0 deletions src/test-utils/empty-ws.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getMissingInjectionErrorFactory, getMissingInjectionErrorObservable } from 'test-utils/missing-injection-factories';
import { WebSocketService } from 'app/services/ws.service';

export class EmptyWebsocketService {
readonly clearSubscriptions$ = getMissingInjectionErrorObservable(WebSocketService.name);
call = getMissingInjectionErrorFactory(WebSocketService.name);
job = getMissingInjectionErrorFactory(WebSocketService.name);
callAndSubscribe = getMissingInjectionErrorFactory(WebSocketService.name);
startJob = getMissingInjectionErrorFactory(WebSocketService.name);
subscribe = getMissingInjectionErrorFactory(WebSocketService.name);
subscribeToLogs = getMissingInjectionErrorFactory(WebSocketService.name);
clearSubscriptions = getMissingInjectionErrorFactory(WebSocketService.name);
}
11 changes: 11 additions & 0 deletions src/test-utils/missing-injection-factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Observable, throwError } from 'rxjs';

export function getMissingInjectionErrorFactory(className: string): () => Observable<unknown> {
return function getMissingInjectionError(): Observable<unknown> {
return getMissingInjectionErrorObservable(className);
};
}

export function getMissingInjectionErrorObservable(className: string): Observable<never> {
return throwError(() => new Error(`${className} injection not provided`));
}

0 comments on commit 08e6b4e

Please sign in to comment.