mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
63469: JSDocs + tests
This commit is contained in:
@@ -227,10 +227,8 @@ describe('ItemRelationshipsComponent', () => {
|
||||
comp.submit();
|
||||
});
|
||||
|
||||
it('it should delete the correct relationship and de-cache the current item', () => {
|
||||
it('it should delete the correct relationship', () => {
|
||||
expect(relationshipService.deleteRelationship).toHaveBeenCalledWith(relationships[1].uuid);
|
||||
expect(objectCache.remove).toHaveBeenCalledWith(item.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(item.self);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -13,6 +13,8 @@ import { Item } from '../shared/item.model';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { DeleteRequest } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
describe('RelationshipService', () => {
|
||||
let service: RelationshipService;
|
||||
@@ -22,6 +24,11 @@ describe('RelationshipService', () => {
|
||||
const relationshipsEndpointURL = `${restEndpointURL}/relationships`;
|
||||
const halService: any = new HALEndpointServiceStub(restEndpointURL);
|
||||
const rdbService = getMockRemoteDataBuildService();
|
||||
const objectCache = Object.assign({
|
||||
/* tslint:disable:no-empty */
|
||||
remove: () => {}
|
||||
/* tslint:enable:no-empty */
|
||||
}) as ObjectCacheService;
|
||||
|
||||
const relationshipType = Object.assign(new RelationshipType(), {
|
||||
type: ResourceType.RelationshipType,
|
||||
@@ -31,24 +38,20 @@ describe('RelationshipService', () => {
|
||||
rightLabel: 'isPublicationOfAuthor'
|
||||
});
|
||||
|
||||
const relationships = [
|
||||
Object.assign(new Relationship(), {
|
||||
self: relationshipsEndpointURL + '/2',
|
||||
id: '2',
|
||||
uuid: '2',
|
||||
leftId: 'author1',
|
||||
rightId: 'publication',
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
}),
|
||||
Object.assign(new Relationship(), {
|
||||
self: relationshipsEndpointURL + '/3',
|
||||
id: '3',
|
||||
uuid: '3',
|
||||
leftId: 'author2',
|
||||
rightId: 'publication',
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
})
|
||||
];
|
||||
const relationship1 = Object.assign(new Relationship(), {
|
||||
self: relationshipsEndpointURL + '/2',
|
||||
id: '2',
|
||||
uuid: '2',
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
});
|
||||
const relationship2 = Object.assign(new Relationship(), {
|
||||
self: relationshipsEndpointURL + '/3',
|
||||
id: '3',
|
||||
uuid: '3',
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
});
|
||||
|
||||
const relationships = [ relationship1, relationship2 ];
|
||||
|
||||
const item = Object.assign(new Item(), {
|
||||
self: 'fake-item-url/publication',
|
||||
@@ -65,6 +68,10 @@ describe('RelationshipService', () => {
|
||||
id: 'author2',
|
||||
uuid: 'author2'
|
||||
});
|
||||
relationship1.leftItem = getRemotedataObservable(relatedItem1);
|
||||
relationship1.rightItem = getRemotedataObservable(item);
|
||||
relationship2.leftItem = getRemotedataObservable(relatedItem2);
|
||||
relationship2.rightItem = getRemotedataObservable(item);
|
||||
const relatedItems = [relatedItem1, relatedItem2];
|
||||
|
||||
const itemService = jasmine.createSpyObj('itemService', {
|
||||
@@ -76,7 +83,8 @@ describe('RelationshipService', () => {
|
||||
requestService,
|
||||
halService,
|
||||
rdbService,
|
||||
itemService
|
||||
itemService,
|
||||
objectCache
|
||||
);
|
||||
}
|
||||
|
||||
@@ -93,13 +101,22 @@ describe('RelationshipService', () => {
|
||||
|
||||
describe('deleteRelationship', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'findById').and.returnValue(getRemotedataObservable(relationship1));
|
||||
spyOn(objectCache, 'remove');
|
||||
service.deleteRelationship(relationships[0].uuid).subscribe();
|
||||
});
|
||||
|
||||
it('should send a DeleteRequest', () => {
|
||||
const expected = new DeleteRequest(requestService.generateRequestId(), relationshipsEndpointURL + '/' + relationships[0].uuid);
|
||||
const expected = new DeleteRequest(requestService.generateRequestId(), relationshipsEndpointURL + '/' + relationship1.uuid);
|
||||
expect(requestService.configure).toHaveBeenCalledWith(expected, undefined);
|
||||
});
|
||||
|
||||
it('should clear the related items their cache', () => {
|
||||
expect(objectCache.remove).toHaveBeenCalledWith(relatedItem1.self);
|
||||
expect(objectCache.remove).toHaveBeenCalledWith(item.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(relatedItem1.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(item.self);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getItemRelationshipsArray', () => {
|
||||
@@ -135,3 +152,7 @@ describe('RelationshipService', () => {
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
function getRemotedataObservable(obj: any): Observable<RemoteData<any>> {
|
||||
return observableOf(new RemoteData(false, false, true, undefined, obj));
|
||||
}
|
||||
|
@@ -51,6 +51,10 @@ export class RelationshipService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a relationship by its UUID
|
||||
* @param uuid
|
||||
*/
|
||||
findById(uuid: string): Observable<RemoteData<Relationship>> {
|
||||
const href$ = this.getRelationshipEndpoint(uuid);
|
||||
return this.rdbService.buildSingle<Relationship>(href$);
|
||||
@@ -211,6 +215,10 @@ export class RelationshipService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear object and request caches of the items related to a relationship (left and right items)
|
||||
* @param uuid
|
||||
*/
|
||||
clearRelatedCache(uuid: string) {
|
||||
this.findById(uuid).pipe(
|
||||
getSucceededRemoteData(),
|
||||
|
Reference in New Issue
Block a user