mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
move effect for cleaning cache to auth.effects
This commit is contained in:
@@ -35,6 +35,7 @@ import { EPersonMock } from '../../shared/testing/eperson.mock';
|
||||
import { AppState, storeModuleConfig } from '../../app.reducer';
|
||||
import { StoreActionTypes } from '../../store.actions';
|
||||
import { isAuthenticated, isAuthenticatedLoaded } from './selectors';
|
||||
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||
|
||||
describe('AuthEffects', () => {
|
||||
let authEffects: AuthEffects;
|
||||
@@ -44,6 +45,8 @@ describe('AuthEffects', () => {
|
||||
let token;
|
||||
let store: MockStore<AppState>;
|
||||
|
||||
const authorizationService = jasmine.createSpyObj(['invalidateAuthorizationsRequestCache']);
|
||||
|
||||
function init() {
|
||||
authServiceStub = new AuthServiceStub();
|
||||
token = authServiceStub.getToken();
|
||||
@@ -68,6 +71,7 @@ describe('AuthEffects', () => {
|
||||
providers: [
|
||||
AuthEffects,
|
||||
provideMockStore({ initialState }),
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: AuthService, useValue: authServiceStub },
|
||||
provideMockActions(() => actions),
|
||||
// other providers
|
||||
@@ -417,4 +421,16 @@ describe('AuthEffects', () => {
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalidateAuthorizationsRequestCache$', () => {
|
||||
it('should call invalidateAuthorizationsRequestCache method in response to a REHYDRATE action', (done) => {
|
||||
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
|
||||
|
||||
authEffects.invalidateAuthorizationsRequestCache$.subscribe(() => {
|
||||
expect((authEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -53,6 +53,7 @@ import { RequestActionTypes } from '../data/request.actions';
|
||||
import { NotificationsActionTypes } from '../../shared/notifications/notifications.actions';
|
||||
import { LeaveZoneScheduler } from '../utilities/leave-zone.scheduler';
|
||||
import { EnterZoneScheduler } from '../utilities/enter-zone.scheduler';
|
||||
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||
|
||||
// Action Types that do not break/prevent the user from an idle state
|
||||
const IDLE_TIMER_IGNORE_TYPES: string[]
|
||||
@@ -218,6 +219,16 @@ export class AuthEffects {
|
||||
);
|
||||
}));
|
||||
|
||||
/**
|
||||
* When the store is rehydrated in the browser, invalidate all cache hits regarding the
|
||||
* authorizations endpoint, to be sure to have consistent responses after a login with external idp
|
||||
*
|
||||
*/
|
||||
@Effect({ dispatch: false }) invalidateAuthorizationsRequestCache$ = this.actions$
|
||||
.pipe(ofType(StoreActionTypes.REHYDRATE),
|
||||
tap(() => this.authorizationsService.invalidateAuthorizationsRequestCache())
|
||||
);
|
||||
|
||||
@Effect()
|
||||
public logOut$: Observable<Action> = this.actions$
|
||||
.pipe(
|
||||
@@ -284,11 +295,13 @@ export class AuthEffects {
|
||||
* @constructor
|
||||
* @param {Actions} actions$
|
||||
* @param {NgZone} zone
|
||||
* @param {AuthorizationDataService} authorizationsService
|
||||
* @param {AuthService} authService
|
||||
* @param {Store} store
|
||||
*/
|
||||
constructor(private actions$: Actions,
|
||||
private zone: NgZone,
|
||||
private authorizationsService: AuthorizationDataService,
|
||||
private authService: AuthService,
|
||||
private store: Store<AppState>) {
|
||||
}
|
||||
|
@@ -5,20 +5,16 @@ import { cold, hot } from 'jasmine-marbles';
|
||||
import { ObjectCacheEffects } from './object-cache.effects';
|
||||
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
||||
import { StoreActionTypes } from '../../store.actions';
|
||||
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||
|
||||
describe('ObjectCacheEffects', () => {
|
||||
let cacheEffects: ObjectCacheEffects;
|
||||
let actions: Observable<any>;
|
||||
const timestamp = 10000;
|
||||
const authorizationService = jasmine.createSpyObj(['invalidateAuthorizationsRequestCache']);
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
ObjectCacheEffects,
|
||||
provideMockActions(() => actions),
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
// other providers
|
||||
],
|
||||
});
|
||||
@@ -37,7 +33,6 @@ describe('ObjectCacheEffects', () => {
|
||||
const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) });
|
||||
|
||||
expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected);
|
||||
expect((cacheEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
8
src/app/core/cache/object-cache.effects.ts
vendored
8
src/app/core/cache/object-cache.effects.ts
vendored
@@ -1,10 +1,9 @@
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Actions, Effect, ofType } from '@ngrx/effects';
|
||||
|
||||
import { StoreActionTypes } from '../../store.actions';
|
||||
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
||||
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class ObjectCacheEffects {
|
||||
@@ -19,11 +18,10 @@ export class ObjectCacheEffects {
|
||||
*/
|
||||
@Effect() fixTimestampsOnRehydrate = this.actions$
|
||||
.pipe(ofType(StoreActionTypes.REHYDRATE),
|
||||
map(() => new ResetObjectCacheTimestampsAction(new Date().getTime())),
|
||||
tap(() => this.authorizationsService.invalidateAuthorizationsRequestCache())
|
||||
map(() => new ResetObjectCacheTimestampsAction(new Date().getTime()))
|
||||
);
|
||||
|
||||
constructor(private actions$: Actions, private authorizationsService: AuthorizationDataService) {
|
||||
constructor(private actions$: Actions) {
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user