mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Merge pull request #2301 from 4Science/signposting-url-fix
[CST-5729] fix issue with signposting endpoint url replace
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { SignpostingDataService } from './signposting-data.service';
|
||||
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { of } from 'rxjs';
|
||||
import { SignpostingLink } from './signposting-links.model';
|
||||
import { APP_CONFIG } from '../../../config/app-config.interface';
|
||||
|
||||
describe('SignpostingDataService', () => {
|
||||
let service: SignpostingDataService;
|
||||
let restServiceSpy: jasmine.SpyObj<DspaceRestService>;
|
||||
let halServiceSpy: jasmine.SpyObj<HALEndpointService>;
|
||||
|
||||
const mocklink = {
|
||||
href: 'http://test.org',
|
||||
rel: 'test',
|
||||
@@ -30,21 +32,25 @@ describe('SignpostingDataService', () => {
|
||||
statusCode: 500
|
||||
};
|
||||
|
||||
const environmentRest = {
|
||||
rest: {
|
||||
baseUrl: 'http://localhost:8080'
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const restSpy = jasmine.createSpyObj('DspaceRestService', ['get', 'getWithHeaders']);
|
||||
const halSpy = jasmine.createSpyObj('HALEndpointService', ['getRootHref']);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
SignpostingDataService,
|
||||
{ provide: DspaceRestService, useValue: restSpy },
|
||||
{ provide: HALEndpointService, useValue: halSpy }
|
||||
{ provide: APP_CONFIG, useValue: environmentRest },
|
||||
{ provide: DspaceRestService, useValue: restSpy }
|
||||
]
|
||||
});
|
||||
|
||||
service = TestBed.inject(SignpostingDataService);
|
||||
restServiceSpy = TestBed.inject(DspaceRestService) as jasmine.SpyObj<DspaceRestService>;
|
||||
halServiceSpy = TestBed.inject(HALEndpointService) as jasmine.SpyObj<HALEndpointService>;
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
@@ -55,8 +61,6 @@ describe('SignpostingDataService', () => {
|
||||
const uuid = '123';
|
||||
const baseUrl = 'http://localhost:8080';
|
||||
|
||||
halServiceSpy.getRootHref.and.returnValue(`${baseUrl}/api`);
|
||||
|
||||
restServiceSpy.get.and.returnValue(of(mockResponse));
|
||||
|
||||
let result: SignpostingLink[];
|
||||
@@ -70,7 +74,6 @@ describe('SignpostingDataService', () => {
|
||||
tick();
|
||||
|
||||
expect(result).toEqual(expectedResult);
|
||||
expect(halServiceSpy.getRootHref).toHaveBeenCalled();
|
||||
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
||||
}));
|
||||
|
||||
@@ -78,8 +81,6 @@ describe('SignpostingDataService', () => {
|
||||
const uuid = '123';
|
||||
const baseUrl = 'http://localhost:8080';
|
||||
|
||||
halServiceSpy.getRootHref.and.returnValue(`${baseUrl}/api`);
|
||||
|
||||
restServiceSpy.get.and.returnValue(of(mockErrResponse));
|
||||
|
||||
let result: any;
|
||||
@@ -91,7 +92,6 @@ describe('SignpostingDataService', () => {
|
||||
tick();
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(halServiceSpy.getRootHref).toHaveBeenCalled();
|
||||
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
||||
}));
|
||||
});
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { RawRestResponse } from '../dspace-rest/raw-rest-response.model';
|
||||
import { SignpostingLink } from './signposting-links.model';
|
||||
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
|
||||
|
||||
/**
|
||||
* Service responsible for handling requests related to the Signposting endpoint
|
||||
@@ -16,7 +16,7 @@ import { SignpostingLink } from './signposting-links.model';
|
||||
})
|
||||
export class SignpostingDataService {
|
||||
|
||||
constructor(private restService: DspaceRestService, protected halService: HALEndpointService) {
|
||||
constructor(@Inject(APP_CONFIG) protected appConfig: AppConfig, private restService: DspaceRestService) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ export class SignpostingDataService {
|
||||
* @param uuid
|
||||
*/
|
||||
getLinks(uuid: string): Observable<SignpostingLink[]> {
|
||||
const baseUrl = this.halService.getRootHref().replace('/api', '');
|
||||
const baseUrl = `${this.appConfig.rest.baseUrl}`;
|
||||
|
||||
return this.restService.get(`${baseUrl}/signposting/links/${uuid}`).pipe(
|
||||
catchError((err) => {
|
||||
|
Reference in New Issue
Block a user