Skip to content

Commit

Permalink
feat: [IOCOM-555] Replace FullReceivedNotification with the autogen…
Browse files Browse the repository at this point in the history
…erated one (#5024)

## Short description
This PR replaces the `FullReceivedNotification` type with the
autogenerated one.

## List of changes proposed in this pull request
- updated definitions
- replaced the `FullReceivedNotification` with the autogenerated
`IOReceivedNotification`.

## How to test
run the tests and verify that everything works

---------

Co-authored-by: Andrea <[email protected]>
  • Loading branch information
adelloste and Vangaorth authored Sep 26, 2023
1 parent 8343bc3 commit 1ff4c91
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 141 deletions.
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"name": "italia-app",
"version": "2.42.0-rc.1",
"io_backend_api": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_backend.yaml",
"io_public_api": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_public.yaml",
"io_backend_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_backend.yaml",
"io_public_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_public.yaml",
"io_content_specs": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/definitions.yml",
"io_bonus_vacanze_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_bonus.yaml",
"io_cgn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.2.1-RELEASE/api_cgn.yaml",
"io_cgn_merchants_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.2.1-RELEASE/api_cgn_operator_search.yaml",
"io_bonus_vacanze_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_bonus.yaml",
"io_cgn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_cgn.yaml",
"io_cgn_merchants_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_cgn_operator_search.yaml",
"io_bpd_citizen": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/citizen.json",
"io_bpd_citizen_v2": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/citizen_v2.json",
"io_bpd_payment": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/payment.json",
"io_bpd_award_periods": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/award.json",
"io_bpd_winning_transactions": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/winning_transactions.json",
"io_bpd_winning_transactions_v2": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/winning_transactions_v2.json",
"api_fci": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_io_sign.yaml",
"io_eu_covid_cert": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_eucovidcert.yaml",
"io_sicilia_vola_token": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_mit_voucher.yaml",
"io_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_pn.yaml",
"api_fci": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_io_sign.yaml",
"io_eu_covid_cert": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_eucovidcert.yaml",
"io_sicilia_vola_token": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_mit_voucher.yaml",
"io_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_pn.yaml",
"io_consumed_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/openapi/consumed/api-piattaforma-notifiche.yaml",
"api_sicilia_vola": "assets/SiciliaVola.yml",
"api_cdc": "assets/CdcSwagger.yml",
"pagopa_api": "assets/paymentManager/spec.json",
"pagopa_api_walletv2": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/bonus/specs/bpd/pm/walletv2.json",
"pagopa_cobadge_configuration": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/pagopa/cobadge/abi_definitions.yml",
"pagopa_privative_configuration": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.27/pagopa/privative/definitions.yml",
"idpay_api": "https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v3.3.0/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml",
"lollipop_api": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/api_lollipop_first_consumer.yaml",
"fast_login_api": "https://raw.githubusercontent.com/pagopa/io-backend/v12.6.1-RELEASE/openapi/generated/api_fast_login.yaml",
"lollipop_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/api_lollipop_first_consumer.yaml",
"fast_login_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.6.2-RELEASE/openapi/generated/api_fast_login.yaml",
"pagopa_api_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/ca0f61d6c764dcc8a8594c1593d436dcdae58a7c/src/domains/wallet-app/api/wallet-service/v1/_openapi.json.tpl",
"private": true,
"scripts": {
Expand Down Expand Up @@ -75,7 +76,7 @@
"generate:eu-covid-cert": "rimraf definitions/eu_covid_cert && mkdir -p definitions/eu_covid_cert && gen-api-models --api-spec $npm_package_io_eu_covid_cert --out-dir ./definitions/eu_covid_cert --no-strict --request-types --response-decoders",
"generate:io_sicilia_vola_token": "rimraf definitions/io_sicilia_vola_token && mkdir -p definitions/io_sicilia_vola_token && gen-api-models --api-spec $npm_package_io_sicilia_vola_token --out-dir ./definitions/io_sicilia_vola_token --no-strict --request-types --response-decoders",
"generate:sicilia_vola_api": "rimraf definitions/api_sicilia_vola && mkdir -p definitions/api_sicilia_vola && gen-api-models --api-spec $npm_package_api_sicilia_vola --out-dir ./definitions/api_sicilia_vola --no-strict --request-types --response-decoders",
"generate:pn-definitions": "rimraf definitions/pn && mkdir -p definitions/pn && gen-api-models --api-spec $npm_package_io_pn_specs --out-dir ./definitions/pn --no-strict --request-types --response-decoders",
"generate:pn-definitions": "rimraf definitions/pn && mkdir -p definitions/pn && gen-api-models --api-spec $npm_package_io_consumed_pn_specs --out-dir ./definitions/pn && gen-api-models --api-spec $npm_package_io_pn_specs --out-dir ./definitions/pn --no-strict --request-types --response-decoders",
"generate:pagopa-api-walletv2": "rimraf definitions/pagopa/walletv2 && mkdir -p definitions/pagopa/walletv2 && gen-api-models --api-spec $npm_package_pagopa_api_walletv2 --out-dir ./definitions/pagopa/walletv2 --no-strict --request-types --response-decoders",
"generate:pagopa-cobadge-configuration": "rimraf definitions/pagopa/cobadge/configuration && mkdir -p definitions/pagopa/cobadge/configuration && gen-api-models --api-spec $npm_package_pagopa_cobadge_configuration --out-dir ./definitions/pagopa/cobadge/configuration",
"generate:pagopa-privative-configuration": "rimraf definitions/pagopa/privative/configuration && mkdir -p definitions/pagopa/privative/configuration && gen-api-models --api-spec $npm_package_pagopa_privative_configuration --out-dir ./definitions/pagopa/privative/configuration",
Expand Down
6 changes: 2 additions & 4 deletions ts/features/pn/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import * as A from "fp-ts/lib/Array";
import * as O from "fp-ts/lib/Option";
import { mixpanelTrack } from "../../../mixpanel";
import { TransactionSummaryErrorContent } from "../../../screens/wallet/payment/NewTransactionSummaryScreen";
import {
NotificationStatusHistoryElement,
PNMessage
} from "../../pn/store/types/types";
import { PNMessage } from "../../pn/store/types/types";
import { NotificationStatusHistoryElement } from "../../../../definitions/pn/NotificationStatusHistoryElement";
import { UIAttachment } from "../../../store/reducers/entities/messages/types";
import { booleanToYesNo, buildEventProperties } from "../../../utils/analytics";

Expand Down
3 changes: 2 additions & 1 deletion ts/features/pn/components/LegacyPnMessageDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import { useOnFirstRender } from "../../../utils/hooks/useOnFirstRender";
import { isDuplicatedPayment } from "../../../utils/payment";
import { MessageAttachments } from "../../messages/components/MessageAttachments";
import PN_ROUTES from "../navigation/routes";
import { NotificationPaymentInfo, PNMessage } from "../store/types/types";
import { PNMessage } from "../store/types/types";
import { NotificationPaymentInfo } from "../../../../definitions/pn/NotificationPaymentInfo";
import {
trackPNAttachmentOpening,
trackPNPaymentInfoError,
Expand Down
3 changes: 2 additions & 1 deletion ts/features/pn/components/PnMessageDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { useOnFirstRender } from "../../../utils/hooks/useOnFirstRender";
import { isDuplicatedPayment } from "../../../utils/payment";
import { MessageAttachments } from "../../messages/components/MessageAttachments";
import PN_ROUTES from "../navigation/routes";
import { NotificationPaymentInfo, PNMessage } from "../store/types/types";
import { PNMessage } from "../store/types/types";
import { NotificationPaymentInfo } from "../../../../definitions/pn/NotificationPaymentInfo";
import {
trackPNAttachmentOpening,
trackPNPaymentInfoError,
Expand Down
2 changes: 1 addition & 1 deletion ts/features/pn/components/PnMessagePayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import I18n from "i18n-js";
import { VSpacer } from "@pagopa/io-app-design-system";
import { useNavigation } from "@react-navigation/native";
import { NotificationPaymentInfo } from "../store/types/types";
import { NotificationPaymentInfo } from "../../../../definitions/pn/NotificationPaymentInfo";
import { TransactionSummary } from "../../../screens/wallet/payment/components/TransactionSummary";
import { TransactionSummaryErrorDetails } from "../../../screens/wallet/payment/components/TransactionSummaryErrorDetails";
import { PotFromActions } from "../../../types/utils";
Expand Down
6 changes: 3 additions & 3 deletions ts/features/pn/components/__test__/PnMessageDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
import { PNMessage } from "../../store/types/types";
import { InitializedProfile } from "../../../../../definitions/backend/InitializedProfile";
import { BackendStatusState } from "../../../../store/reducers/backendStatus";
import { ServiceId } from "../../../../../definitions/backend/ServiceId";
import { Download } from "../../../../store/reducers/entities/messages/downloads";
import { NotificationRecipient } from "../../../../../definitions/pn/NotificationRecipient";

const mockedOnAttachmentSelect = jest.fn();

Expand Down Expand Up @@ -124,18 +124,18 @@ const generatePnMessage = () =>
subject: "This is the message subject",
senderDenomination: "Sender denomination",
abstract: "Message abstract",
serviceId: "" as ServiceId,
notificationStatusHistory: [],
recipients: [
{
recipientType: "-",
taxId: generateTestFiscalCode(),
denomination: "AaAaAa BbBbBb",
payment: {
noticeCode: "026773337463073118",
creditorTaxId: "00000000009"
}
}
],
] as Array<NotificationRecipient>,
attachments: [
{
messageId: generateTestMessageId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RenderAPI, fireEvent, render } from "@testing-library/react-native";
import { NavigationAction } from "@react-navigation/native";
import { PnMessagePayment } from "../PnMessagePayment";
import { UIMessageId } from "../../../../store/reducers/entities/messages/types";
import { NotificationPaymentInfo } from "../../store/types/types";
import { NotificationPaymentInfo } from "../../../../../definitions/pn/NotificationPaymentInfo";
import PN_ROUTES from "../../navigation/routes";
import ROUTES from "../../../../navigation/routes";

Expand Down
3 changes: 2 additions & 1 deletion ts/features/pn/screens/LegacyPnMessageDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { LegacyPnMessageDetails } from "../components/LegacyPnMessageDetails";
import { PnMessageDetailsError } from "../components/PnMessageDetailsError";
import { PnParamsList } from "../navigation/params";
import { pnMessageFromIdSelector } from "../store/reducers";
import { NotificationPaymentInfo, PNMessage } from "../store/types/types";
import { PNMessage } from "../store/types/types";
import { NotificationPaymentInfo } from "../../../../definitions/pn/NotificationPaymentInfo";
import { cancelPreviousAttachmentDownload } from "../../../store/actions/messages";
import { profileFiscalCodeSelector } from "../../../store/reducers/profile";
import { isCancelledFromPNMessagePot, paymentFromPNMessagePot } from "../utils";
Expand Down
3 changes: 2 additions & 1 deletion ts/features/pn/screens/PnMessageDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { PnMessageDetails } from "../components/PnMessageDetails";
import { PnMessageDetailsError } from "../components/PnMessageDetailsError";
import { PnParamsList } from "../navigation/params";
import { pnMessageFromIdSelector } from "../store/reducers";
import { NotificationPaymentInfo, PNMessage } from "../store/types/types";
import { PNMessage } from "../store/types/types";
import { NotificationPaymentInfo } from "../../../../definitions/pn/NotificationPaymentInfo";
import { cancelPreviousAttachmentDownload } from "../../../store/actions/messages";
import { profileFiscalCodeSelector } from "../../../store/reducers/profile";
import { isCancelledFromPNMessagePot, paymentFromPNMessagePot } from "../utils";
Expand Down
26 changes: 13 additions & 13 deletions ts/features/pn/store/types/__test__/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as E from "fp-ts/lib/Either";
import { FullReceivedNotification } from "../types";
import { IOReceivedNotification } from "../../../../../../definitions/pn/IOReceivedNotification";

describe("FullReceivedNotification type", () => {
it("should decode a cancelled notification with completed payments list", () => {
Expand All @@ -16,16 +16,16 @@ describe("FullReceivedNotification type", () => {
isCancelled: true,
completedPayments
};
const maybeFullReceivedNotification = FullReceivedNotification.decode(
const maybeFullReceivedNotification = IOReceivedNotification.decode(
fullReceivedNotification
);
expect(E.isRight(maybeFullReceivedNotification)).toBe(true);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.isCancelled
).toBe(true);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.completedPayments
).toBe(completedPayments);
});
Expand All @@ -37,16 +37,16 @@ describe("FullReceivedNotification type", () => {
notificationStatusHistory: [],
isCancelled: true
};
const maybeFullReceivedNotification = FullReceivedNotification.decode(
const maybeFullReceivedNotification = IOReceivedNotification.decode(
fullReceivedNotification
);
expect(E.isRight(maybeFullReceivedNotification)).toBe(true);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.isCancelled
).toBe(true);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.completedPayments
).toBeUndefined();
});
Expand All @@ -58,16 +58,16 @@ describe("FullReceivedNotification type", () => {
notificationStatusHistory: [],
isCancelled: false
};
const maybeFullReceivedNotification = FullReceivedNotification.decode(
const maybeFullReceivedNotification = IOReceivedNotification.decode(
fullReceivedNotification
);
expect(E.isRight(maybeFullReceivedNotification)).toBe(true);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.isCancelled
).toBe(false);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.completedPayments
).toBeUndefined();
});
Expand All @@ -78,16 +78,16 @@ describe("FullReceivedNotification type", () => {
recipients: [],
notificationStatusHistory: []
};
const maybeFullReceivedNotification = FullReceivedNotification.decode(
const maybeFullReceivedNotification = IOReceivedNotification.decode(
fullReceivedNotification
);
expect(E.isRight(maybeFullReceivedNotification)).toBe(true);
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.isCancelled
).toBeUndefined();
expect(
(maybeFullReceivedNotification as E.Right<FullReceivedNotification>).right
(maybeFullReceivedNotification as E.Right<IOReceivedNotification>).right
.completedPayments
).toBeUndefined();
});
Expand Down
18 changes: 9 additions & 9 deletions ts/features/pn/store/types/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { pipe } from "fp-ts/lib/function";
import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";
import { ThirdPartyMessageWithContent } from "../../../../../definitions/backend/ThirdPartyMessageWithContent";
import { ThirdPartyMessage } from "../../../../../definitions/pn/ThirdPartyMessage";
import { attachmentsFromThirdPartyMessage } from "../../../../store/reducers/entities/messages/transformers";
import { PNMessage, FullReceivedNotification } from "./types";
import { PNMessage } from "./types";

export const toPNMessage = (
messageFromApi: ThirdPartyMessageWithContent
): O.Option<PNMessage> =>
pipe(
messageFromApi.third_party_message.details,
FullReceivedNotification.decode,
E.map(notification => ({
...notification,
serviceId: messageFromApi.sender_service_id,
messageFromApi.third_party_message,
ThirdPartyMessage.decode,
O.fromEither,
O.chainNullableK(message => message.details),
O.map(details => ({
...details,
attachments: pipe(
attachmentsFromThirdPartyMessage(messageFromApi, "PN"),
O.toUndefined
)
})),
O.fromEither
}))
);
92 changes: 2 additions & 90 deletions ts/features/pn/store/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,7 @@
import * as t from "io-ts";
import { IsoDateFromString } from "@pagopa/ts-commons/lib/dates";
import { ServiceId } from "../../../../../definitions/backend/ServiceId";
import { IOReceivedNotification } from "../../../../../definitions/pn/IOReceivedNotification";
import { UIAttachment } from "../../../../store/reducers/entities/messages/types";

export type NotificationStatus = t.TypeOf<typeof NotificationStatus>;
export const NotificationStatus = t.string;

export type TimelineElementId = t.TypeOf<typeof TimelineElementId>;
export const TimelineElementId = t.string;

const NotificationStatusHistoryElementR = t.interface({
activeFrom: IsoDateFromString,

relatedTimelineElements: t.readonlyArray(
TimelineElementId,
"array of TimelineElementId"
),

status: NotificationStatus
});
const NotificationStatusHistoryElementO = t.partial({});

export const NotificationStatusHistoryElement = t.intersection(
[NotificationStatusHistoryElementR, NotificationStatusHistoryElementO],
"NotificationStatusHistoryElement"
);
export type NotificationStatusHistoryElement = t.TypeOf<
typeof NotificationStatusHistoryElement
>;

export type NotificationStatusHistory = t.TypeOf<
typeof NotificationStatusHistory
>;
export const NotificationStatusHistory = t.readonlyArray(
NotificationStatusHistoryElement,
"array of NotificationStatusHistoryElement"
);

export const NotificationPaymentInfoR = t.interface({
noticeCode: t.string,
creditorTaxId: t.string
});

export const NotificationPaymentInfoO = t.partial({});

export const NotificationPaymentInfo = t.intersection(
[NotificationPaymentInfoR, NotificationPaymentInfoO],
"NotificationPaymentInfo"
);

export type NotificationPaymentInfo = t.TypeOf<typeof NotificationPaymentInfo>;

export const NotificationRecipientR = t.interface({
denomination: t.string,
taxId: t.string
});

export const NotificationRecipientO = t.partial({
payment: NotificationPaymentInfo
});

export const NotificationRecipient = t.intersection(
[NotificationRecipientR, NotificationRecipientO],
"NotificationRecipient"
);

export const FullReceivedNotificationR = t.interface({
subject: t.string,
iun: t.string,
recipients: t.array(NotificationRecipient),
notificationStatusHistory: NotificationStatusHistory
});

export const FullReceivedNotificationO = t.partial({
abstract: t.string,
senderDenomination: t.string,
isCancelled: t.boolean,
completedPayments: t.readonlyArray(t.string)
});

export const FullReceivedNotification = t.intersection(
[FullReceivedNotificationR, FullReceivedNotificationO],
"FullReceivedNotification"
);

export type FullReceivedNotification = t.TypeOf<
typeof FullReceivedNotification
>;

export type PNMessage = FullReceivedNotification &
export type PNMessage = IOReceivedNotification &
Readonly<{
serviceId: ServiceId;
attachments?: ReadonlyArray<UIAttachment>;
}>;
Loading

0 comments on commit 1ff4c91

Please sign in to comment.