diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts index accebb8df0..93528db8e8 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts @@ -105,6 +105,7 @@ describe('WorkPackageResource service', () => { describe('when updating multiple linked resources', () => { var updateWorkPackageStub: SinonStub; + var result; const expectCacheUpdate = () => { it('should update the work package cache', () => { @@ -122,8 +123,6 @@ describe('WorkPackageResource service', () => { }); describe('when the resources are properties of the work package', () => { - var result; - const testResultIsResource = (href, prepare) => { beforeEach(prepare); expectCacheUpdate(); @@ -180,6 +179,41 @@ describe('WorkPackageResource service', () => { }); }); }); + + describe('when the linked resource are not properties of the work package', () => { + const expectRejectedWithCacheUpdate = prepare => { + beforeEach(prepare); + + it('should return a rejected promise', () => { + expect(result).to.eventually.be.rejected; + }); + + expectCacheUpdate(); + }; + + beforeEach(() => { + source = {}; + createWorkPackage(); + }); + + describe('when using updateLinkedResources', () => { + expectRejectedWithCacheUpdate(() => { + result = workPackage.updateLinkedResources('attachments', 'activities'); + }); + }); + + describe('when using updateActivities', () => { + expectRejectedWithCacheUpdate(() => { + result = workPackage.updateActivities(); + }); + }); + + describe('when using updateAttachments', () => { + expectRejectedWithCacheUpdate(() => { + result = workPackage.updateAttachments(); + }); + }); + }); }); describe('when a work package is created with attachments and activities', () => { diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts index 22e9c7ecde..e7ec04559f 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts @@ -408,10 +408,15 @@ export class WorkPackageResource extends HalResource { * And inform the cache service about the work package update. * * Return a promise that returns the linked resources as properties. + * Return a rejected promise, if the resource is not a property of the work package. */ public updateLinkedResources(...resourceNames): IPromise<{[linkName: string]: HalResource}> { const resources: {[id: string]: IPromise} = {}; - resourceNames.forEach(name => resources[name] = this[name].$update()); + + resourceNames.forEach(name => { + const linked = this[name]; + resources[name] = linked ? linked.$update() : $q.reject(); + }); wpCacheService.updateWorkPackage(this); return $q.all(resources); @@ -421,7 +426,8 @@ export class WorkPackageResource extends HalResource { * Get updated activities from the server and inform the cache service about the work * package update. * - * Return a promise that returns the activities. + * Return a promise that returns the activities. Reject, if the work package has + * no activities. */ public updateActivities(): IPromise { return this @@ -433,7 +439,8 @@ export class WorkPackageResource extends HalResource { * Get updated attachments and activities from the server and inform the cache service * about the update. * - * Return a promise that returns the attachments. + * Return a promise that returns the attachments. Reject, if the work package has + * no attachments. */ public updateAttachments(): IPromise { return this