Skip to content

Commit

Permalink
feat: Add organization fiscal code in EnrichedMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Garma00 authored May 27, 2024
1 parent 8140b0d commit 5f91cf4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 76 deletions.
84 changes: 22 additions & 62 deletions openapi/__tests__/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { CommonServiceMetadata as ApiCommonServiceMetadata } from "../../generat
import { StandardServiceMetadata as ApiStandardServiceMetadata } from "../../generated/definitions/StandardServiceMetadata";
import { ServiceScopeEnum } from "../../generated/definitions/ServiceScope";
import { SpecialServiceCategoryEnum } from "../../generated/definitions/SpecialServiceCategory";
import { NotRejectedMessageStatusValueEnum as MessageStatusValueEnum, NotRejectedMessageStatusValueEnum } from "../../generated/definitions/NotRejectedMessageStatusValue";
import { NotRejectedMessageStatusValueEnum as MessageStatusValueEnum } from "../../generated/definitions/NotRejectedMessageStatusValue";
import { MessageStatus } from "../../generated/definitions/MessageStatus";
import { MessageStatusChange } from "../../generated/definitions/MessageStatusChange";
import { MessageStatusAttributes } from "../../generated/definitions/MessageStatusAttributes";
Expand All @@ -33,14 +33,12 @@ import { Change_typeEnum as ReadingChangeType } from "../../generated/definition
import { Change_typeEnum as ArchinvingChangeType } from "../../generated/definitions/MessageStatusArchivingChange";
import { FeatureLevelTypeEnum } from "../../generated/definitions/FeatureLevelType";
import { ThirdPartyMessage } from "../../generated/definitions/ThirdPartyMessage";
import { BaseEnrichedMessage } from "../../generated/definitions/BaseEnrichedMessage"
import { EnrichedMessageWithOrganizationFiscalCode } from "../../generated/definitions/EnrichedMessageWithOrganizationFiscalCode"
import { EnrichedMessage } from "../../generated/definitions/EnrichedMessage";
import { NonEmptyString, Semver } from "@pagopa/ts-commons/lib/strings";

import { AppVersion } from "../../generated/definitions/AppVersion";
import { ThirdPartyData } from "../../generated/definitions/ThirdPartyData";
import { aService } from "../../__mocks__/mocks";
import { EnrichedMessage } from "../../generated/definitions/EnrichedMessage";

describe("ServicePayload definition", () => {
const commonServicePayload = {
Expand Down Expand Up @@ -236,66 +234,28 @@ const aPayee: Payee = { fiscal_code: anOrganizationFiscalCode };

const aThirdPartyId = "aThirdPartyId" as NonEmptyString;

describe("BaseEnrichedMessage definition", () => {
it("should decode a BaseEnrichedMessage", () => {
const aBaseEnrichedMessage = {
...aMessageWithoutContent,
service_name: "aService",
organization_name: aService.organizationName,
message_title: "aTitle",
};

expect(
E.isRight(BaseEnrichedMessage.decode(aBaseEnrichedMessage))
).toBe(true);
});
});

describe("EnrichedMessage definition", () => {
it("should not fail decoding an EnrichedMessage with an organization fiscal code", () => {
const anEnrichedMessage = {
...aMessageWithoutContent,
sender_service_id: "test" as NonEmptyString,
service_name: "aService",
organization_name: aService.organizationName,
organization_fiscal_code: aService.organizationFiscalCode,
message_title: "aTitle",
};

expect(
E.isRight(EnrichedMessage.decode(anEnrichedMessage))
).toBe(true);
});
});

describe("EnrichedMessageWithOrganizationFiscalCode definition", () => {
it("should fail decoding a EnrichedMessageWithOrganizationFiscalCode if the organization fiscal code is not provided", () => {
const aBaseEnrichedMessageWithOrganizationFiscalCode = {
...aMessageWithoutContent,
service_name: "aService",
organization_name: aService.organizationName,
message_title: "aTitle",
};

expect(
E.isLeft(EnrichedMessageWithOrganizationFiscalCode.decode(aBaseEnrichedMessageWithOrganizationFiscalCode))
).toBe(true);
});
describe("EnrichedMessage", () => {
const aValidEnrichedMessage: EnrichedMessage = {
id: "A_MESSAGE_ID",
fiscal_code: aFiscalCode,
created_at: aDate,
sender_service_id: aMessageWithoutContent.sender_service_id as NonEmptyString,
service_name: "aService",
organization_name: aService.organizationName,
organization_fiscal_code: aService.organizationFiscalCode,
message_title: "aTitle",
is_read: false,
is_archived: false,
};

it("should decode correctly a EnrichedMessageWithOrganizationFiscalCode if the organization fiscal code is provided", () => {
const aBaseEnrichedMessage = {
...aMessageWithoutContent,
service_name: "aService",
organization_name: aService.organizationName,
organization_fiscal_code: aService.organizationFiscalCode,
message_title: "aTitle",
};
it("should correctly decode a valid EnrichedMessage", () => {
expect(E.isRight(EnrichedMessage.decode(aValidEnrichedMessage))).toBe(true)
})

expect(
E.isRight(EnrichedMessageWithOrganizationFiscalCode.decode(aBaseEnrichedMessage))
).toBe(true);
});
});
it("should fail decoding an EnrichedMessage without organization fiscal code", () => {
expect(E.isLeft(EnrichedMessage.decode({ ...aValidEnrichedMessage, organization_fiscal_code: undefined }))).toBe(true)
})
})

describe("NewMessage definition", () => {
it("should decode STANDARD NewMessage with content but without payment data", () => {
Expand Down
19 changes: 5 additions & 14 deletions openapi/definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ BaseEnrichedMessage:
type: string
organization_name:
type: string
organization_fiscal_code:
$ref: "#/OrganizationFiscalCode"
message_title:
type: string
category:
Expand All @@ -443,23 +445,13 @@ BaseEnrichedMessage:
- sender_service_id
- service_name
- organization_name
- organization_fiscal_code
- message_title

EnrichedMessage:
allOf:
- $ref: "#/BaseEnrichedMessage"
- $ref: "#/MessageStatusAttributes"

EnrichedMessageWithOrganizationFiscalCode:
allOf:
- $ref: "#/EnrichedMessage"
- type: object
properties:
organization_fiscal_code:
$ref: "#/OrganizationFiscalCode"
required:
- organization_fiscal_code

ExternalCreatedMessageWithoutContent:
allOf:
- $ref: "#/CreatedMessageWithoutContent"
Expand Down Expand Up @@ -526,9 +518,8 @@ ExternalMessageResponseWithContent:
PublicMessage:
x-one-of: true
allOf:
- $ref: "#/EnrichedMessageWithOrganizationFiscalCode"
- $ref: "#/CreatedMessageWithoutContent"

- $ref: "#/EnrichedMessage"
- $ref: "#/CreatedMessageWithoutContent"
MessageResponseNotificationStatus:
type: object
properties:
Expand Down

0 comments on commit 5f91cf4

Please sign in to comment.