1+ import { TestBed } from '@angular/core/testing' ;
12import { BitstreamDataService } from './bitstream-data.service' ;
23import { ObjectCacheService } from '../cache/object-cache.service' ;
34import { RequestService } from './request.service' ;
45import { Bitstream } from '../shared/bitstream.model' ;
56import { HALEndpointService } from '../shared/hal-endpoint.service' ;
67import { BitstreamFormatDataService } from './bitstream-format-data.service' ;
7- import { of as observableOf } from 'rxjs' ;
8+ import { Observable , of as observableOf } from 'rxjs' ;
89import { BitstreamFormat } from '../shared/bitstream-format.model' ;
910import { BitstreamFormatSupportLevel } from '../shared/bitstream-format-support-level' ;
10- import { PutRequest } from './request.models' ;
11+ import { PatchRequest , PutRequest } from './request.models' ;
1112import { getMockRequestService } from '../../shared/mocks/request.service.mock' ;
1213import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub' ;
1314import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service' ;
1415import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock' ;
1516import { testSearchDataImplementation } from './base/search-data.spec' ;
1617import { testPatchDataImplementation } from './base/patch-data.spec' ;
1718import { testDeleteDataImplementation } from './base/delete-data.spec' ;
19+ import { DSOChangeAnalyzer } from './dso-change-analyzer.service' ;
20+ import { NotificationsService } from '../../shared/notifications/notifications.service' ;
21+ import objectContaining = jasmine . objectContaining ;
22+ import { RemoteData } from './remote-data' ;
23+ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model' ;
1824
1925describe ( 'BitstreamDataService' , ( ) => {
2026 let service : BitstreamDataService ;
@@ -25,10 +31,18 @@ describe('BitstreamDataService', () => {
2531 let rdbService : RemoteDataBuildService ;
2632 const bitstreamFormatHref = 'rest-api/bitstreamformats' ;
2733
28- const bitstream = Object . assign ( new Bitstream ( ) , {
29- uuid : 'fake-bitstream' ,
34+ const bitstream1 = Object . assign ( new Bitstream ( ) , {
35+ id : 'fake-bitstream1' ,
36+ uuid : 'fake-bitstream1' ,
3037 _links : {
31- self : { href : 'fake-bitstream-self' }
38+ self : { href : 'fake-bitstream1-self' }
39+ }
40+ } ) ;
41+ const bitstream2 = Object . assign ( new Bitstream ( ) , {
42+ id : 'fake-bitstream2' ,
43+ uuid : 'fake-bitstream2' ,
44+ _links : {
45+ self : { href : 'fake-bitstream2-self' }
3246 }
3347 } ) ;
3448 const format = Object . assign ( new BitstreamFormat ( ) , {
@@ -50,7 +64,18 @@ describe('BitstreamDataService', () => {
5064 } ) ;
5165 rdbService = getMockRemoteDataBuildService ( ) ;
5266
53- service = new BitstreamDataService ( requestService , rdbService , objectCache , halService , null , bitstreamFormatService , null , null ) ;
67+ TestBed . configureTestingModule ( {
68+ providers : [
69+ { provide : ObjectCacheService , useValue : objectCache } ,
70+ { provide : RequestService , useValue : requestService } ,
71+ { provide : HALEndpointService , useValue : halService } ,
72+ { provide : BitstreamFormatDataService , useValue : bitstreamFormatService } ,
73+ { provide : RemoteDataBuildService , useValue : rdbService } ,
74+ { provide : DSOChangeAnalyzer , useValue : { } } ,
75+ { provide : NotificationsService , useValue : { } } ,
76+ ] ,
77+ } ) ;
78+ service = TestBed . inject ( BitstreamDataService ) ;
5479 } ) ;
5580
5681 describe ( 'composition' , ( ) => {
@@ -62,11 +87,49 @@ describe('BitstreamDataService', () => {
6287
6388 describe ( 'when updating the bitstream\'s format' , ( ) => {
6489 beforeEach ( ( ) => {
65- service . updateFormat ( bitstream , format ) ;
90+ service . updateFormat ( bitstream1 , format ) ;
6691 } ) ;
6792
6893 it ( 'should send a put request' , ( ) => {
6994 expect ( requestService . send ) . toHaveBeenCalledWith ( jasmine . any ( PutRequest ) ) ;
7095 } ) ;
7196 } ) ;
97+
98+ describe ( 'removeMultiple' , ( ) => {
99+ function mockBuildFromRequestUUIDAndAwait ( requestUUID$ : string | Observable < string > , callback : ( rd ?: RemoteData < any > ) => Observable < unknown > , ..._linksToFollow : FollowLinkConfig < any > [ ] ) : Observable < RemoteData < any > > {
100+ callback ( ) ;
101+ return ;
102+ }
103+
104+ beforeEach ( ( ) => {
105+ spyOn ( service , 'invalidateByHref' ) ;
106+ spyOn ( rdbService , 'buildFromRequestUUIDAndAwait' ) . and . callFake ( ( requestUUID$ : string | Observable < string > , callback : ( rd ?: RemoteData < any > ) => Observable < unknown > , ...linksToFollow : FollowLinkConfig < any > [ ] ) => mockBuildFromRequestUUIDAndAwait ( requestUUID$ , callback , ...linksToFollow ) ) ;
107+ } ) ;
108+
109+ it ( 'should be able to 1 bitstream' , ( ) => {
110+ service . removeMultiple ( [ bitstream1 ] ) ;
111+
112+ expect ( requestService . send ) . toHaveBeenCalledWith ( objectContaining ( {
113+ href : `${ url } /bitstreams` ,
114+ body : [
115+ { op : 'remove' , path : '/bitstreams/fake-bitstream1' } ,
116+ ] ,
117+ } as PatchRequest ) ) ;
118+ expect ( service . invalidateByHref ) . toHaveBeenCalledWith ( 'fake-bitstream1-self' ) ;
119+ } ) ;
120+
121+ it ( 'should be able to delete multiple bitstreams' , ( ) => {
122+ service . removeMultiple ( [ bitstream1 , bitstream2 ] ) ;
123+
124+ expect ( requestService . send ) . toHaveBeenCalledWith ( objectContaining ( {
125+ href : `${ url } /bitstreams` ,
126+ body : [
127+ { op : 'remove' , path : '/bitstreams/fake-bitstream1' } ,
128+ { op : 'remove' , path : '/bitstreams/fake-bitstream2' } ,
129+ ] ,
130+ } as PatchRequest ) ) ;
131+ expect ( service . invalidateByHref ) . toHaveBeenCalledWith ( 'fake-bitstream1-self' ) ;
132+ expect ( service . invalidateByHref ) . toHaveBeenCalledWith ( 'fake-bitstream2-self' ) ;
133+ } ) ;
134+ } ) ;
72135} ) ;
0 commit comments