Skip to content

Commit 7c13db2

Browse files
committed
94273: Invalidate object on successful patch
1 parent d40f163 commit 7c13db2

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,12 @@ describe('DataService', () => {
351351

352352
describe('patch', () => {
353353
const dso = {
354-
uuid: 'dso-uuid'
354+
uuid: 'dso-uuid',
355+
_links: {
356+
self: {
357+
href: 'dso-href',
358+
}
359+
}
355360
};
356361
const operations = [
357362
Object.assign({
@@ -361,12 +366,23 @@ describe('DataService', () => {
361366
}) as Operation
362367
];
363368

364-
beforeEach(() => {
369+
it('should send a PatchRequest', () => {
365370
service.patch(dso, operations);
371+
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(PatchRequest));
366372
});
367373

368-
it('should send a PatchRequest', () => {
369-
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(PatchRequest));
374+
it('should invalidate the cached object if successfully patched', () => {
375+
spyOn(rdbService, 'buildFromRequestUUIDAndAwait');
376+
spyOn(service, 'invalidateByHref');
377+
378+
service.patch(dso, operations);
379+
380+
expect(rdbService.buildFromRequestUUIDAndAwait).toHaveBeenCalled();
381+
expect((rdbService.buildFromRequestUUIDAndAwait as jasmine.Spy).calls.argsFor(0)[0]).toBe(requestService.generateRequestId());
382+
const callback = (rdbService.buildFromRequestUUIDAndAwait as jasmine.Spy).calls.argsFor(0)[1];
383+
callback();
384+
385+
expect(service.invalidateByHref).toHaveBeenCalledWith('dso-href');
370386
});
371387
});
372388

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
484484
this.requestService.send(request);
485485
});
486486

487-
return this.rdbService.buildFromRequestUUID(requestId);
487+
return this.rdbService.buildFromRequestUUIDAndAwait(requestId, () => this.invalidateByHref(object._links.self.href));
488488
}
489489

490490
createPatchFromCache(object: T): Observable<Operation[]> {

0 commit comments

Comments
 (0)