feat: init and fork some code from angular-auth-oidc-client
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
This commit is contained in:
101
src/callback/refresh-session-refresh-token.service.spec.ts
Normal file
101
src/callback/refresh-session-refresh-token.service.spec.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { mockProvider } from '../../test/auto-mock';
|
||||
import { CallbackContext } from '../flows/callback-context';
|
||||
import { FlowsService } from '../flows/flows.service';
|
||||
import { ResetAuthDataService } from '../flows/reset-auth-data.service';
|
||||
import { LoggerService } from '../logging/logger.service';
|
||||
import { IntervalService } from './interval.service';
|
||||
import { RefreshSessionRefreshTokenService } from './refresh-session-refresh-token.service';
|
||||
|
||||
describe('RefreshSessionRefreshTokenService', () => {
|
||||
let refreshSessionRefreshTokenService: RefreshSessionRefreshTokenService;
|
||||
let intervalService: IntervalService;
|
||||
let resetAuthDataService: ResetAuthDataService;
|
||||
let flowsService: FlowsService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
providers: [
|
||||
RefreshSessionRefreshTokenService,
|
||||
mockProvider(LoggerService),
|
||||
mockProvider(FlowsService),
|
||||
mockProvider(ResetAuthDataService),
|
||||
mockProvider(IntervalService),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
flowsService = TestBed.inject(FlowsService);
|
||||
refreshSessionRefreshTokenService = TestBed.inject(
|
||||
RefreshSessionRefreshTokenService
|
||||
);
|
||||
intervalService = TestBed.inject(IntervalService);
|
||||
resetAuthDataService = TestBed.inject(ResetAuthDataService);
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(refreshSessionRefreshTokenService).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('refreshSessionWithRefreshTokens', () => {
|
||||
it('calls flowsService.processRefreshToken()', waitForAsync(() => {
|
||||
const spy = spyOn(flowsService, 'processRefreshToken').and.returnValue(
|
||||
of({} as CallbackContext)
|
||||
);
|
||||
|
||||
refreshSessionRefreshTokenService
|
||||
.refreshSessionWithRefreshTokens({ configId: 'configId1' }, [
|
||||
{ configId: 'configId1' },
|
||||
])
|
||||
.subscribe(() => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('resetAuthorizationData in case of error', waitForAsync(() => {
|
||||
spyOn(flowsService, 'processRefreshToken').and.returnValue(
|
||||
throwError(() => new Error('error'))
|
||||
);
|
||||
const resetSilentRenewRunningSpy = spyOn(
|
||||
resetAuthDataService,
|
||||
'resetAuthorizationData'
|
||||
);
|
||||
|
||||
refreshSessionRefreshTokenService
|
||||
.refreshSessionWithRefreshTokens({ configId: 'configId1' }, [
|
||||
{ configId: 'configId1' },
|
||||
])
|
||||
.subscribe({
|
||||
error: (err) => {
|
||||
expect(resetSilentRenewRunningSpy).toHaveBeenCalled();
|
||||
expect(err).toBeTruthy();
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
it('finalize with stopPeriodicTokenCheck in case of error', fakeAsync(() => {
|
||||
spyOn(flowsService, 'processRefreshToken').and.returnValue(
|
||||
throwError(() => new Error('error'))
|
||||
);
|
||||
const stopPeriodicallyTokenCheckSpy = spyOn(
|
||||
intervalService,
|
||||
'stopPeriodicTokenCheck'
|
||||
);
|
||||
|
||||
refreshSessionRefreshTokenService
|
||||
.refreshSessionWithRefreshTokens({ configId: 'configId1' }, [
|
||||
{ configId: 'configId1' },
|
||||
])
|
||||
.subscribe({
|
||||
error: (err) => {
|
||||
expect(err).toBeTruthy();
|
||||
},
|
||||
});
|
||||
tick();
|
||||
expect(stopPeriodicallyTokenCheckSpy).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user