Commits
Corrado Lombardi authored c40f31279f8
10 10 | import { CoreState } from '../core.reducers'; |
11 11 | import { Community } from '../shared/community.model'; |
12 12 | import { HALEndpointService } from '../shared/hal-endpoint.service'; |
13 13 | import { Item } from '../shared/item.model'; |
14 14 | import { ComColDataService } from './comcol-data.service'; |
15 15 | import { CommunityDataService } from './community-data.service'; |
16 16 | import { DSOChangeAnalyzer } from './dso-change-analyzer.service'; |
17 17 | import { FindByIDRequest, FindListOptions } from './request.models'; |
18 18 | import { RequestEntry } from './request.reducer'; |
19 19 | import { RequestService } from './request.service'; |
20 + | import {createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$} from '../../shared/remote-data.utils'; |
20 21 | |
21 22 | const LINK_NAME = 'test'; |
22 23 | |
23 24 | class TestService extends ComColDataService<any> { |
24 25 | |
25 26 | constructor( |
26 27 | protected requestService: RequestService, |
27 28 | protected rdbService: RemoteDataBuildService, |
28 29 | protected store: Store<CoreState>, |
29 30 | protected cds: CommunityDataService, |
44 45 | } |
45 46 | |
46 47 | describe('ComColDataService', () => { |
47 48 | let scheduler: TestScheduler; |
48 49 | let service: TestService; |
49 50 | let requestService: RequestService; |
50 51 | let cds: CommunityDataService; |
51 52 | let objectCache: ObjectCacheService; |
52 53 | let halService: any = {}; |
53 54 | |
54 - | const rdbService = {} as RemoteDataBuildService; |
55 + | const rdbService = { |
56 + | buildSingle : () => null |
57 + | } as any; |
55 58 | const store = {} as Store<CoreState>; |
56 59 | const notificationsService = {} as NotificationsService; |
57 60 | const http = {} as HttpClient; |
58 61 | const comparator = {} as any; |
59 62 | |
60 63 | const scopeID = 'd9d30c0c-69b7-4369-8397-ca67c888974d'; |
61 64 | const options = Object.assign(new FindListOptions(), { |
62 65 | scopeID: scopeID |
63 66 | }); |
64 67 | const getRequestEntry$ = (successful: boolean) => { |
171 174 | }); |
172 175 | |
173 176 | it('should throw an error', () => { |
174 177 | const result = service.getBrowseEndpoint(options); |
175 178 | const expected = cold('--#-', undefined, new Error(`The Community with scope ${scopeID} couldn't be retrieved`)); |
176 179 | |
177 180 | expect(result).toBeObservable(expected); |
178 181 | }); |
179 182 | }); |
180 183 | |
184 + | describe('cache refresh', () => { |
185 + | let communityWithoutParentHref; |
186 + | let data; |
187 + | |
188 + | beforeEach(() => { |
189 + | scheduler = getTestScheduler(); |
190 + | halService = { |
191 + | getEndpoint: (linkPath) => 'https://rest.api/core/' + linkPath |
192 + | }; |
193 + | service = initTestService(); |
194 + | |
195 + | }) |
196 + | describe('cache refreshed top level community', () => { |
197 + | beforeEach(() => { |
198 + | spyOn(rdbService, 'buildSingle').and.returnValue(createNoContentRemoteDataObject$()); |
199 + | data = { |
200 + | dso: Object.assign(new Community(), { |
201 + | metadata: [{ |
202 + | key: 'dc.title', |
203 + | value: 'top level community' |
204 + | }] |
205 + | }), |
206 + | _links: { |
207 + | parentCommunity: { |
208 + | href: 'topLevel/parentCommunity' |
209 + | } |
210 + | } |
211 + | }; |
212 + | communityWithoutParentHref = { |
213 + | dso: Object.assign(new Community(), { |
214 + | metadata: [{ |
215 + | key: 'dc.title', |
216 + | value: 'top level community' |
217 + | }] |
218 + | }), |
219 + | _links: {} |
220 + | }; |
221 + | }); |
222 + | it('top level community cache refreshed', () => { |
223 + | scheduler.schedule(() => (service as any).refreshCache(data)); |
224 + | scheduler.flush(); |
225 + | expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('https://rest.api/core/communities/search/top'); |
226 + | }); |
227 + | it('top level community without parent link, cache not refreshed', () => { |
228 + | scheduler.schedule(() => (service as any).refreshCache(communityWithoutParentHref)); |
229 + | scheduler.flush(); |
230 + | expect(requestService.removeByHrefSubstring).not.toHaveBeenCalled(); |
231 + | }); |
232 + | }); |
233 + | |
234 + | describe('cache refreshed child community', () => { |
235 + | beforeEach(() => { |
236 + | const parentCommunity = Object.assign(new Community(), { |
237 + | uuid: 'a20da287-e174-466a-9926-f66as300d399', |
238 + | id: 'a20da287-e174-466a-9926-f66as300d399', |
239 + | metadata: [{ |
240 + | key: 'dc.title', |
241 + | value: 'parent community' |
242 + | }], |
243 + | _links: {} |
244 + | }); |
245 + | spyOn(rdbService, 'buildSingle').and.returnValue(createSuccessfulRemoteDataObject$(parentCommunity)); |
246 + | data = { |
247 + | dso: Object.assign(new Community(), { |
248 + | metadata: [{ |
249 + | key: 'dc.title', |
250 + | value: 'child community' |
251 + | }] |
252 + | }), |
253 + | _links: { |
254 + | parentCommunity: { |
255 + | href: 'child/parentCommunity' |
256 + | } |
257 + | } |
258 + | }; |
259 + | }); |
260 + | it('child level community cache refreshed', () => { |
261 + | scheduler.schedule(() => (service as any).refreshCache(data)); |
262 + | scheduler.flush(); |
263 + | expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('a20da287-e174-466a-9926-f66as300d399'); |
264 + | }); |
265 + | }); |
266 + | }); |
267 + | |
181 268 | }); |
182 269 | |
183 270 | }); |