Reject update of linked resources, if they don't exist

pull/4783/head
Alex Dik 8 years ago
parent ddab8c3b34
commit 6c1d64a42d
  1. 38
      frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts
  2. 13
      frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.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', () => {

@ -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<HalResource>} = {};
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<HalResource> {
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<HalResource> {
return this

Loading…
Cancel
Save