mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Adapt the service to a LinkedRepository result
This commit is contained in:
@@ -10,12 +10,13 @@ import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { RestResponse } from '../cache/response.models';
|
||||
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
||||
import { ItemDataService } from './item-data.service';
|
||||
import { DeleteRequest, PostRequest } from './request.models';
|
||||
import { DeleteRequest, GetRequest, PostRequest } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
|
||||
import { CoreState } from '../core-state.model';
|
||||
import { RequestEntry } from './request-entry.model';
|
||||
import { FindListOptions } from './find-list-options.model';
|
||||
import { HALEndpointServiceStub } from 'src/app/shared/testing/hal-endpoint-service.stub';
|
||||
|
||||
describe('ItemDataService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -36,13 +37,11 @@ describe('ItemDataService', () => {
|
||||
}) as RequestService;
|
||||
const rdbService = getMockRemoteDataBuildService();
|
||||
|
||||
const itemEndpoint = 'https://rest.api/core/items';
|
||||
const itemEndpoint = 'https://rest.api/core';
|
||||
|
||||
const store = {} as Store<CoreState>;
|
||||
const objectCache = {} as ObjectCacheService;
|
||||
const halEndpointService = jasmine.createSpyObj('halService', {
|
||||
getEndpoint: observableOf(itemEndpoint)
|
||||
});
|
||||
const halEndpointService: any = new HALEndpointServiceStub(itemEndpoint);
|
||||
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||
findByHref: {}
|
||||
});
|
||||
@@ -185,6 +184,33 @@ describe('ItemDataService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAccessStatusEndpoint', () => {
|
||||
beforeEach(() => {
|
||||
service = initTestService();
|
||||
});
|
||||
it('should retrieve the access status endpoint', () => {
|
||||
const itemId = '3de6ea60-ec39-419b-ae6f-065930ac1429';
|
||||
const result = service.getAccessStatusEndpoint(itemId);
|
||||
result.subscribe(((value) => {
|
||||
expect(value).toEqual(`${itemEndpoint}/items/${itemId}/accessStatus`);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAccessStatus', () => {
|
||||
beforeEach(() => {
|
||||
service = initTestService();
|
||||
});
|
||||
it('should send a GET request', (done) => {
|
||||
const itemId = '3de6ea60-ec39-419b-ae6f-065930ac1429';
|
||||
const result = service.getAccessStatus(itemId);
|
||||
result.subscribe(() => {
|
||||
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when cache is invalidated', () => {
|
||||
beforeEach(() => {
|
||||
service = initTestService();
|
||||
|
@@ -292,25 +292,31 @@ export class ItemDataService extends DataService<Item> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the endpoint for an item's access status
|
||||
* @param itemId
|
||||
*/
|
||||
public getAccessStatusEndpoint(itemId: string): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
switchMap((url: string) => this.halService.getEndpoint('accessStatus', `${url}/${itemId}`))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the the access status
|
||||
* @param itemId
|
||||
*/
|
||||
public getAccessStatus(itemId: string): Observable<RemoteData<AccessStatusObject>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const href$ = this.halService.getEndpoint('accessStatus').pipe(
|
||||
map((href) => href.replace('{?uuid}', `?uuid=${itemId}`))
|
||||
);
|
||||
const hrefObs = this.getAccessStatusEndpoint(itemId);
|
||||
|
||||
href$.pipe(
|
||||
find((href: string) => hasValue(href)),
|
||||
map((href: string) => {
|
||||
const request = new GetRequest(requestId, href);
|
||||
this.requestService.send(request);
|
||||
})
|
||||
).subscribe();
|
||||
hrefObs.pipe(
|
||||
take(1)
|
||||
).subscribe((href) => {
|
||||
const request = new GetRequest(this.requestService.generateRequestId(), href);
|
||||
this.requestService.send(request);
|
||||
});
|
||||
|
||||
return this.rdbService.buildFromRequestUUID(requestId);
|
||||
return this.rdbService.buildSingle<AccessStatusObject>(hrefObs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -151,7 +151,7 @@ describe('VersionHistoryDataService', () => {
|
||||
describe('when getVersionsEndpoint is called', () => {
|
||||
it('should return the correct value', () => {
|
||||
service.getVersionsEndpoint(versionHistoryId).subscribe((res) => {
|
||||
expect(res).toBe(url + '/versions');
|
||||
expect(res).toBe(url + '/versionhistories/version-history-id/versions');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { autoserialize } from 'cerialize';
|
||||
import { autoserialize, deserialize } from 'cerialize';
|
||||
import { typedObject } from 'src/app/core/cache/builders/build-decorators';
|
||||
import { CacheableObject } from 'src/app/core/cache/object-cache.reducer';
|
||||
import { HALLink } from 'src/app/core/shared/hal-link.model';
|
||||
import { ResourceType } from 'src/app/core/shared/resource-type';
|
||||
import { excludeFromEquals } from 'src/app/core/utilities/equals.decorators';
|
||||
import { ACCESS_STATUS } from './access-status.resource-type';
|
||||
|
||||
@typedObject
|
||||
export class AccessStatusObject {
|
||||
export class AccessStatusObject implements CacheableObject {
|
||||
static type = ACCESS_STATUS;
|
||||
|
||||
/**
|
||||
@@ -20,4 +22,12 @@ export class AccessStatusObject {
|
||||
*/
|
||||
@autoserialize
|
||||
status: string;
|
||||
|
||||
/**
|
||||
* The {@link HALLink}s for this AccessStatusObject
|
||||
*/
|
||||
@deserialize
|
||||
_links: {
|
||||
self: HALLink;
|
||||
};
|
||||
}
|
||||
|
@@ -1,9 +1,13 @@
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { hasValue } from '../empty.util';
|
||||
|
||||
export class HALEndpointServiceStub {
|
||||
|
||||
constructor(private url: string) {}
|
||||
getEndpoint(path: string) {
|
||||
getEndpoint(path: string, startHref?: string) {
|
||||
if (hasValue(startHref)) {
|
||||
return observableOf(startHref + '/' + path);
|
||||
}
|
||||
return observableOf(this.url + '/' + path);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user