Skip to content

Commit

Permalink
chore: [IOCOM-1479] organization_fiscal_code from GET /messages (#…
Browse files Browse the repository at this point in the history
…5847)

## Short description
This PR updates the io-backend spec to receive
`organization_fiscal_code` in the `GET /messages` endpoint.

## List of changes proposed in this pull request
- io-backend spec to 13.39.1
- `toUIMessage` introduces the new `organizationFiscalCode` property
- `WrappedMessageListItem` reads `organizationFiscalCode` directly from
the `UIMessage` instance instead of relying on the `Service` instance

## How to test
Using the io-dev-api-server, check that the service logo is loaded
properly in the new DS messages home and that `organizationFiscalCode`
has a non-falsy value.

---------

Co-authored-by: Martino Cesari Tomba <[email protected]>
  • Loading branch information
Vangaorth and forrest57 authored Jun 11, 2024
1 parent 0c37522 commit 6471059
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 106 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "italia-app",
"version": "2.62.0-rc.0",
"io_backend_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_backend.yaml",
"io_public_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_public.yaml",
"io_backend_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_backend.yaml",
"io_public_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_public.yaml",
"io_content_specs": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.32/definitions.yml",
"io_cgn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_cgn.yaml",
"io_cgn_merchants_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_cgn_operator_search.yaml",
"api_fci": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_io_sign.yaml",
"io_eu_covid_cert": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_eucovidcert.yaml",
"io_sicilia_vola_token": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_mit_voucher.yaml",
"io_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_pn.yaml",
"io_consumed_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/openapi/consumed/api-piattaforma-notifiche.yaml",
"io_cgn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_cgn.yaml",
"io_cgn_merchants_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_cgn_operator_search.yaml",
"api_fci": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_io_sign.yaml",
"io_eu_covid_cert": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_eucovidcert.yaml",
"io_sicilia_vola_token": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_mit_voucher.yaml",
"io_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_pn.yaml",
"io_consumed_pn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/openapi/consumed/api-piattaforma-notifiche.yaml",
"api_cdc": "assets/CdcSwagger.yml",
"pagopa_api": "assets/paymentManager/spec.json",
"pagopa_api_walletv2": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.30/bonus/specs/bpd/pm/walletv2.json",
"pagopa_cobadge_configuration": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.30/pagopa/cobadge/abi_definitions.yml",
"pagopa_privative_configuration": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.30/pagopa/privative/definitions.yml",
"pagopa_api_walletv2": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.32/bonus/specs/bpd/pm/walletv2.json",
"pagopa_cobadge_configuration": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.32/pagopa/cobadge/abi_definitions.yml",
"pagopa_privative_configuration": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.32/pagopa/privative/definitions.yml",
"idpay_api": "https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v6.9.1/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml",
"services_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_services_app_backend.yaml",
"lollipop_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/api_lollipop_first_consumer.yaml",
"fast_login_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.35.0-RELEASE/openapi/generated/api_fast_login.yaml",
"services_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_services_app_backend.yaml",
"lollipop_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/api_lollipop_first_consumer.yaml",
"fast_login_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.39.1-RELEASE/openapi/generated/api_fast_login.yaml",
"pagopa_api_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/v1.35.1/src/domains/wallet-app/api/payment-wallet/v1/_openapi.json.tpl",
"pagopa_api_ecommerce": "https://raw.githubusercontent.com/pagopa/pagopa-infra/v1.35.1/src/domains/ecommerce-app/api/ecommerce-io/v1/_openapi.json.tpl",
"pagopa_api_biz_events": "https://raw.githubusercontent.com/pagopa/pagopa-infra/0a6784276fd43aaff7709dd90e0d379e77326f28/src/domains/bizevents-app/api/transaction-service/v1/_openapi-jwt.json.tpl",
Expand Down
6 changes: 6 additions & 0 deletions ts/features/messages/__mocks__/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const apiPayload = {
time_to_live: 3600,
service_name: service_1.service_name,
organization_name: service_1.organization_name,
organization_fiscal_code: service_1.organization_fiscal_code,
message_title: "Għandek flus?"
},
{
Expand All @@ -70,6 +71,7 @@ export const apiPayload = {
time_to_live: 3600,
service_name: service_1.service_name,
organization_name: service_1.organization_name,
organization_fiscal_code: service_1.organization_fiscal_code,
message_title: "Analiżi tad-demm"
},
{
Expand All @@ -82,6 +84,7 @@ export const apiPayload = {
time_to_live: 3600,
service_name: "alert",
organization_name: "Наркомвнудел",
organization_fiscal_code: "CDFSCL",
message_title: "позвоните нам!"
}
],
Expand All @@ -101,6 +104,7 @@ const successPayloadMessages: ReloadMessagesPayload["messages"] = [
timeToLive,
serviceName: service_1.service_name,
organizationName: service_1.organization_name,
organizationFiscalCode: service_1.organization_fiscal_code,
title: "Għandek flus?",
hasPrecondition: false,
raw: apiPayload.items[0] as any
Expand All @@ -116,6 +120,7 @@ const successPayloadMessages: ReloadMessagesPayload["messages"] = [
timeToLive,
serviceName: service_1.service_name,
organizationName: service_1.organization_name,
organizationFiscalCode: service_1.organization_fiscal_code,
title: "Analiżi tad-demm",
hasPrecondition: false,
raw: apiPayload.items[1] as any
Expand All @@ -131,6 +136,7 @@ const successPayloadMessages: ReloadMessagesPayload["messages"] = [
timeToLive,
serviceName: service_2.service_name,
organizationName: service_2.organization_name,
organizationFiscalCode: service_2.organization_fiscal_code,
title: "позвоните нам!",
hasPrecondition: false,
raw: apiPayload.items[2] as any
Expand Down
36 changes: 6 additions & 30 deletions ts/features/messages/components/Home/WrappedMessageListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import React, { useEffect, useMemo } from "react";
import {
useIODispatch,
useIOSelector,
useIOStore
} from "../../../../store/hooks";
import { serviceByIdSelector } from "../../../services/details/store/reducers/servicesById";
import React, { useMemo } from "react";
import { UIMessage } from "../../types";
import { logosForService } from "../../../../utils/services";
import I18n from "../../../../i18n";
import { TagEnum } from "../../../../../definitions/backend/MessageCategoryPN";
import { convertDateToWordDistance } from "../../utils/convertDateToWordDistance";
import {
accessibilityLabelForMessageItem,
getLoadServiceDetailsActionIfNeeded
} from "./homeUtils";
import { logoForService } from "../../../services/home/utils";
import { accessibilityLabelForMessageItem } from "./homeUtils";
import { MessageListItem } from "./DS/MessageListItem";

type WrappedMessageListItemProps = {
Expand All @@ -23,27 +14,12 @@ type WrappedMessageListItemProps = {
export const WrappedMessageListItem = ({
message
}: WrappedMessageListItemProps) => {
const dispatch = useIODispatch();
const store = useIOStore();
const serviceId = message.serviceId;
const service = useIOSelector(state => serviceByIdSelector(state, serviceId));
const organizationFiscalCode = service?.organization_fiscal_code;
useEffect(() => {
const state = store.getState();
const loadServiceDetailsActionOrUndefined =
getLoadServiceDetailsActionIfNeeded(
state,
serviceId,
organizationFiscalCode
);
if (loadServiceDetailsActionOrUndefined) {
dispatch(loadServiceDetailsActionOrUndefined);
}
}, [dispatch, organizationFiscalCode, serviceId, store]);
const organizationFiscalCode = message.organizationFiscalCode;

const serviceLogoUriSources = useMemo(
() => (service ? logosForService(service) : undefined),
[service]
() => logoForService(serviceId, organizationFiscalCode),
[serviceId, organizationFiscalCode]
);
const organizationName =
message.organizationName || I18n.t("messages.errorLoading.senderInfo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { createStore } from "redux";
import { appReducer } from "../../../../../store/reducers";
import { applicationChangeState } from "../../../../../store/actions/application";
import { preferencesDesignSystemSetEnabled } from "../../../../../store/actions/persistedPreferences";
import { loadServiceDetail } from "../../../../services/details/store/actions/details";
import { ServiceId } from "../../../../../../definitions/backend/ServiceId";
import { renderScreenWithNavigationStoreContext } from "../../../../../utils/testWrapper";
import { UIMessage } from "../../../types";
import { MESSAGES_ROUTES } from "../../../navigation/routes";
import { ServicePublic } from "../../../../../../definitions/backend/ServicePublic";
import { TagEnum as SENDTagEnum } from "../../../../../../definitions/backend/MessageCategoryPN";
import { TagEnum } from "../../../../../../definitions/backend/MessageCategoryPayment";
import { WrappedMessageListItem } from "../WrappedMessageListItem";
Expand All @@ -24,91 +22,49 @@ describe("WrappedMessageListItem", () => {
jest.resetAllMocks();
jest.clearAllMocks();
});
it("should trigger the loadServiceDetail.request when service details are not available", () => {
const serviceId = "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId;
const message = messageGenerator(false, false, serviceId);
renderComponent(message, serviceId, false);
expect(mockDispatch.mock.calls[0][0]).toStrictEqual(
loadServiceDetail.request(serviceId)
);
});
it("should not trigger the loadServiceDetail.request when service details are available", () => {
const serviceId = "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId;
const message = messageGenerator(false, false, serviceId);
renderComponent(message, serviceId);
expect(mockDispatch.mock.calls[0]).toBeUndefined();
});
it("should match snapshot, not from SEND, unread message", () => {
const serviceId = "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId;
const message = messageGenerator(false, false, serviceId);
const component = renderComponent(message, serviceId);
const message = messageGenerator(false, false);
const component = renderComponent(message);
expect(component.toJSON()).toMatchSnapshot();
});
it("should match snapshot, not from SEND, read message", () => {
const serviceId = "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId;
const message = messageGenerator(false, true, serviceId);
const component = renderComponent(message, serviceId);
const message = messageGenerator(false, true);
const component = renderComponent(message);
expect(component.toJSON()).toMatchSnapshot();
});
it("should match snapshot, from SEND, unread message", () => {
const serviceId = "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId;
const message = messageGenerator(true, false, serviceId);
const component = renderComponent(message, serviceId);
const message = messageGenerator(true, false);
const component = renderComponent(message);
expect(component.toJSON()).toMatchSnapshot();
});
it("should match snapshot, from SEND, read message", () => {
const serviceId = "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId;
const message = messageGenerator(true, true, serviceId);
const component = renderComponent(message, serviceId);
const message = messageGenerator(true, true);
const component = renderComponent(message);
expect(component.toJSON()).toMatchSnapshot();
});
});

const messageGenerator = (
isFromSend: boolean,
isRead: boolean,
serviceId: ServiceId
): UIMessage =>
const messageGenerator = (isFromSend: boolean, isRead: boolean): UIMessage =>
({
createdAt: new Date(1990, 0, 2, 3, 4),
isRead,
organizationName: "Organization name",
serviceId,
organizationFiscalCode: "RGNFSCCDO",
serviceId: "01HYFJYTXYHPJTNKP60MRCYRMV" as ServiceId,
serviceName: "Service name",
title: "Message title",
category: {
tag: isFromSend ? SENDTagEnum.PN : TagEnum.PAYMENT
}
} as UIMessage);

const renderComponent = (
message: UIMessage,
serviceId: ServiceId,
addServiceDetailsToReducer: boolean = true
) => {
const renderComponent = (message: UIMessage) => {
const initialState = appReducer(undefined, applicationChangeState("active"));
const designSystemState = appReducer(
initialState,
preferencesDesignSystemSetEnabled({ isDesignSystemEnabled: true })
);
const serviceDetailsAvailableTest = appReducer(
designSystemState,
loadServiceDetail.success({
service_id: serviceId,
department_name: "Dep name",
organization_fiscal_code: "01223580551",
organization_name: "Org name",
service_name: "Serv name",
version: 1
} as ServicePublic)
);
const store = createStore(
appReducer,
(addServiceDetailsToReducer
? serviceDetailsAvailableTest
: designSystemState) as any
);

const store = createStore(appReducer, designSystemState as any);
return renderScreenWithNavigationStoreContext(
() => <WrappedMessageListItem message={message} />,
MESSAGES_ROUTES.MESSAGES_HOME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ exports[`WrappedMessageListItem should match snapshot, from SEND, read mes
<View
collapsable={false}
forwardedRef={[Function]}
handlerTag={6}
handlerTag={4}
handlerType="PanGestureHandler"
needsOffscreenAlphaCompositing={false}
onGestureHandlerEvent={[Function]}
Expand Down Expand Up @@ -1298,7 +1298,7 @@ exports[`WrappedMessageListItem should match snapshot, from SEND, unread mes
<View
collapsable={false}
forwardedRef={[Function]}
handlerTag={5}
handlerTag={3}
handlerType="PanGestureHandler"
needsOffscreenAlphaCompositing={false}
onGestureHandlerEvent={[Function]}
Expand Down Expand Up @@ -2383,7 +2383,7 @@ exports[`WrappedMessageListItem should match snapshot, not from SEND, read mes
<View
collapsable={false}
forwardedRef={[Function]}
handlerTag={4}
handlerTag={2}
handlerType="PanGestureHandler"
needsOffscreenAlphaCompositing={false}
onGestureHandlerEvent={[Function]}
Expand Down Expand Up @@ -3198,7 +3198,7 @@ exports[`WrappedMessageListItem should match snapshot, not from SEND, unread mes
<View
collapsable={false}
forwardedRef={[Function]}
handlerTag={3}
handlerTag={1}
handlerType="PanGestureHandler"
needsOffscreenAlphaCompositing={false}
onGestureHandlerEvent={[Function]}
Expand Down
1 change: 1 addition & 0 deletions ts/features/messages/store/reducers/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const toUIMessage = (
serviceId: messageFromApi.sender_service_id,
serviceName: enriched.service_name,
organizationName: enriched.organization_name,
organizationFiscalCode: enriched.organization_fiscal_code,
title: enriched.message_title,
timeToLive: messageFromApi.time_to_live,
hasPrecondition: enriched.has_precondition ?? false,
Expand Down
1 change: 1 addition & 0 deletions ts/features/messages/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type UIMessage = WithUIMessageId<{
serviceId: ServiceId;
serviceName: string;
organizationName: string;
organizationFiscalCode: string;
title: string;
timeToLive?: TimeToLiveSeconds;
hasPrecondition: boolean;
Expand Down

0 comments on commit 6471059

Please sign in to comment.