mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +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 { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
import { SignpostingDataService } from './signposting-data.service';
|
import { SignpostingDataService } from './signposting-data.service';
|
||||||
import { DspaceRestService } from '../dspace-rest/dspace-rest.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 { SignpostingLink } from './signposting-links.model';
|
||||||
|
import { APP_CONFIG } from '../../../config/app-config.interface';
|
||||||
|
|
||||||
describe('SignpostingDataService', () => {
|
describe('SignpostingDataService', () => {
|
||||||
let service: SignpostingDataService;
|
let service: SignpostingDataService;
|
||||||
let restServiceSpy: jasmine.SpyObj<DspaceRestService>;
|
let restServiceSpy: jasmine.SpyObj<DspaceRestService>;
|
||||||
let halServiceSpy: jasmine.SpyObj<HALEndpointService>;
|
|
||||||
const mocklink = {
|
const mocklink = {
|
||||||
href: 'http://test.org',
|
href: 'http://test.org',
|
||||||
rel: 'test',
|
rel: 'test',
|
||||||
@@ -30,21 +32,25 @@ describe('SignpostingDataService', () => {
|
|||||||
statusCode: 500
|
statusCode: 500
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const environmentRest = {
|
||||||
|
rest: {
|
||||||
|
baseUrl: 'http://localhost:8080'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const restSpy = jasmine.createSpyObj('DspaceRestService', ['get', 'getWithHeaders']);
|
const restSpy = jasmine.createSpyObj('DspaceRestService', ['get', 'getWithHeaders']);
|
||||||
const halSpy = jasmine.createSpyObj('HALEndpointService', ['getRootHref']);
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
SignpostingDataService,
|
SignpostingDataService,
|
||||||
{ provide: DspaceRestService, useValue: restSpy },
|
{ provide: APP_CONFIG, useValue: environmentRest },
|
||||||
{ provide: HALEndpointService, useValue: halSpy }
|
{ provide: DspaceRestService, useValue: restSpy }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
service = TestBed.inject(SignpostingDataService);
|
service = TestBed.inject(SignpostingDataService);
|
||||||
restServiceSpy = TestBed.inject(DspaceRestService) as jasmine.SpyObj<DspaceRestService>;
|
restServiceSpy = TestBed.inject(DspaceRestService) as jasmine.SpyObj<DspaceRestService>;
|
||||||
halServiceSpy = TestBed.inject(HALEndpointService) as jasmine.SpyObj<HALEndpointService>;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
it('should be created', () => {
|
||||||
@@ -55,8 +61,6 @@ describe('SignpostingDataService', () => {
|
|||||||
const uuid = '123';
|
const uuid = '123';
|
||||||
const baseUrl = 'http://localhost:8080';
|
const baseUrl = 'http://localhost:8080';
|
||||||
|
|
||||||
halServiceSpy.getRootHref.and.returnValue(`${baseUrl}/api`);
|
|
||||||
|
|
||||||
restServiceSpy.get.and.returnValue(of(mockResponse));
|
restServiceSpy.get.and.returnValue(of(mockResponse));
|
||||||
|
|
||||||
let result: SignpostingLink[];
|
let result: SignpostingLink[];
|
||||||
@@ -70,7 +74,6 @@ describe('SignpostingDataService', () => {
|
|||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(result).toEqual(expectedResult);
|
expect(result).toEqual(expectedResult);
|
||||||
expect(halServiceSpy.getRootHref).toHaveBeenCalled();
|
|
||||||
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -78,8 +81,6 @@ describe('SignpostingDataService', () => {
|
|||||||
const uuid = '123';
|
const uuid = '123';
|
||||||
const baseUrl = 'http://localhost:8080';
|
const baseUrl = 'http://localhost:8080';
|
||||||
|
|
||||||
halServiceSpy.getRootHref.and.returnValue(`${baseUrl}/api`);
|
|
||||||
|
|
||||||
restServiceSpy.get.and.returnValue(of(mockErrResponse));
|
restServiceSpy.get.and.returnValue(of(mockErrResponse));
|
||||||
|
|
||||||
let result: any;
|
let result: any;
|
||||||
@@ -91,7 +92,6 @@ describe('SignpostingDataService', () => {
|
|||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
expect(halServiceSpy.getRootHref).toHaveBeenCalled();
|
|
||||||
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
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 { catchError, map } from 'rxjs/operators';
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
|
||||||
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
|
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 { RawRestResponse } from '../dspace-rest/raw-rest-response.model';
|
||||||
import { SignpostingLink } from './signposting-links.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
|
* Service responsible for handling requests related to the Signposting endpoint
|
||||||
@@ -16,7 +16,7 @@ import { SignpostingLink } from './signposting-links.model';
|
|||||||
})
|
})
|
||||||
export class SignpostingDataService {
|
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
|
* @param uuid
|
||||||
*/
|
*/
|
||||||
getLinks(uuid: string): Observable<SignpostingLink[]> {
|
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(
|
return this.restService.get(`${baseUrl}/signposting/links/${uuid}`).pipe(
|
||||||
catchError((err) => {
|
catchError((err) => {
|
||||||
|
Reference in New Issue
Block a user