11import { fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2+
3+ import { of } from 'rxjs' ;
4+
25import { SignpostingDataService } from './signposting-data.service' ;
36import { DspaceRestService } from '../dspace-rest/dspace-rest.service' ;
4- import { HALEndpointService } from '../shared/hal-endpoint.service' ;
5- import { of } from 'rxjs' ;
67import { SignpostingLink } from './signposting-links.model' ;
8+ import { APP_CONFIG } from '../../../config/app-config.interface' ;
79
810describe ( 'SignpostingDataService' , ( ) => {
911 let service : SignpostingDataService ;
1012 let restServiceSpy : jasmine . SpyObj < DspaceRestService > ;
11- let halServiceSpy : jasmine . SpyObj < HALEndpointService > ;
13+
1214 const mocklink = {
1315 href : 'http://test.org' ,
1416 rel : 'test' ,
@@ -30,21 +32,25 @@ describe('SignpostingDataService', () => {
3032 statusCode : 500
3133 } ;
3234
35+ const environmentRest = {
36+ rest : {
37+ baseUrl : 'http://localhost:8080'
38+ }
39+ } ;
40+
3341 beforeEach ( ( ) => {
3442 const restSpy = jasmine . createSpyObj ( 'DspaceRestService' , [ 'get' , 'getWithHeaders' ] ) ;
35- const halSpy = jasmine . createSpyObj ( 'HALEndpointService' , [ 'getRootHref' ] ) ;
3643
3744 TestBed . configureTestingModule ( {
3845 providers : [
3946 SignpostingDataService ,
40- { provide : DspaceRestService , useValue : restSpy } ,
41- { provide : HALEndpointService , useValue : halSpy }
47+ { provide : APP_CONFIG , useValue : environmentRest } ,
48+ { provide : DspaceRestService , useValue : restSpy }
4249 ]
4350 } ) ;
4451
4552 service = TestBed . inject ( SignpostingDataService ) ;
4653 restServiceSpy = TestBed . inject ( DspaceRestService ) as jasmine . SpyObj < DspaceRestService > ;
47- halServiceSpy = TestBed . inject ( HALEndpointService ) as jasmine . SpyObj < HALEndpointService > ;
4854 } ) ;
4955
5056 it ( 'should be created' , ( ) => {
@@ -55,8 +61,6 @@ describe('SignpostingDataService', () => {
5561 const uuid = '123' ;
5662 const baseUrl = 'http://localhost:8080' ;
5763
58- halServiceSpy . getRootHref . and . returnValue ( `${ baseUrl } /api` ) ;
59-
6064 restServiceSpy . get . and . returnValue ( of ( mockResponse ) ) ;
6165
6266 let result : SignpostingLink [ ] ;
@@ -70,16 +74,13 @@ describe('SignpostingDataService', () => {
7074 tick ( ) ;
7175
7276 expect ( result ) . toEqual ( expectedResult ) ;
73- expect ( halServiceSpy . getRootHref ) . toHaveBeenCalled ( ) ;
7477 expect ( restServiceSpy . get ) . toHaveBeenCalledWith ( `${ baseUrl } /signposting/links/${ uuid } ` ) ;
7578 } ) ) ;
7679
7780 it ( 'should handle error and return an empty array' , fakeAsync ( ( ) => {
7881 const uuid = '123' ;
7982 const baseUrl = 'http://localhost:8080' ;
8083
81- halServiceSpy . getRootHref . and . returnValue ( `${ baseUrl } /api` ) ;
82-
8384 restServiceSpy . get . and . returnValue ( of ( mockErrResponse ) ) ;
8485
8586 let result : any ;
@@ -91,7 +92,6 @@ describe('SignpostingDataService', () => {
9192 tick ( ) ;
9293
9394 expect ( result ) . toEqual ( [ ] ) ;
94- expect ( halServiceSpy . getRootHref ) . toHaveBeenCalled ( ) ;
9595 expect ( restServiceSpy . get ) . toHaveBeenCalledWith ( `${ baseUrl } /signposting/links/${ uuid } ` ) ;
9696 } ) ) ;
9797} ) ;
0 commit comments