Skip to content

Commit

Permalink
Merge pull request #1922 from andsouto/refresh-authWellKnownEndPoints
Browse files Browse the repository at this point in the history
fix: refresh authWellKnownEndPoints
  • Loading branch information
FabianGosebrink committed Apr 4, 2024
2 parents 0fe5da3 + 1ef3518 commit b2e26f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,37 @@ 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'
).and.returnValue(of({ issuer: 'anything' }));

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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b2e26f7

Please sign in to comment.