Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#ICC-101] Return message read status, if applicable #211

Merged
merged 25 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1887cf3
[#ICC-101] update fn-commons, ts-commons and fix buind and tests
gquadrati Jun 22, 2022
1d59a18
[#ICC-101] wip - messageReadStatusAuth
gquadrati Jun 22, 2022
7176312
[#ICC-101] fix yarn.lock
gquadrati Jun 22, 2022
7f27760
[#ICC-101] update GetMessageHandler with canAccessMessageReadStatus
gquadrati Jun 22, 2022
701e139
[#ICC-101] add semver library
gquadrati Jun 23, 2022
961bd1e
[#ICC-101] add env var MIN_APP_VERSION_WITH_READ_AUTH
gquadrati Jun 23, 2022
6a99ca9
[#ICC-101] implements check based on appversion
gquadrati Jun 23, 2022
d085c3e
[#ICC-101] fix lint errors
gquadrati Jun 23, 2022
adde4cf
[#ICC-101] fix servicePreferencesSettingsVersion
gquadrati Jun 23, 2022
70fa3f2
[#ICC-101] minor changes
gquadrati Jun 23, 2022
1d260fa
[#ICC-101] add unit tests
gquadrati Jun 23, 2022
86f1eba
[#ICC-101] integration tests added
gquadrati Jun 24, 2022
69f51ee
[#ICC-101] update fn-commons
gquadrati Jun 24, 2022
74b3ad1
[#ICC-101] refactor based on comments
gquadrati Jun 24, 2022
ae19c7d
cleaned tests
michaeldisaro Jun 24, 2022
5665e31
[#ICC-101] refactor based on comments
gquadrati Jun 24, 2022
0a46bb7
[#ICC-101] refactor isAppVersionHandlingReadAuthorization, fix error
gquadrati Jun 24, 2022
b0e499c
[#ICC-101] updates based on comments
gquadrati Jun 24, 2022
5b116a0
[#ICC-101] updates based on comments - 2
gquadrati Jun 24, 2022
a6e9bee
[#ICC-101] switch id overriding
gquadrati Jun 27, 2022
3de45ab
[#ICC-101] do not retrieve advanced data for pending messages
gquadrati Jun 27, 2022
8d66473
[#ICC-101] refactor tests and added UNAVAILABLE test
gquadrati Jun 28, 2022
c4cfe21
[#ICC-101] fix isAppVersionHandlingReadAuthorization check
gquadrati Jun 28, 2022
5e411b9
[#ICC-101] added comments based on review
gquadrati Jun 30, 2022
74b17c8
[#ICC-101] fix test titles
gquadrati Jun 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 51 additions & 24 deletions GetMessage/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,26 @@ import { FeatureLevelTypeEnum } from "@pagopa/io-functions-commons/dist/generate

import * as TE from "fp-ts/lib/TaskEither";

import { ReadStatusEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/ReadStatus";

import { GetMessageHandler } from "../handler";

import {
aMessageContentWithLegalData,
aMessagePayload
} from "../../__mocks__/mocks";

// Tests
// -----------------------

describe("GetMessageHandler", () => {
jest.useFakeTimers();

// Read status checker
const mockMessageReadStatusAuth = jest.fn((_serviceId, _fiscalCode) =>
TE.of<Error, boolean>(false)
);

// -----------------------

const mockContext = {
log: {
// eslint-disable-next-line no-console
Expand All @@ -71,11 +80,6 @@ describe("GetMessageHandler", () => {
}
} as any;

afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});

afterAll(() => {
jest.useRealTimers();
});
Expand Down Expand Up @@ -177,7 +181,9 @@ describe("GetMessageHandler", () => {
};

function getNotificationModelMock(
aRetrievedNotification: any = { data: "data" }
aRetrievedNotification: any = {
data: "data"
}
): any {
return {
findNotificationForMessage: jest.fn(() =>
Expand Down Expand Up @@ -233,6 +239,7 @@ describe("GetMessageHandler", () => {
upsert: jest.fn(status => TE.left(status))
};
}

it("should respond with a message if requesting user is the sender", async () => {
const mockMessageModel = {
findMessageForRecipient: jest.fn(() =>
Expand All @@ -246,7 +253,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -283,7 +291,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -318,7 +327,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -359,7 +369,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
{} as any,
{} as any,
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -398,7 +409,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
{} as any,
{} as any,
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -435,7 +447,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
{} as any,
{} as any,
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -472,7 +485,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
{} as any,
{} as any,
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -508,7 +522,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -550,7 +565,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
{} as any,
{} as any,
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -597,7 +613,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(aRetrievedNotification),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -642,7 +659,8 @@ describe("GetMessageHandler", () => {
),
getNotificationModelMock(),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand All @@ -656,6 +674,7 @@ describe("GetMessageHandler", () => {

expect(result.kind).toBe("IResponseErrorInternal");
});

it("should fail if any error occurs trying to retrieve the notification status", async () => {
const mockMessageModel = {
findMessageForRecipient: jest.fn(() =>
Expand All @@ -676,7 +695,8 @@ describe("GetMessageHandler", () => {
)
} as any,
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -738,7 +758,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(aRetrievedNotification),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand Down Expand Up @@ -778,7 +799,8 @@ describe("GetMessageHandler", () => {
getMessageStatusModelMock(),
getNotificationModelMock(aRetrievedNotification),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand All @@ -796,6 +818,7 @@ describe("GetMessageHandler", () => {
aRetrievedMessageWithoutContent.fiscalCode,
aRetrievedMessageWithoutContent.id
);
expect(mockMessageReadStatusAuth).not.toHaveBeenCalled();

expect(result.kind).toBe("IResponseSuccessJson");
if (result.kind === "IResponseSuccessJson") {
Expand All @@ -815,12 +838,15 @@ describe("GetMessageHandler", () => {
getContentFromBlob: jest.fn(() => TE.of(none))
};

mockMessageReadStatusAuth.mockReturnValueOnce(TE.right(true));

const getMessageHandler = GetMessageHandler(
mockMessageModel as any,
getMessageStatusModelMock(),
getNotificationModelMock(aRetrievedNotification),
getNotificationStatusModelMock(),
{} as any
{} as any,
mockMessageReadStatusAuth
);

const result = await getMessageHandler(
Expand All @@ -838,12 +864,13 @@ describe("GetMessageHandler", () => {
aRetrievedMessageWithoutContent.fiscalCode,
aRetrievedMessageWithoutContent.id
);
expect(mockMessageReadStatusAuth).toHaveBeenCalled();

expect(result.kind).toBe("IResponseSuccessJson");
if (result.kind === "IResponseSuccessJson") {
expect(result.value).toEqual({
...aPublicExtendedMessageResponseWithAdvancedFeatures,
read_status: ReadStatusEnum.UNAVAILABLE
read_status: aMessageStatus.isRead ? "READ" : "UNREAD"
});
}
});
Expand Down
Loading