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:
95
src/provide-auth.spec.ts
Normal file
95
src/provide-auth.spec.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { APP_INITIALIZER } from '@angular/core';
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { mockProvider } from '../test/auto-mock';
|
||||
import { PASSED_CONFIG } from './auth-config';
|
||||
import { ConfigurationService } from './config/config.service';
|
||||
import {
|
||||
StsConfigHttpLoader,
|
||||
StsConfigLoader,
|
||||
StsConfigStaticLoader,
|
||||
} from './config/loader/config-loader';
|
||||
import { OidcSecurityService } from './oidc.security.service';
|
||||
import { provideAuth, withAppInitializerAuthCheck } from './provide-auth';
|
||||
|
||||
describe('provideAuth', () => {
|
||||
describe('APP_CONFIG', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
provideAuth({ config: { authority: 'something' } }),
|
||||
mockProvider(ConfigurationService),
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should provide config', () => {
|
||||
const config = TestBed.inject(PASSED_CONFIG);
|
||||
|
||||
expect(config).toEqual({ config: { authority: 'something' } });
|
||||
});
|
||||
|
||||
it('should create StsConfigStaticLoader if config is passed', () => {
|
||||
const configLoader = TestBed.inject(StsConfigLoader);
|
||||
|
||||
expect(configLoader instanceof StsConfigStaticLoader).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('StsConfigHttpLoader', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
provideAuth({
|
||||
loader: {
|
||||
provide: StsConfigLoader,
|
||||
useFactory: () => new StsConfigHttpLoader(of({})),
|
||||
},
|
||||
}),
|
||||
mockProvider(ConfigurationService),
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create StsConfigStaticLoader if config is passed', () => {
|
||||
const configLoader = TestBed.inject(StsConfigLoader);
|
||||
|
||||
expect(configLoader instanceof StsConfigHttpLoader).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('features', () => {
|
||||
let oidcSecurityServiceMock: jasmine.SpyObj<OidcSecurityService>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
oidcSecurityServiceMock = jasmine.createSpyObj<OidcSecurityService>(
|
||||
'OidcSecurityService',
|
||||
['checkAuthMultiple']
|
||||
);
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
provideAuth(
|
||||
{ config: { authority: 'something' } },
|
||||
withAppInitializerAuthCheck()
|
||||
),
|
||||
mockProvider(ConfigurationService),
|
||||
{
|
||||
provide: OidcSecurityService,
|
||||
useValue: oidcSecurityServiceMock,
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should provide APP_INITIALIZER config', () => {
|
||||
const config = TestBed.inject(APP_INITIALIZER);
|
||||
|
||||
expect(config.length)
|
||||
.withContext('Expected an APP_INITIALIZER to be registered')
|
||||
.toBe(1);
|
||||
expect(oidcSecurityServiceMock.checkAuthMultiple).toHaveBeenCalledTimes(
|
||||
1
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user