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

[IP-387] Upgrade fp-ts #165

Merged
merged 74 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
1e775ae
update dependencies
balanza Sep 6, 2021
a8edf51
[#ip-387] update utils/orchestrator.tsgst
balanza Sep 6, 2021
9855f22
[#ip-387] update utils/random.tsgst
balanza Sep 6, 2021
3bd2341
[#ip-387] update utils/sessionApiClient.ts
balanza Sep 15, 2021
4c138cb
[#ip-387] update utils/subscription_feed.tsgst
balanza Sep 6, 2021
456f86c
[#ip-387] update utils/middlewaresgst
balanza Sep 6, 2021
22b0e74
[#ip-387] update utils/featureFlags.tsgst
balanza Sep 6, 2021
8a84112
[#ip-387] update utils/extensions/modelsgst
balanza Sep 6, 2021
72f9616
[#ip-387] update utils/conversions.tsgst
balanza Sep 6, 2021
ab1bea7
[#ip-387] [#ip-387] update utils/config.ts
balanza Sep 6, 2021
dc1ef08
[#ip-387] update utils/appinsights.ts
balanza Sep 6, 2021
c801e8f
[#ip-387] update utils/apim.ts
balanza Sep 7, 2021
9048311
[#ip-387] update UserDataProcessingTrigger
balanza Sep 7, 2021
6c77f34
[#ip-387] update UserDataProcessingRecoveryOrchestrator
balanza Sep 7, 2021
39f9233
[#ip-387] update UserDataProcessingProcessFailedRecords
balanza Sep 7, 2021
41b4f13
[#ip-387] update UserDataProcessingFindFailureReasonActivity
balanza Sep 7, 2021
1e31b83
[#ip-387] update __mocks__
balanza Sep 7, 2021
13aa5b7
[#ip-387] update UserDataProcessingCheckLastStatusActivity
balanza Sep 7, 2021
765e2d3
[#ip-387] update UserDataDownloadOrchestrator
balanza Sep 7, 2021
188e43a
[#ip-387] update UserDataDeleteOrchestratorV2
balanza Sep 7, 2021
ea02635
[#ip-387] update UserDataDeleteOrchestrator
balanza Sep 7, 2021
16f6a9c
[#ip-387] update UpsertServiceOrchestrator
balanza Sep 7, 2021
b2e4444
[#ip-387] update UploadServiceLogo
balanza Sep 9, 2021
a45bb84
[#ip-387] [#ip-387] update UploadOrganizationLogo
balanza Sep 9, 2021
214ca59
[#ip-387] update UpdateVisibleServicesCacheOrchestrator
balanza Sep 9, 2021
f36fd76
[#ip-387] update UpdateVisibleServicesCacheActivity
balanza Sep 9, 2021
4d7a482
[#ip-387] update UpdateVisibleServicesCache
balanza Sep 9, 2021
743baa3
[#ip-387] [#ip-387] update UpdateVisibleServicesActivity
balanza Sep 9, 2021
c33b8d0
[#ip-387] update UpdateUserGroups
balanza Sep 9, 2021
ad5ae4b
[#ip-387] update UpdateUser
balanza Sep 9, 2021
18b3fa1
[#ip-387] update UpdateSubscriptionsFeedActivity
balanza Sep 9, 2021
c7bbf1d
[#ip-387] update UpdateService
balanza Sep 9, 2021
c0fd570
[#ip-387] update SetUserSessionLockActivity
balanza Sep 9, 2021
bca6339
[#ip-387] update SetUserDataProcessingStatusActivity
balanza Sep 9, 2021
5bf8390
[#ip-387] update SetUserDataProcessingStatus
balanza Sep 9, 2021
263496f
[#ip-387] update SendUserDataDownloadMessageActivity
balanza Sep 9, 2021
317a0a1
[#ip-387] update SendUserDataDeleteEmailActivity
balanza Sep 10, 2021
22feac6
[#ip-387] update RegenerateSubscriptionKeys
balanza Sep 10, 2021
1fa1cac
[#ip-387] update IsFailedUserDataProcessingActivity
balanza Sep 10, 2021
db18172
[#ip-387] update Info
balanza Sep 10, 2021
23fce0c
[#ip-387] update GetUsers
balanza Sep 10, 2021
8191a8c
[#ip-387] update GetUserDataProcessingActivity
balanza Sep 10, 2021
99b3662
[#ip-387] update GetUser
balanza Sep 13, 2021
6dbeb14
[#ip-387] update GetSubscriptionKeys
balanza Sep 13, 2021
c126814
[#ip-387] update GetServicesPreferencesActivity
balanza Sep 13, 2021
d2b2dba
[#ip-387] update GetServices
balanza Sep 13, 2021
3de1e20
[#ip-387] update GetService
balanza Sep 13, 2021
9089b48
[#ip-387] update GetProfileActivity
balanza Sep 13, 2021
69ac9a0
[#ip-387] update GetFailedUserDataProcessingList
balanza Sep 13, 2021
730d10f
[#ip-387] update GetFailedUserDataProcessing
balanza Sep 13, 2021
b849aab
[#ip-387] update ExtractUserDataActivity
balanza Sep 13, 2021
4d8efe1
[#ip-387] [#ip-387] update DeleteUserDataActivity
balanza Sep 13, 2021
78a0951
[#ip-387] update CreateUser
balanza Sep 13, 2021
68ae861
[#ip-387] update CreateSubscription
balanza Sep 14, 2021
1b9c198
[#ip-387] update CreateService
balanza Sep 14, 2021
b76131d
[#ip-387] update CreateDevelopmentProfile
balanza Sep 14, 2021
f78dd8d
[#ip-387] fix after review
balanza Sep 15, 2021
1c8838d
fix after review
balanza Sep 15, 2021
80cd1c6
fix after review
balanza Sep 15, 2021
18d69f9
[#ip-387] fix after review
balanza Sep 15, 2021
7b2b7e0
[#ip-387] lint fix
balanza Sep 15, 2021
1381aae
[#ip-387] fix after review
balanza Sep 15, 2021
afa6858
[#ip-387] fix after review
balanza Sep 15, 2021
0eb3db8
[#ip-387] fix after review
balanza Sep 15, 2021
67fd68c
[#ip-387] fix after review
balanza Sep 15, 2021
179c051
[#ip-387] Revert "fix after review"
balanza Sep 16, 2021
409be2e
[#ip-387] [#ip-387] fix after review
balanza Sep 16, 2021
e44eb01
[#ip-387] fix after review
balanza Sep 16, 2021
928cf9c
[#ip-387] fix after review
balanza Sep 16, 2021
f2418a3
[#ip-387] fix after review
balanza Sep 17, 2021
1ecf36d
[#ip-387] fix after review
balanza Sep 17, 2021
4470544
[#ip-387] fix after review
balanza Sep 17, 2021
2c8dd17
[#ip-387] [#ip-387] fix after review
balanza Sep 20, 2021
b4441e9
Merge branch 'master' into ip-387--upgrade-fp-ts
Sep 21, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
} from "../handler";

import { none, some } from "fp-ts/lib/Option";
import { fromEither, fromLeft } from "fp-ts/lib/TaskEither";
import * as TE from "fp-ts/lib/TaskEither";
import * as E from "fp-ts/lib/Either";
import { UserDataProcessingModel } from "@pagopa/io-functions-commons/dist/src/models/user_data_processing";
import { toCosmosErrorResponse } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model";

Expand All @@ -26,7 +27,7 @@ describe("UserDataProcessingCheckLastStatusActivity", () => {
it("should handle a result", async () => {
const mockModel = ({
findLastVersionByModelId: jest.fn(() =>
fromEither(right(some(aUserDataProcessing)))
TE.fromEither(right(some(aUserDataProcessing)))
)
} as any) as UserDataProcessingModel;

Expand All @@ -40,16 +41,18 @@ describe("UserDataProcessingCheckLastStatusActivity", () => {
const result = await handler(contextMock, input);

const decodedResult = ActivityResultSuccess.decode(result);
expect(decodedResult.isRight()).toBe(true);
expect(decodedResult.value).toEqual({
kind: "SUCCESS",
value: aUserDataProcessingStatus
});
expect(E.isRight(decodedResult)).toBe(true);
if (E.isRight(decodedResult)) {
expect(decodedResult.right).toEqual({
kind: "SUCCESS",
value: aUserDataProcessingStatus
});
}
});

it("should handle a record not found failure", async () => {
const mockModel = ({
findLastVersionByModelId: jest.fn(() => fromEither(right(none)))
findLastVersionByModelId: jest.fn(() => TE.fromEither(right(none)))
} as any) as UserDataProcessingModel;

const handler = createUserDataProcessingCheckLastStatusActivityHandler(
Expand All @@ -61,13 +64,13 @@ describe("UserDataProcessingCheckLastStatusActivity", () => {
};
const result = await handler(contextMock, input);

expect(ActivityResultNotFoundFailure.decode(result).isRight()).toBe(true);
expect(E.isRight(ActivityResultNotFoundFailure.decode(result))).toBe(true);
});

it("should handle a query error", async () => {
const mockModel = ({
findLastVersionByModelId: jest.fn(() =>
fromLeft(toCosmosErrorResponse({ kind: "COSMOS_ERROR_RESPONSE" }))
TE.left(toCosmosErrorResponse({ kind: "COSMOS_ERROR_RESPONSE" }))
)
} as any) as UserDataProcessingModel;

Expand All @@ -80,12 +83,12 @@ describe("UserDataProcessingCheckLastStatusActivity", () => {
};
const result = await handler(contextMock, input);

expect(ActivityResultQueryFailure.decode(result).isRight()).toBe(true);
expect(E.isRight(ActivityResultQueryFailure.decode(result))).toBe(true);
});

it("should handle a rejection", async () => {
const mockModel = ({
findLastVersionByModelId: jest.fn(() => fromEither(right(none)))
findLastVersionByModelId: jest.fn(() => TE.fromEither(right(none)))
} as any) as UserDataProcessingModel;

const handler = createUserDataProcessingCheckLastStatusActivityHandler(
Expand All @@ -97,7 +100,7 @@ describe("UserDataProcessingCheckLastStatusActivity", () => {
};
const result = await handler(contextMock, input);

expect(ActivityResultNotFoundFailure.decode(result).isRight()).toBe(true);
expect(E.isRight(ActivityResultNotFoundFailure.decode(result))).toBe(true);
});

it("should handle an invalid input", async () => {
Expand All @@ -112,7 +115,7 @@ describe("UserDataProcessingCheckLastStatusActivity", () => {
invalid: "input"
});

expect(ActivityResultInvalidInputFailure.decode(result).isRight()).toBe(
expect(E.isRight(ActivityResultInvalidInputFailure.decode(result))).toBe(
true
);
});
Expand Down
66 changes: 35 additions & 31 deletions UserDataProcessingCheckLastStatusActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
} from "@pagopa/io-functions-commons/dist/src/models/user_data_processing";
import { readableReport } from "@pagopa/ts-commons/lib/reporters";
import { FiscalCode } from "@pagopa/ts-commons/lib/strings";
import { identity } from "fp-ts/lib/function";
import { fromEither, fromLeft, taskEither } from "fp-ts/lib/TaskEither";
import { flow, pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import * as E from "fp-ts/lib/Either";
import * as TE from "fp-ts/lib/TaskEither";
import * as t from "io-ts";
import { getMessageFromCosmosErrors } from "../utils/conversions";

Expand Down Expand Up @@ -75,45 +77,47 @@ export const createUserDataProcessingCheckLastStatusActivityHandler = (
_: Context,
input: unknown
): Promise<ActivityResult> =>
fromEither(ActivityInput.decode(input))
.mapLeft<ActivityResultFailure>((reason: t.Errors) =>
pipe(
input,
ActivityInput.decode,
E.mapLeft((reason: t.Errors) =>
ActivityResultInvalidInputFailure.encode({
kind: "INVALID_INPUT_FAILURE",
reason: readableReport(reason)
})
)
.chain(({ choice, fiscalCode }) =>
userDataProcessingModel
.findLastVersionByModelId([
),
TE.fromEither,
TE.chainW(({ choice, fiscalCode }) =>
pipe(
userDataProcessingModel.findLastVersionByModelId([
makeUserDataProcessingId(choice, fiscalCode),
fiscalCode
])
.foldTaskEither<ActivityResultFailure, UserDataProcessingStatus>(
error =>
fromLeft(
ActivityResultQueryFailure.encode({
kind: "QUERY_FAILURE",
query: "findOneUserDataProcessingById",
reason: `${error.kind}, ${getMessageFromCosmosErrors(error)}`
]),
TE.mapLeft(error =>
ActivityResultQueryFailure.encode({
kind: "QUERY_FAILURE",
query: "findOneUserDataProcessingById",
reason: `${error.kind}, ${getMessageFromCosmosErrors(error)}`
})
),
TE.chainW(
flow(
O.map(r => r.status),
E.fromOption(() =>
ActivityResultNotFoundFailure.encode({
kind: "NOT_FOUND_FAILURE"
})
balanza marked this conversation as resolved.
Show resolved Hide resolved
),
maybeRecord =>
maybeRecord.fold(
fromLeft(
ActivityResultNotFoundFailure.encode({
kind: "NOT_FOUND_FAILURE"
})
),
r => taskEither.of(r.status)
)
TE.fromEither
balanza marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
.map(status =>
)
),
TE.map(status =>
ActivityResultSuccess.encode({
kind: "SUCCESS",
value: status
})
)
.mapLeft(identity)
.run()
.then(e => e.value);
balanza marked this conversation as resolved.
Show resolved Hide resolved
),
TE.toUnion
)();
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { right } from "fp-ts/lib/Either";
import { context as contextMock } from "../../__mocks__/functions";
import {
aFiscalCode,
aUserDataProcessing,
aUserDataProcessingStatus
} from "../../__mocks__/mocks";
import { aFiscalCode, aUserDataProcessing } from "../../__mocks__/mocks";

import {
ActivityInput,
ActivityResultInvalidInputFailure,
ActivityResultNotFoundFailure,
ActivityResultQueryFailure,
ActivityResultSuccess,
getFindFailureReasonActivityHandler
} from "../handler";

import { none, some } from "fp-ts/lib/Option";
import { fromEither, fromLeft } from "fp-ts/lib/TaskEither";
import * as E from "fp-ts/lib/Either";
import { UserDataProcessingModel } from "@pagopa/io-functions-commons/dist/src/models/user_data_processing";
import { toCosmosErrorResponse } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model";
import { DurableOrchestrationStatus } from "durable-functions/lib/src/durableorchestrationstatus";

const aChoice = aUserDataProcessing.choice;
Expand Down Expand Up @@ -59,11 +51,13 @@ describe("UserDataProcessingFindFailureReasonActivity", () => {
);

const decodedResult = ActivityResultSuccess.decode(result);
expect(decodedResult.isRight()).toBe(true);
expect(decodedResult.value).toEqual({
kind: "SUCCESS",
value: JSON.stringify(failedOrchestratorOutput, (key, value) => value)
});
expect(E.isRight(decodedResult)).toBe(true);
if (E.isRight(decodedResult)) {
expect(decodedResult.right).toEqual({
kind: "SUCCESS",
value: JSON.stringify(failedOrchestratorOutput, (key, value) => value)
});
}
});

it("should handle a record not found failure", async () => {
Expand All @@ -82,7 +76,7 @@ describe("UserDataProcessingFindFailureReasonActivity", () => {
input
);

expect(ActivityResultNotFoundFailure.decode(result).isRight()).toBe(true);
expect(E.isRight(ActivityResultNotFoundFailure.decode(result))).toBe(true);
});

it("should handle an invalid input", async () => {
Expand All @@ -93,7 +87,7 @@ describe("UserDataProcessingFindFailureReasonActivity", () => {
invalid: "input"
});

expect(ActivityResultInvalidInputFailure.decode(result).isRight()).toBe(
expect(E.isRight(ActivityResultInvalidInputFailure.decode(result))).toBe(
true
);
});
Expand Down
56 changes: 31 additions & 25 deletions UserDataProcessingFindFailureReasonActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from "@pagopa/io-functions-commons/dist/generated/definitions/UserDataProcessingChoice";
import { FiscalCode, NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import * as t from "io-ts";
import { fromEither, tryCatch } from "fp-ts/lib/TaskEither";
import { identity } from "fp-ts/lib/function";
import { fromNullable } from "fp-ts/lib/Either";
import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/function";
import * as E from "fp-ts/lib/Either";
import { makeOrchestratorId as makeDownloadOrchestratorId } from "../UserDataDownloadOrchestrator/utils";
import { makeOrchestratorId as makeDeleteOrchestratorId } from "../UserDataDeleteOrchestrator/utils";

Expand Down Expand Up @@ -82,48 +82,54 @@ export type ActivityResult = t.TypeOf<typeof ActivityResult>;
export const getFindFailureReasonActivityHandler = async (
context: Context,
input: unknown
): Promise<ActivityResult> => {
const client = df.getClient(context);

return fromEither(ActivityInput.decode(input))
.mapLeft(_ =>
): Promise<ActivityResult> =>
pipe(
input,
ActivityInput.decode,
TE.fromEither,
TE.mapLeft(_ =>
ActivityResultFailure.encode({
kind: "INVALID_INPUT_FAILURE",
reason: "Input not valid for this activity"
})
)
.chain(({ choice, fiscalCode }) => {
),
TE.chain(({ choice, fiscalCode }) => {
// create failed orchestrator id based on choice
const failedUserDataProcessingOrchestratorId =
choice === UserDataProcessingChoiceEnum.DELETE
? makeDeleteOrchestratorId(fiscalCode)
: makeDownloadOrchestratorId(fiscalCode);

return tryCatch(
return TE.tryCatch(
() =>
// get the status of the failed orchestrator
client.getStatus(failedUserDataProcessingOrchestratorId),
df
.getClient(context)
.getStatus(failedUserDataProcessingOrchestratorId),
() =>
ActivityResultFailure.encode({
kind: "NOT_FOUND_FAILURE"
})
);
})
.fold(identity, orchestratorStatus =>
fromNullable("No reason found")(orchestratorStatus.output)
.map(o =>
}),
TE.map(orchestratorStatus =>
pipe(
orchestratorStatus.output,
E.fromNullable("No reason found"),
E.map(o =>
ActivityResultSuccess.encode({
kind: "SUCCESS",
value: JSON.stringify(o, (key, value) => value) as NonEmptyString
value: JSON.stringify(o, (_, value) => value) as NonEmptyString
})
)
.mapLeft(e =>
),
E.mapLeft(e =>
ActivityResultSuccess.encode({
kind: "SUCCESS",
value: JSON.stringify(e, (key, value) => value) as NonEmptyString
value: JSON.stringify(e, (_, value) => value) as NonEmptyString
})
)
.fold<ActivityResult>(identity, identity)
)
.run();
};
),
E.toUnion
)
),
TE.toUnion
)();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UserDataProcessingStatusEnum } from "@pagopa/io-functions-commons/dist/
import { FiscalCode } from "@pagopa/ts-commons/lib/strings";
import { processFailedUserDataProcessingHandler } from "../handler";
import { SqlQuerySpec, FeedOptions } from "@azure/cosmos";
import { tryCatch2v } from "fp-ts/lib/Either";
import * as E from "fp-ts/lib/Either";
import { Branded } from "io-ts";
import { NonNegativeInteger } from "@pagopa/ts-commons/lib/numbers";
import * as t from "io-ts";
Expand Down Expand Up @@ -137,7 +137,7 @@ const recordsIterator = (query: string | SqlQuerySpec) => ({
// and keep the asynchrounous behaviour
await new Promise(resolve => setTimeout(resolve, 100));
yield [
tryCatch2v(
E.tryCatch(
() =>
recordMock(
record.choice,
Expand Down
Loading