diff --git a/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.spec.ts b/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.spec.ts index 2e61fd57..84eb6dd7 100644 --- a/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.spec.ts +++ b/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.spec.ts @@ -36,25 +36,18 @@ describe('AuthWellKnownService', () => { }); describe('getAuthWellKnownEndPoints', () => { - it('getAuthWellKnownEndPoints return stored endpoints if they exist', waitForAsync(() => { - const dataServiceSpy = spyOn( - dataService, - 'getWellKnownEndPointsForConfig' - ); - - spyOn(storagePersistenceService, 'read') - .withArgs('authWellKnownEndPoints', { configId: 'configId1' }) - .and.returnValue({ issuer: 'anything' }); - + it('getAuthWellKnownEndPoints throws an error if not config provided', waitForAsync(() => { service - .queryAndStoreAuthWellKnownEndPoints({ configId: 'configId1' }) - .subscribe((result) => { - expect(dataServiceSpy).not.toHaveBeenCalled(); - expect(result).toEqual({ issuer: 'anything' }); + .queryAndStoreAuthWellKnownEndPoints(null) + .subscribe({ + error: (error) => { + expect(error).toEqual(new Error('Please provide a configuration before setting up the module')) + } }); })); - it('getAuthWellKnownEndPoints calls dataservice if none is stored', waitForAsync(() => { + + it('getAuthWellKnownEndPoints calls always dataservice', waitForAsync(() => { const dataServiceSpy = spyOn( dataService, 'getWellKnownEndPointsForConfig' @@ -62,16 +55,18 @@ describe('AuthWellKnownService', () => { spyOn(storagePersistenceService, 'read') .withArgs('authWellKnownEndPoints', { configId: 'configId1' }) - .and.returnValue(null); + .and.returnValue({ issuer: 'anything' }); + service .queryAndStoreAuthWellKnownEndPoints({ configId: 'configId1' }) .subscribe((result) => { + expect(storagePersistenceService.read).not.toHaveBeenCalled(); expect(dataServiceSpy).toHaveBeenCalled(); expect(result).toEqual({ issuer: 'anything' }); }); })); - it('getAuthWellKnownEndPoints stored the result if http cal is made', waitForAsync(() => { + it('getAuthWellKnownEndPoints stored the result if http call is made', waitForAsync(() => { const dataServiceSpy = spyOn( dataService, 'getWellKnownEndPointsForConfig' diff --git a/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.ts b/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.ts index 575bf65a..d5a4a226 100644 --- a/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service.ts @@ -1,5 +1,5 @@ import { Injectable, inject } from '@angular/core'; -import { Observable, of, throwError } from 'rxjs'; +import { Observable, throwError } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; import { EventTypes } from '../../public-events/event-types'; import { PublicEventsService } from '../../public-events/public-events.service'; @@ -41,15 +41,6 @@ export class AuthWellKnownService { ); } - const alreadySavedWellKnownEndpoints = this.storagePersistenceService.read( - 'authWellKnownEndPoints', - config - ); - - if (!!alreadySavedWellKnownEndpoints) { - return of(alreadySavedWellKnownEndpoints); - } - return this.dataService.getWellKnownEndPointsForConfig(config).pipe( tap((mappedWellKnownEndpoints) => this.storeWellKnownEndpoints(config, mappedWellKnownEndpoints)