Skip to content

Commit 5d6edad

Browse files
committed
[CST-5729] turn to use app config baseurl
1 parent e85f9f2 commit 5d6edad

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
2+
3+
import { of } from 'rxjs';
4+
25
import { SignpostingDataService } from './signposting-data.service';
36
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
4-
import { HALEndpointService } from '../shared/hal-endpoint.service';
5-
import { of } from 'rxjs';
67
import { SignpostingLink } from './signposting-links.model';
8+
import { APP_CONFIG } from '../../../config/app-config.interface';
79

810
describe('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
});

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Injectable } from '@angular/core';
1+
import { Inject, Injectable } from '@angular/core';
22

33
import { catchError, map } from 'rxjs/operators';
44
import { Observable, of as observableOf } from 'rxjs';
55

66
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
7-
import { HALEndpointService } from '../shared/hal-endpoint.service';
87
import { RawRestResponse } from '../dspace-rest/raw-rest-response.model';
98
import { SignpostingLink } from './signposting-links.model';
9+
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
1010

1111
/**
1212
* Service responsible for handling requests related to the Signposting endpoint
@@ -16,7 +16,7 @@ import { SignpostingLink } from './signposting-links.model';
1616
})
1717
export class SignpostingDataService {
1818

19-
constructor(private restService: DspaceRestService, protected halService: HALEndpointService) {
19+
constructor(@Inject(APP_CONFIG) protected appConfig: AppConfig, private restService: DspaceRestService) {
2020
}
2121

2222
/**
@@ -25,8 +25,7 @@ export class SignpostingDataService {
2525
* @param uuid
2626
*/
2727
getLinks(uuid: string): Observable<SignpostingLink[]> {
28-
const regex = /\/api$/gm;
29-
const baseUrl = this.halService.getRootHref().replace(regex, '');
28+
const baseUrl = `${this.appConfig.rest.baseUrl}`;
3029

3130
return this.restService.get(`${baseUrl}/signposting/links/${uuid}`).pipe(
3231
catchError((err) => {

0 commit comments

Comments
 (0)