Commits

Giuseppe Digilio authored b04c33a5fbf
Invalidate authorization requests cache on REHYDRATE
No tags

src/app/core/cache/object-cache.effects.spec.ts

Modified
1 1 import { TestBed } from '@angular/core/testing';
2 2 import { Observable } from 'rxjs';
3 3 import { provideMockActions } from '@ngrx/effects/testing';
4 4 import { cold, hot } from 'jasmine-marbles';
5 5 import { ObjectCacheEffects } from './object-cache.effects';
6 6 import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
7 7 import { StoreActionTypes } from '../../store.actions';
8 +import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
8 9
9 10 describe('ObjectCacheEffects', () => {
10 11 let cacheEffects: ObjectCacheEffects;
11 12 let actions: Observable<any>;
12 13 const timestamp = 10000;
14 + const authorizationService = jasmine.createSpyObj(['invalidateAuthorizationsRequestCache']);
15 +
13 16 beforeEach(() => {
14 17 TestBed.configureTestingModule({
15 18 providers: [
16 19 ObjectCacheEffects,
17 20 provideMockActions(() => actions),
21 + { provide: AuthorizationDataService, useValue: authorizationService },
18 22 // other providers
19 23 ],
20 24 });
21 25
22 26 cacheEffects = TestBed.inject(ObjectCacheEffects);
23 27 });
24 28
25 29 describe('fixTimestampsOnRehydrate$', () => {
26 30
27 31 it('should return a RESET_TIMESTAMPS action in response to a REHYDRATE action', () => {
28 32 spyOn(Date.prototype, 'getTime').and.callFake(() => {
29 33 return timestamp;
30 34 });
31 35 actions = hot('--a-', { a: { type: StoreActionTypes.REHYDRATE, payload: {} } });
32 36
33 37 const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) });
34 38
35 39 expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected);
40 + expect((cacheEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled();
36 41 });
37 42 });
38 43 });

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut