mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
65272: Clear template-item cache on removal
This commit is contained in:
@@ -13,6 +13,8 @@ import { Item } from '../../../core/shared/item.model';
|
||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/testing/utils';
|
||||
import { ItemTemplateDataService } from '../../../core/data/item-template-data.service';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
|
||||
describe('CollectionMetadataComponent', () => {
|
||||
let comp: CollectionMetadataComponent;
|
||||
@@ -20,11 +22,14 @@ describe('CollectionMetadataComponent', () => {
|
||||
let router: Router;
|
||||
let itemTemplateService: ItemTemplateDataService;
|
||||
|
||||
const template = new Item();
|
||||
const template = Object.assign(new Item(), {
|
||||
self: 'template-selflink'
|
||||
});
|
||||
const collection = Object.assign(new Collection(), {
|
||||
uuid: 'collection-id',
|
||||
id: 'collection-id',
|
||||
name: 'Fake Collection'
|
||||
name: 'Fake Collection',
|
||||
self: 'collection-selflink'
|
||||
});
|
||||
|
||||
const itemTemplateServiceStub = Object.assign({
|
||||
@@ -37,6 +42,12 @@ describe('CollectionMetadataComponent', () => {
|
||||
success: {},
|
||||
error: {}
|
||||
});
|
||||
const objectCache = jasmine.createSpyObj('objectCache', {
|
||||
remove: {}
|
||||
});
|
||||
const requestService = jasmine.createSpyObj('requestService', {
|
||||
removeByHrefSubstring: {}
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -46,7 +57,9 @@ describe('CollectionMetadataComponent', () => {
|
||||
{ provide: CollectionDataService, useValue: {} },
|
||||
{ provide: ItemTemplateDataService, useValue: itemTemplateServiceStub },
|
||||
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: createSuccessfulRemoteDataObject(collection) }) } } },
|
||||
{ provide: NotificationsService, useValue: notificationsService }
|
||||
{ provide: NotificationsService, useValue: notificationsService },
|
||||
{ provide: ObjectCacheService, useValue: objectCache },
|
||||
{ provide: RequestService, useValue: requestService }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
@@ -84,6 +97,11 @@ describe('CollectionMetadataComponent', () => {
|
||||
it('should display a success notification', () => {
|
||||
expect(notificationsService.success).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset related object and request cache', () => {
|
||||
expect(objectCache.remove).toHaveBeenCalledWith(template.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(collection.self);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when delete returns a failure', () => {
|
||||
|
@@ -12,6 +12,8 @@ import { switchMap, take } from 'rxjs/operators';
|
||||
import { combineLatest as combineLatestObservable } from 'rxjs';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
|
||||
/**
|
||||
* Component for editing a collection's metadata
|
||||
@@ -35,7 +37,9 @@ export class CollectionMetadataComponent extends ComcolMetadataComponent<Collect
|
||||
protected router: Router,
|
||||
protected route: ActivatedRoute,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected translate: TranslateService
|
||||
protected translate: TranslateService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected requestService: RequestService
|
||||
) {
|
||||
super(collectionDataService, router, route, notificationsService, translate);
|
||||
}
|
||||
@@ -94,13 +98,19 @@ export class CollectionMetadataComponent extends ComcolMetadataComponent<Collect
|
||||
);
|
||||
|
||||
combineLatestObservable(collection$, template$).pipe(
|
||||
switchMap(([collection, template]) => this.itemTemplateService.deleteByCollectionID(template, collection.uuid))
|
||||
switchMap(([collection, template]) => {
|
||||
const success$ = this.itemTemplateService.deleteByCollectionID(template, collection.uuid);
|
||||
this.objectCache.remove(template.self);
|
||||
this.requestService.removeByHrefSubstring(collection.self);
|
||||
return success$;
|
||||
})
|
||||
).subscribe((success: boolean) => {
|
||||
if (success) {
|
||||
this.notificationsService.success(null, this.translate.get('collection.edit.template.notifications.delete.success'));
|
||||
} else {
|
||||
this.notificationsService.error(null, this.translate.get('collection.edit.template.notifications.delete.error'));
|
||||
}
|
||||
this.initTemplateItem();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { inheritSerialization, deserialize, autoserializeAs } from 'cerialize';
|
||||
import { inheritSerialization, deserialize } from 'cerialize';
|
||||
|
||||
import { mapsTo, relationship } from '../builders/build-decorators';
|
||||
import { TemplateItem } from '../../shared/template-item.model';
|
||||
@@ -12,18 +12,6 @@ import { Collection } from '../../shared/collection.model';
|
||||
@inheritSerialization(NormalizedItem)
|
||||
export class NormalizedTemplateItem extends NormalizedItem {
|
||||
|
||||
/**
|
||||
* The human-readable identifier of this DSpaceObject
|
||||
*/
|
||||
@autoserializeAs(String)
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The universally unique identifier of this DSpaceObject
|
||||
*/
|
||||
@autoserializeAs(String, 'id')
|
||||
uuid: string;
|
||||
|
||||
/**
|
||||
* The Collection that this item is a template for
|
||||
*/
|
||||
|
@@ -8,7 +8,7 @@ import { ResourceType } from './resource-type';
|
||||
* Class representing a DSpace Template Item
|
||||
*/
|
||||
export class TemplateItem extends Item {
|
||||
static type = new ResourceType('templateItem');
|
||||
static type = new ResourceType('itemtemplate');
|
||||
|
||||
/**
|
||||
* The Collection that this item is a template for
|
||||
|
Reference in New Issue
Block a user