Commits

Yura Bondarenko authored 0fe199a97c0
78849: Fix unit test
No tags

src/app/core/data/eperson-registration.service.spec.ts

Modified
1 1 import { RequestService } from './request.service';
2 2 import { EpersonRegistrationService } from './eperson-registration.service';
3 3 import { RestResponse } from '../cache/response.models';
4 -import { RequestEntry, RequestEntryState } from './request.reducer';
4 +import { RequestEntry } from './request.reducer';
5 5 import { cold } from 'jasmine-marbles';
6 6 import { PostRequest } from './request.models';
7 7 import { Registration } from '../shared/registration.model';
8 8 import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
9 -import { createPendingRemoteDataObject, createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
9 +import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
10 10 import { of as observableOf } from 'rxjs/internal/observable/of';
11 11 import { TestScheduler } from 'rxjs/testing';
12 12
13 -fdescribe('EpersonRegistrationService', () => {
13 +describe('EpersonRegistrationService', () => {
14 14 let testScheduler;
15 15
16 16 let service: EpersonRegistrationService;
17 17 let requestService: RequestService;
18 18
19 19 let halService: any;
20 20 let rdbService: any;
21 21
22 22 const registration = new Registration();
23 23 registration.email = 'test@mail.org';
89 89 it('should return a registration corresponding to the provided token', () => {
90 90 const expected = service.searchByToken('test-token');
91 91
92 92 expect(expected).toBeObservable(cold('(a|)', {
93 93 a: Object.assign(new Registration(), {
94 94 email: registrationWithUser.email,
95 95 token: 'test-token',
96 96 user: registrationWithUser.user
97 97 })
98 98 }));
99 -
100 99 });
101 100
102 - it('should return the original registration if it was already cached', () => {
101 + it('should use cached responses and /registrations/search/findByToken?', () => {
103 102 testScheduler.run(({ cold, expectObservable }) => {
104 - rdbService.buildSingle.and.returnValue(cold('a-b-c', {
105 - a: createSuccessfulRemoteDataObject(registrationWithUser),
106 - b: createPendingRemoteDataObject(),
107 - c: createSuccessfulRemoteDataObject(new Registration())
108 - }));
109 -
110 - expectObservable(
111 - service.searchByToken('test-token')
112 - ).toBe('(a|)', {
113 - a: Object.assign(new Registration(), {
114 - email: registrationWithUser.email,
115 - token: 'test-token',
116 - user: registrationWithUser.user
117 - })
103 + rdbService.buildSingle.and.returnValue(cold('a', { a: rd }));
104 +
105 + service.searchByToken('test-token');
106 +
107 + expect(requestService.send).toHaveBeenCalledWith(
108 + jasmine.objectContaining({
109 + uuid: 'request-id', method: 'GET',
110 + href: 'rest-url/registrations/search/findByToken?token=test-token',
111 + }), true
112 + );
113 + expectObservable(rdbService.buildSingle.calls.argsFor(0)[0]).toBe('(a|)', {
114 + a: 'rest-url/registrations/search/findByToken?token=test-token'
118 115 });
119 116 });
120 117 });
121 118
122 - it('should re-request the registration if it was already cached but stale', () => {
123 - const rdCachedStale = createSuccessfulRemoteDataObject(new Registration());
124 - rdCachedStale.state = RequestEntryState.SuccessStale;
125 -
126 - testScheduler.run(({ cold, expectObservable }) => {
127 - rdbService.buildSingle.and.returnValue(cold('a-b-c', {
128 - a: rdCachedStale,
129 - b: createPendingRemoteDataObject(),
130 - c: createSuccessfulRemoteDataObject(registrationWithUser),
131 - }));
132 -
133 - expectObservable(
134 - service.searchByToken('test-token')
135 - ).toBe('----(c|)', {
136 - c: Object.assign(new Registration(), {
137 - email: registrationWithUser.email,
138 - token: 'test-token',
139 - user: registrationWithUser.user
140 - })
141 - });
142 - });
143 - });
144 119 });
145 120
146 121 });

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

Add shortcut