move effect for cleaning cache to auth.effects

This commit is contained in:
Giuseppe Digilio
2021-07-21 09:46:15 +02:00
parent b04c33a5fb
commit 85fa1c5a9c
4 changed files with 32 additions and 10 deletions

View File

@@ -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();
});
});
});