File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 [ ] > {
You can’t perform that action at this time.
0 commit comments