Commits

Art Lowel authored 5ad621b27ea
fix issue where more than one api call was made on every route change
No tags

src/app/core/data/request.service.spec.ts

Modified
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('setStaleByHref', () => {
643 + const uuid = 'c574a42c-4818-47ac-bbe1-6c3cd622c81f';
644 + const href = 'https://rest.api/some/object';
645 + const freshRE: any = {
646 + request: { uuid, href },
647 + state: RequestEntryState.Success
648 + };
649 + const staleRE: any = {
650 + request: { uuid, href },
651 + state: RequestEntryState.SuccessStale
652 + };
653 +
654 + it(`should call getByHref to retrieve the RequestEntry matching the href`, () => {
655 + spyOn(service, 'getByHref').and.returnValue(observableOf(staleRE));
656 + service.setStaleByHref(href);
657 + expect(service.getByHref).toHaveBeenCalledWith(href);
658 + });
659 +
660 + it(`should dispatch a RequestStaleAction for the RequestEntry returned by getByHref`, (done: DoneFn) => {
661 + spyOn(service, 'getByHref').and.returnValue(observableOf(staleRE));
662 + spyOn(store, 'dispatch');
663 + service.setStaleByHref(href).subscribe(() => {
664 + expect(store.dispatch).toHaveBeenCalledWith(new RequestStaleAction(uuid));
665 + done();
666 + });
667 + });
668 +
669 + it(`should emit true when the request in the store is stale`, () => {
670 + spyOn(service, 'getByHref').and.returnValue(cold('a-b', {
671 + a: freshRE,
672 + b: staleRE
673 + }));
674 + const result$ = service.setStaleByHref(href);
675 + expect(result$).toBeObservable(cold('--(c|)', { c: true }));
676 + });
677 + });
641 678 });

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

Add shortcut