From dc860ba8e91002afc512de9813edc726cc545655 Mon Sep 17 00:00:00 2001 From: acuiuli Date: Wed, 7 Feb 2024 09:32:37 +0100 Subject: [PATCH] added configuration_id field in message_view --- src/models/__tests__/message_view.test.ts | 20 +++++++++++++++++++- src/models/message_view.ts | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/models/__tests__/message_view.test.ts b/src/models/__tests__/message_view.test.ts index 64c0359d..d8603c54 100644 --- a/src/models/__tests__/message_view.test.ts +++ b/src/models/__tests__/message_view.test.ts @@ -93,6 +93,22 @@ describe("message_view", () => { expect(E.isLeft(result)).toBeTruthy(); }); + it("GIVEN a valid message_view object with thirdParty WHEN the object contain an invalid configuration_id THEN the decode fails", async () => { + const messageViewWithThirdParty = { + ...aMessageView, + components: { + ...aMessageView.components, + thirdParty: { + has: true, + id: "AN_ID", + configuration_id: "anInvalidUlid" + } + } + }; + const result = MessageView.decode(messageViewWithThirdParty); + expect(E.isLeft(result)).toBeTruthy(); + }); + it("GIVEN a valid message_view object with thirdParty WHEN the object contains a valid id THEN the decode succeed", async () => { const messageViewWithThirdParty = { ...aMessageView, @@ -100,7 +116,8 @@ describe("message_view", () => { ...aMessageView.components, thirdParty: { has: true, - id: "AN_ID" + id: "AN_ID", + configuration_id: "01ARZ3NDEKTSV4RRFFQ69G5FAV" } } }; @@ -229,6 +246,7 @@ describe("message_view", () => { ); } }); + it("GIVEN a valid message_view without third party object WHEN the object is decode THEN the decode succeed", async () => { const { thirdParty, ...componentsWithoutThirdParty } = aComponents; diff --git a/src/models/message_view.ts b/src/models/message_view.ts index 4eaa682a..814f7465 100644 --- a/src/models/message_view.ts +++ b/src/models/message_view.ts @@ -1,5 +1,5 @@ import * as t from "io-ts"; -import { NonEmptyString } from "@pagopa/ts-commons/lib/strings"; +import { NonEmptyString, Ulid } from "@pagopa/ts-commons/lib/strings"; import { Container } from "@azure/cosmos"; import { NonNegativeInteger } from "@pagopa/ts-commons/lib/numbers"; import { enumType, withDefault } from "@pagopa/ts-commons/lib/types"; @@ -55,6 +55,7 @@ export const ThirdPartyComponent = t.union([ id: NonEmptyString }), t.partial({ + configuration_id: Ulid, has_precondition: enumType( HasPreconditionEnum, "has_precondition"