mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge remote-tracking branch 'origin/main' into CST-5307
# Conflicts: # src/app/core/core.module.ts # src/app/shared/shared.module.ts
This commit is contained in:
81
src/app/core/data/access-status-data.service.spec.ts
Normal file
81
src/app/core/data/access-status-data.service.spec.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { RequestService } from './request.service';
|
||||
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
|
||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||
import { fakeAsync, tick } from '@angular/core/testing';
|
||||
import { GetRequest } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { hasNoValue } from '../../shared/empty.util';
|
||||
import { AccessStatusDataService } from './access-status-data.service';
|
||||
import { Item } from '../shared/item.model';
|
||||
|
||||
const url = 'fake-url';
|
||||
|
||||
describe('AccessStatusDataService', () => {
|
||||
let service: AccessStatusDataService;
|
||||
let requestService: RequestService;
|
||||
let notificationsService: any;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: any;
|
||||
|
||||
const itemId = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
id: itemId,
|
||||
name: 'test-item',
|
||||
_links: {
|
||||
accessStatus: {
|
||||
href: `https://rest.api/items/${itemId}/accessStatus`
|
||||
},
|
||||
self: {
|
||||
href: `https://rest.api/items/${itemId}`
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe('when the requests are successful', () => {
|
||||
beforeEach(() => {
|
||||
createService();
|
||||
});
|
||||
|
||||
describe('when calling findAccessStatusFor', () => {
|
||||
let contentSource$;
|
||||
|
||||
beforeEach(() => {
|
||||
contentSource$ = service.findAccessStatusFor(mockItem);
|
||||
});
|
||||
|
||||
it('should send a new GetRequest', fakeAsync(() => {
|
||||
contentSource$.subscribe();
|
||||
tick();
|
||||
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Create an AccessStatusDataService used for testing
|
||||
* @param reponse$ Supply a RemoteData to be returned by the REST API (optional)
|
||||
*/
|
||||
function createService(reponse$?: Observable<RemoteData<any>>) {
|
||||
requestService = getMockRequestService();
|
||||
let buildResponse$ = reponse$;
|
||||
if (hasNoValue(reponse$)) {
|
||||
buildResponse$ = createSuccessfulRemoteDataObject$({});
|
||||
}
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildFromRequestUUID: buildResponse$,
|
||||
buildSingle: buildResponse$
|
||||
});
|
||||
objectCache = jasmine.createSpyObj('objectCache', {
|
||||
remove: jasmine.createSpy('remove')
|
||||
});
|
||||
halService = new HALEndpointServiceStub(url);
|
||||
notificationsService = new NotificationsServiceStub();
|
||||
service = new AccessStatusDataService(null, halService, null, notificationsService, objectCache, rdbService, requestService, null);
|
||||
}
|
||||
});
|
45
src/app/core/data/access-status-data.service.ts
Normal file
45
src/app/core/data/access-status-data.service.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { dataService } from '../cache/builders/build-decorators';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { DataService } from './data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||
import { CoreState } from '../core-state.model';
|
||||
import { AccessStatusObject } from 'src/app/shared/object-list/access-status-badge/access-status.model';
|
||||
import { ACCESS_STATUS } from 'src/app/shared/object-list/access-status-badge/access-status.resource-type';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { Item } from '../shared/item.model';
|
||||
|
||||
@Injectable()
|
||||
@dataService(ACCESS_STATUS)
|
||||
export class AccessStatusDataService extends DataService<AccessStatusObject> {
|
||||
|
||||
protected linkPath = 'accessStatus';
|
||||
|
||||
constructor(
|
||||
protected comparator: DefaultChangeAnalyzer<AccessStatusObject>,
|
||||
protected halService: HALEndpointService,
|
||||
protected http: HttpClient,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected requestService: RequestService,
|
||||
protected store: Store<CoreState>,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given item
|
||||
* @param item Item we want the access status of
|
||||
*/
|
||||
findAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
|
||||
return this.findByHref(item._links.accessStatus.href);
|
||||
}
|
||||
}
|
@@ -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: {}
|
||||
});
|
||||
|
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user