Commits
Tim Donohue authored and GitHub committed 499463f47e5 Merge
1 1 | import { Store, StoreModule } from '@ngrx/store'; |
2 2 | import { cold, getTestScheduler } from 'jasmine-marbles'; |
3 - | import { EMPTY, of as observableOf } from 'rxjs'; |
3 + | import { EMPTY, Observable, of as observableOf } from 'rxjs'; |
4 4 | import { TestScheduler } from 'rxjs/testing'; |
5 5 | |
6 6 | import { getMockObjectCacheService } from '../../shared/mocks/object-cache.service.mock'; |
7 7 | import { defaultUUID, getMockUUIDService } from '../../shared/mocks/uuid.service.mock'; |
8 8 | import { ObjectCacheService } from '../cache/object-cache.service'; |
9 9 | import { coreReducers} from '../core.reducers'; |
10 10 | import { UUIDService } from '../shared/uuid.service'; |
11 11 | import { RequestConfigureAction, RequestExecuteAction, RequestStaleAction } from './request.actions'; |
12 12 | import { |
13 13 | DeleteRequest, |
631 631 | a: { state: RequestEntryState.ResponsePending }, |
632 632 | b: { state: RequestEntryState.Success }, |
633 633 | c: { state: RequestEntryState.SuccessStale }, |
634 634 | d: { state: RequestEntryState.Error }, |
635 635 | })); |
636 636 | |
637 637 | const done$ = service.setStaleByUUID('something'); |
638 638 | expect(done$).toBeObservable(cold('-----(t|)', { t: true })); |
639 639 | })); |
640 640 | }); |
641 + | |
642 + | describe('setStaleByHrefSubstring', () => { |
643 + | let dispatchSpy: jasmine.Spy; |
644 + | let getByUUIDSpy: jasmine.Spy; |
645 + | |
646 + | beforeEach(() => { |
647 + | dispatchSpy = spyOn(store, 'dispatch'); |
648 + | getByUUIDSpy = spyOn(service, 'getByUUID').and.callThrough(); |
649 + | }); |
650 + | |
651 + | describe('with an empty/no matching requests in the state', () => { |
652 + | it('should return true', () => { |
653 + | const done$: Observable<boolean> = service.setStaleByHrefSubstring('https://rest.api/endpoint/selfLink'); |
654 + | expect(done$).toBeObservable(cold('(a|)', { a: true })); |
655 + | }); |
656 + | }); |
657 + | |
658 + | describe('with a matching request in the state', () => { |
659 + | beforeEach(() => { |
660 + | const state = Object.assign({}, initialState, { |
661 + | core: Object.assign({}, initialState.core, { |
662 + | 'index': { |
663 + | 'get-request/href-to-uuid': { |
664 + | 'https://rest.api/endpoint/selfLink': '5f2a0d2a-effa-4d54-bd54-5663b960f9eb' |
665 + | } |
666 + | } |
667 + | }) |
668 + | }); |
669 + | mockStore.setState(state); |
670 + | }); |
671 + | |
672 + | it('should return an Observable that emits true as soon as the request is stale', () => { |
673 + | dispatchSpy.and.callFake(() => { /* empty */ }); // don't actually set as stale |
674 + | getByUUIDSpy.and.returnValue(cold('a-b--c--d-', { // but fake the state in the cache |
675 + | a: { state: RequestEntryState.ResponsePending }, |
676 + | b: { state: RequestEntryState.Success }, |
677 + | c: { state: RequestEntryState.SuccessStale }, |
678 + | d: { state: RequestEntryState.Error }, |
679 + | })); |
680 + | const done$: Observable<boolean> = service.setStaleByHrefSubstring('https://rest.api/endpoint/selfLink'); |
681 + | expect(done$).toBeObservable(cold('-----(a|)', { a: true })); |
682 + | }); |
683 + | }); |
684 + | }); |
641 685 | }); |