From 7e28976347a0432df466aa35f5df1367e533b317 Mon Sep 17 00:00:00 2001 From: Ruth Di Giacomo Date: Fri, 13 Sep 2024 14:58:30 +0200 Subject: [PATCH 1/6] refactor: change the error when using canCreate --- .../src/consumption/ConsumptionCoreErrors.ts | 4 ++++ .../src/modules/common/ValidationResult.ts | 9 ++------ .../outgoing/OutgoingRequestsController.ts | 6 +++++- .../DecideRequestParametersValidator.test.ts | 2 +- .../IncomingRequestsController.test.ts | 4 ++-- .../OutgoingRequestsController.test.ts | 21 ++++++++++++------- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/packages/consumption/src/consumption/ConsumptionCoreErrors.ts b/packages/consumption/src/consumption/ConsumptionCoreErrors.ts index 2a6a2910a..23bf9eabc 100644 --- a/packages/consumption/src/consumption/ConsumptionCoreErrors.ts +++ b/packages/consumption/src/consumption/ConsumptionCoreErrors.ts @@ -306,6 +306,10 @@ class Requests { return new CoreError("error.consumption.requests.missingRelationship", message); } + public inheritedFromItem(message: string) { + return new ApplicationError("error.consumption.validation.inheritedFromItem", message); + } + private static readonly _decideValidation = class { public invalidNumberOfItems(message: string) { return new ApplicationError("error.consumption.requests.decide.validation.invalidNumberOfItems", message); diff --git a/packages/consumption/src/modules/common/ValidationResult.ts b/packages/consumption/src/modules/common/ValidationResult.ts index 99a817c0c..6ff2f4432 100644 --- a/packages/consumption/src/modules/common/ValidationResult.ts +++ b/packages/consumption/src/modules/common/ValidationResult.ts @@ -1,4 +1,5 @@ import { ApplicationError } from "@js-soft/ts-utils"; +import { ConsumptionCoreErrors } from "../../consumption/ConsumptionCoreErrors"; export abstract class ValidationResult { protected constructor(public readonly items: ValidationResult[]) {} @@ -21,13 +22,7 @@ export abstract class ValidationResult { public static fromItems(items: ValidationResult[]): ValidationResult { return items.some((r) => r.isError()) - ? ValidationResult.error( - new ApplicationError( - "error.consumption.validation.inheritedFromItem", - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ), - items - ) + ? ValidationResult.error(ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors."), items) : ValidationResult.success(items); } } diff --git a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts index 76f95bf6d..5e74bec0e 100644 --- a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts +++ b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts @@ -115,7 +115,11 @@ export class OutgoingRequestsController extends ConsumptionBaseController { private async _create(id: CoreId, content: Request, peer: CoreAddress) { const canCreateResult = await this.canCreate({ content, peer }); - if (canCreateResult.isError()) throw canCreateResult.error; + if (canCreateResult.isError()) { + throw ConsumptionCoreErrors.requests.inheritedFromItem( + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ); + } const request = LocalRequest.from({ id: id, diff --git a/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts b/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts index 17f6735ab..40619828b 100644 --- a/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts +++ b/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts @@ -273,7 +273,7 @@ describe("DecideRequestParametersValidator", function () { expectedError: { indexPath: [0], code: "error.consumption.validation.inheritedFromItem", - message: "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + message: "Some child items have errors." } } ]; diff --git a/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts b/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts index 63502829d..984ad955f 100644 --- a/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts @@ -365,7 +365,7 @@ describe("IncomingRequestsController", function () { expect(validationResult).errorValidationResult({ code: "error.consumption.validation.inheritedFromItem", - message: "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -559,7 +559,7 @@ describe("IncomingRequestsController", function () { expect(validationResult).errorValidationResult({ code: "error.consumption.validation.inheritedFromItem", - message: "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); diff --git a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts index b80819b00..1b172d9aa 100644 --- a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts @@ -152,7 +152,7 @@ describe("OutgoingRequestsController", function () { }); expect(validationResult).errorValidationResult({ code: "error.consumption.validation.inheritedFromItem", - message: "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -185,7 +185,7 @@ describe("OutgoingRequestsController", function () { }); expect(validationResult).errorValidationResult({ code: "error.consumption.validation.inheritedFromItem", - message: "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -193,9 +193,7 @@ describe("OutgoingRequestsController", function () { expect(validationResult.items[1].isError()).toBe(true); expect((validationResult.items[1] as ErrorValidationResult).error.code).toBe("error.consumption.validation.inheritedFromItem"); - expect((validationResult.items[1] as ErrorValidationResult).error.message).toBe( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ); + expect((validationResult.items[1] as ErrorValidationResult).error.message).toBe("Some child items have errors."); expect(validationResult.items[1].items).toHaveLength(1); expect(validationResult.items[1].items[0].isError()).toBe(true); @@ -230,11 +228,20 @@ describe("OutgoingRequestsController", function () { test("throws when canCreate returns an error", async function () { const oldCanCreate = context.outgoingRequestsController.canCreate; context.outgoingRequestsController.canCreate = (_: ICreateOutgoingRequestParameters) => { - return Promise.resolve(ValidationResult.error(new ApplicationError("aCode", "aMessage"))); + return Promise.resolve( + ValidationResult.error( + new ApplicationError( + "error.consumption.validation.inheritedFromItem", + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ) + ) + ); }; await When.iTryToCreateAnOutgoingRequest(); - await Then.itThrowsAnErrorWithTheErrorMessage("aMessage"); + await Then.itThrowsAnErrorWithTheErrorMessage( + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ); context.outgoingRequestsController.canCreate = oldCanCreate; }); From c497a72ece0d0fc30826d15c091a7def47e6496d Mon Sep 17 00:00:00 2001 From: Ruth Di Giacomo Date: Fri, 13 Sep 2024 15:13:44 +0200 Subject: [PATCH 2/6] refactor: OutgoingRequestsController.test.ts changed --- .../modules/requests/OutgoingRequestsController.test.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts index 1b172d9aa..4f2dbc2c3 100644 --- a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts @@ -228,14 +228,7 @@ describe("OutgoingRequestsController", function () { test("throws when canCreate returns an error", async function () { const oldCanCreate = context.outgoingRequestsController.canCreate; context.outgoingRequestsController.canCreate = (_: ICreateOutgoingRequestParameters) => { - return Promise.resolve( - ValidationResult.error( - new ApplicationError( - "error.consumption.validation.inheritedFromItem", - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ) - ) - ); + return Promise.resolve(ValidationResult.error(new ApplicationError("aCode", "aMessage"))); }; await When.iTryToCreateAnOutgoingRequest(); From 9fc9672169823270889886cd04a520ff6a49e897 Mon Sep 17 00:00:00 2001 From: Ruth Di Giacomo Date: Fri, 13 Sep 2024 16:19:39 +0200 Subject: [PATCH 3/6] fix: regarding all cases in fromItems --- .../src/modules/common/ValidationResult.ts | 16 +++++++++++++--- .../outgoing/OutgoingRequestsController.ts | 6 +----- .../requests/OutgoingRequestsController.test.ts | 4 +--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/consumption/src/modules/common/ValidationResult.ts b/packages/consumption/src/modules/common/ValidationResult.ts index 6ff2f4432..2d0b9b57a 100644 --- a/packages/consumption/src/modules/common/ValidationResult.ts +++ b/packages/consumption/src/modules/common/ValidationResult.ts @@ -21,9 +21,19 @@ export abstract class ValidationResult { } public static fromItems(items: ValidationResult[]): ValidationResult { - return items.some((r) => r.isError()) - ? ValidationResult.error(ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors."), items) - : ValidationResult.success(items); + if (items.some((r) => r.isError())) { + const receivedError = items.find((r) => r.isError()); + if (typeof receivedError?.error.code !== "undefined") { + return ValidationResult.error(ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors."), items); + } + return ValidationResult.error( + ConsumptionCoreErrors.requests.inheritedFromItem( + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ), + items + ); + } + return ValidationResult.success(items); } } diff --git a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts index 5e74bec0e..76f95bf6d 100644 --- a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts +++ b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts @@ -115,11 +115,7 @@ export class OutgoingRequestsController extends ConsumptionBaseController { private async _create(id: CoreId, content: Request, peer: CoreAddress) { const canCreateResult = await this.canCreate({ content, peer }); - if (canCreateResult.isError()) { - throw ConsumptionCoreErrors.requests.inheritedFromItem( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ); - } + if (canCreateResult.isError()) throw canCreateResult.error; const request = LocalRequest.from({ id: id, diff --git a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts index 4f2dbc2c3..0a63e6c72 100644 --- a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts @@ -232,9 +232,7 @@ describe("OutgoingRequestsController", function () { }; await When.iTryToCreateAnOutgoingRequest(); - await Then.itThrowsAnErrorWithTheErrorMessage( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ); + await Then.itThrowsAnErrorWithTheErrorMessage("aMessage"); context.outgoingRequestsController.canCreate = oldCanCreate; }); From 91d1e79853d7b85578bb3cfd441036f0846b906b Mon Sep 17 00:00:00 2001 From: Ruth Di Giacomo Date: Tue, 17 Sep 2024 09:11:32 +0200 Subject: [PATCH 4/6] fix: false position, tests added --- .../src/modules/common/ValidationResult.ts | 16 ++-------- .../outgoing/OutgoingRequestsController.ts | 10 +++++- .../OutgoingRequestsController.test.ts | 7 +++++ .../requests/RequestsIntegrationTest.ts | 24 ++++++++++++++ .../test/modules/DeciderModule.test.ts | 31 +++++++++++++++++++ 5 files changed, 74 insertions(+), 14 deletions(-) diff --git a/packages/consumption/src/modules/common/ValidationResult.ts b/packages/consumption/src/modules/common/ValidationResult.ts index 2d0b9b57a..6ff2f4432 100644 --- a/packages/consumption/src/modules/common/ValidationResult.ts +++ b/packages/consumption/src/modules/common/ValidationResult.ts @@ -21,19 +21,9 @@ export abstract class ValidationResult { } public static fromItems(items: ValidationResult[]): ValidationResult { - if (items.some((r) => r.isError())) { - const receivedError = items.find((r) => r.isError()); - if (typeof receivedError?.error.code !== "undefined") { - return ValidationResult.error(ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors."), items); - } - return ValidationResult.error( - ConsumptionCoreErrors.requests.inheritedFromItem( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ), - items - ); - } - return ValidationResult.success(items); + return items.some((r) => r.isError()) + ? ValidationResult.error(ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors."), items) + : ValidationResult.success(items); } } diff --git a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts index 76f95bf6d..96334f22d 100644 --- a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts +++ b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts @@ -115,7 +115,15 @@ export class OutgoingRequestsController extends ConsumptionBaseController { private async _create(id: CoreId, content: Request, peer: CoreAddress) { const canCreateResult = await this.canCreate({ content, peer }); - if (canCreateResult.isError()) throw canCreateResult.error; + if (canCreateResult.isError()) { + if (canCreateResult.error.code === "error.consumption.validation.inheritedFromItem") { + throw ConsumptionCoreErrors.requests.inheritedFromItem( + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ); + } + + throw canCreateResult.error; + } const request = LocalRequest.from({ id: id, diff --git a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts index 0a63e6c72..041437b64 100644 --- a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts @@ -225,6 +225,13 @@ describe("OutgoingRequestsController", function () { await Then.itThrowsAnErrorWithTheErrorMessage("*content*Value is not defined*"); }); + test("throws that it is necessary to call 'canCreate' when at least one RequestItem is invalid", async function () { + await When.iTryToCreateAnOutgoingRequestWithIncorrectRequestItem(); + await Then.itThrowsAnErrorWithTheErrorMessage( + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ); + }); + test("throws when canCreate returns an error", async function () { const oldCanCreate = context.outgoingRequestsController.canCreate; context.outgoingRequestsController.canCreate = (_: ICreateOutgoingRequestParameters) => { diff --git a/packages/consumption/test/modules/requests/RequestsIntegrationTest.ts b/packages/consumption/test/modules/requests/RequestsIntegrationTest.ts index d84d9f0cc..a1aecacc6 100644 --- a/packages/consumption/test/modules/requests/RequestsIntegrationTest.ts +++ b/packages/consumption/test/modules/requests/RequestsIntegrationTest.ts @@ -936,6 +936,30 @@ export class RequestsWhen { return Promise.resolve(); } + public iTryToCreateAnOutgoingRequestWithIncorrectRequestItem(): Promise { + const params: ICreateOutgoingRequestParameters = { + content: { + items: [ + TestRequestItem.from({ + mustBeAccepted: false, + shouldFailAtCanCreateOutgoingRequestItem: true + }), + TestRequestItem.from({ + mustBeAccepted: false, + shouldFailAtCanCreateOutgoingRequestItem: true + }) + ] + }, + peer: CoreAddress.from("did:e:a-domain:dids:anidentity") + }; + + this.context.actionToTry = async () => { + await this.context.outgoingRequestsController.create(params as any); + }; + + return Promise.resolve(); + } + public iTryToCreateAnOutgoingRequestFromRelationshipTemplateResponseWithoutResponseSource(): Promise { const paramsWithoutResponseSource: Omit = { response: TestObjectFactory.createResponse(), diff --git a/packages/runtime/test/modules/DeciderModule.test.ts b/packages/runtime/test/modules/DeciderModule.test.ts index 4d72e366e..d1647c6f9 100644 --- a/packages/runtime/test/modules/DeciderModule.test.ts +++ b/packages/runtime/test/modules/DeciderModule.test.ts @@ -123,4 +123,35 @@ describe("DeciderModule", () => { (e) => e.data.template.id === template.id && e.data.result === RelationshipTemplateProcessedResult.ManualRequestDecisionRequired ); }); + + test("if you call canCreate for a request with an item which has an error you receive another errorMessage as if you call create", async () => { + const requestContent = { + content: { + items: [ + { + "@type": "ShareAttributeRequestItem", + sourceAttributeId: "ATT", + attribute: { + "@type": "IdentityAttribute", + owner: (await sender.transport.account.getIdentityInfo()).value.address, + value: { + "@type": "GivenName", + value: "aGivenName" + } + }, + mustBeAccepted: true + } + ] + }, + peer: (await recipient.transport.account.getIdentityInfo()).value.address + }; + const canCreateResult = await sender.consumption.outgoingRequests.canCreate(requestContent); + const createResult = await sender.consumption.outgoingRequests.create(requestContent); + expect(createResult.error.code).toBe("error.consumption.validation.inheritedFromItem"); + expect(createResult.error.message).toBe( + "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." + ); + expect(canCreateResult.value.code).toBe("error.consumption.validation.inheritedFromItem"); + expect(canCreateResult.value.message).toBe("Some child items have errors."); + }); }); From 46e98eb9e5477076cdd165b820a813cd6794e3e7 Mon Sep 17 00:00:00 2001 From: Ruth Di Giacomo Date: Tue, 17 Sep 2024 11:48:45 +0200 Subject: [PATCH 5/6] refactor: incorporate code review --- .../src/consumption/ConsumptionCoreErrors.ts | 2 +- .../outgoing/OutgoingRequestsController.ts | 8 ++--- .../DecideRequestParametersValidator.test.ts | 4 +-- .../IncomingRequestsController.test.ts | 8 ++--- .../OutgoingRequestsController.test.ts | 10 +++--- .../test/modules/DeciderModule.test.ts | 31 ------------------- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/packages/consumption/src/consumption/ConsumptionCoreErrors.ts b/packages/consumption/src/consumption/ConsumptionCoreErrors.ts index 23bf9eabc..4929645aa 100644 --- a/packages/consumption/src/consumption/ConsumptionCoreErrors.ts +++ b/packages/consumption/src/consumption/ConsumptionCoreErrors.ts @@ -307,7 +307,7 @@ class Requests { } public inheritedFromItem(message: string) { - return new ApplicationError("error.consumption.validation.inheritedFromItem", message); + return new ApplicationError("error.consumption.requests.validation.inheritedFromItem", message); } private static readonly _decideValidation = class { diff --git a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts index 96334f22d..23de46a1f 100644 --- a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts +++ b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts @@ -116,12 +116,8 @@ export class OutgoingRequestsController extends ConsumptionBaseController { const canCreateResult = await this.canCreate({ content, peer }); if (canCreateResult.isError()) { - if (canCreateResult.error.code === "error.consumption.validation.inheritedFromItem") { - throw ConsumptionCoreErrors.requests.inheritedFromItem( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ); - } - + const error = ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors. Call 'canCreate' to get more information."); + if (canCreateResult.error.equals(error)) throw error; throw canCreateResult.error; } diff --git a/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts b/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts index 40619828b..2701dd5f1 100644 --- a/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts +++ b/packages/consumption/test/modules/requests/DecideRequestParametersValidator.test.ts @@ -272,7 +272,7 @@ describe("DecideRequestParametersValidator", function () { }, expectedError: { indexPath: [0], - code: "error.consumption.validation.inheritedFromItem", + code: "error.consumption.requests.validation.inheritedFromItem", message: "Some child items have errors." } } @@ -317,7 +317,7 @@ describe("DecideRequestParametersValidator", function () { } expect(validationResult).errorValidationResult({ - code: "error.consumption.validation.inheritedFromItem" + code: "error.consumption.requests.validation.inheritedFromItem" }); let childResult = validationResult; diff --git a/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts b/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts index 984ad955f..20463d0c9 100644 --- a/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/IncomingRequestsController.test.ts @@ -364,7 +364,7 @@ describe("IncomingRequestsController", function () { }); expect(validationResult).errorValidationResult({ - code: "error.consumption.validation.inheritedFromItem", + code: "error.consumption.requests.validation.inheritedFromItem", message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -372,7 +372,7 @@ describe("IncomingRequestsController", function () { expect(validationResult.items[0].isError()).toBe(false); expect(validationResult.items[1].isError()).toBe(true); - expect(validationResult.items[1]).errorValidationResult({ code: "error.consumption.validation.inheritedFromItem" }); + expect(validationResult.items[1]).errorValidationResult({ code: "error.consumption.requests.validation.inheritedFromItem" }); expect(validationResult.items[1].items).toHaveLength(3); expect(validationResult.items[1].items[0].isError()).toBe(true); @@ -558,7 +558,7 @@ describe("IncomingRequestsController", function () { const validationResult = await When.iCallCanRejectWith(rejectParams); expect(validationResult).errorValidationResult({ - code: "error.consumption.validation.inheritedFromItem", + code: "error.consumption.requests.validation.inheritedFromItem", message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -566,7 +566,7 @@ describe("IncomingRequestsController", function () { expect(validationResult.items[0].isError()).toBe(false); expect(validationResult.items[1].isError()).toBe(true); - expect(validationResult.items[1]).errorValidationResult({ code: "error.consumption.validation.inheritedFromItem" }); + expect(validationResult.items[1]).errorValidationResult({ code: "error.consumption.requests.validation.inheritedFromItem" }); expect(validationResult.items[1].items).toHaveLength(3); expect(validationResult.items[1].items[0].isError()).toBe(true); diff --git a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts index 041437b64..003fbb15f 100644 --- a/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts +++ b/packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts @@ -151,7 +151,7 @@ describe("OutgoingRequestsController", function () { } }); expect(validationResult).errorValidationResult({ - code: "error.consumption.validation.inheritedFromItem", + code: "error.consumption.requests.validation.inheritedFromItem", message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -184,7 +184,7 @@ describe("OutgoingRequestsController", function () { } }); expect(validationResult).errorValidationResult({ - code: "error.consumption.validation.inheritedFromItem", + code: "error.consumption.requests.validation.inheritedFromItem", message: "Some child items have errors." }); expect(validationResult.items).toHaveLength(2); @@ -192,7 +192,7 @@ describe("OutgoingRequestsController", function () { expect(validationResult.items[0].isError()).toBe(false); expect(validationResult.items[1].isError()).toBe(true); - expect((validationResult.items[1] as ErrorValidationResult).error.code).toBe("error.consumption.validation.inheritedFromItem"); + expect((validationResult.items[1] as ErrorValidationResult).error.code).toBe("error.consumption.requests.validation.inheritedFromItem"); expect((validationResult.items[1] as ErrorValidationResult).error.message).toBe("Some child items have errors."); expect(validationResult.items[1].items).toHaveLength(1); @@ -227,9 +227,7 @@ describe("OutgoingRequestsController", function () { test("throws that it is necessary to call 'canCreate' when at least one RequestItem is invalid", async function () { await When.iTryToCreateAnOutgoingRequestWithIncorrectRequestItem(); - await Then.itThrowsAnErrorWithTheErrorMessage( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ); + await Then.itThrowsAnErrorWithTheErrorMessage("Some child items have errors. Call 'canCreate' to get more information."); }); test("throws when canCreate returns an error", async function () { diff --git a/packages/runtime/test/modules/DeciderModule.test.ts b/packages/runtime/test/modules/DeciderModule.test.ts index d1647c6f9..4d72e366e 100644 --- a/packages/runtime/test/modules/DeciderModule.test.ts +++ b/packages/runtime/test/modules/DeciderModule.test.ts @@ -123,35 +123,4 @@ describe("DeciderModule", () => { (e) => e.data.template.id === template.id && e.data.result === RelationshipTemplateProcessedResult.ManualRequestDecisionRequired ); }); - - test("if you call canCreate for a request with an item which has an error you receive another errorMessage as if you call create", async () => { - const requestContent = { - content: { - items: [ - { - "@type": "ShareAttributeRequestItem", - sourceAttributeId: "ATT", - attribute: { - "@type": "IdentityAttribute", - owner: (await sender.transport.account.getIdentityInfo()).value.address, - value: { - "@type": "GivenName", - value: "aGivenName" - } - }, - mustBeAccepted: true - } - ] - }, - peer: (await recipient.transport.account.getIdentityInfo()).value.address - }; - const canCreateResult = await sender.consumption.outgoingRequests.canCreate(requestContent); - const createResult = await sender.consumption.outgoingRequests.create(requestContent); - expect(createResult.error.code).toBe("error.consumption.validation.inheritedFromItem"); - expect(createResult.error.message).toBe( - "Some child items have errors. If this error occurred during the specification of a Request, call 'canCreate' to get more information." - ); - expect(canCreateResult.value.code).toBe("error.consumption.validation.inheritedFromItem"); - expect(canCreateResult.value.message).toBe("Some child items have errors."); - }); }); From 7825c72c988c199b9f39068b67d9d5c1473a3fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= <33655937+jkoenig134@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:23:19 +0200 Subject: [PATCH 6/6] chore: add newline --- .../src/modules/requests/outgoing/OutgoingRequestsController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts index 23de46a1f..a4757745a 100644 --- a/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts +++ b/packages/consumption/src/modules/requests/outgoing/OutgoingRequestsController.ts @@ -118,6 +118,7 @@ export class OutgoingRequestsController extends ConsumptionBaseController { if (canCreateResult.isError()) { const error = ConsumptionCoreErrors.requests.inheritedFromItem("Some child items have errors. Call 'canCreate' to get more information."); if (canCreateResult.error.equals(error)) throw error; + throw canCreateResult.error; }