Skip to content

Commit

Permalink
[#IOPAE-87] change reference (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
balanza authored Dec 2, 2022
1 parent 843a26f commit 7d9dab4
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 50 deletions.
4 changes: 2 additions & 2 deletions CreateLegalMessage/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { Context } from "@azure/functions";
import { CreateLegalMessageHandler } from "../handler";
import { getLogger, ILogger } from "../../utils/logging";
import { ILegalMessageMapModel } from "../../utils/legal-message";
import { ServiceId } from "../../generated/api-admin/ServiceId";
import { ServiceId } from "@pagopa/io-functions-admin-sdk/ServiceId";
import {
EmailString,
NonEmptyString,
OrganizationFiscalCode
} from "@pagopa/ts-commons/lib/strings";
import { APIClient } from "../../clients/admin";
import { UserGroup } from "@pagopa/io-functions-commons/dist/src/utils/middlewares/azure_api_auth";
import { ImpersonatedService } from "../../generated/api-admin/ImpersonatedService";
import { ImpersonatedService } from "@pagopa/io-functions-admin-sdk/ImpersonatedService";
import {
ResponseErrorInternal,
ResponseErrorNotFound,
Expand Down
2 changes: 1 addition & 1 deletion CreateLegalMessage/impersonate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as TE from "fp-ts/lib/TaskEither";
import { ImpersonatedService } from "@pagopa/io-functions-admin-sdk/ImpersonatedService";
import { APIClient } from "../clients/admin";
import { ImpersonatedService } from "../generated/api-admin/ImpersonatedService";
import { withApiRequestWrapper } from "../utils/api";
import { ILogger } from "../utils/logging";
import { ErrorResponses } from "../utils/responses";
Expand Down
4 changes: 2 additions & 2 deletions CreateService/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
ServiceMetadata
} from "@pagopa/io-functions-commons/dist/src/models/service";
import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { Subscription } from "../../generated/api-admin/Subscription";
import { UserInfo } from "../../generated/api-admin/UserInfo";
import { Subscription } from "@pagopa/io-functions-admin-sdk/Subscription";
import { UserInfo } from "@pagopa/io-functions-admin-sdk/UserInfo";
import { ServicePayload } from "../../generated/definitions/ServicePayload";
import {
CreateServiceHandler,
Expand Down
8 changes: 4 additions & 4 deletions CreateService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ import {
} from "@pagopa/ts-commons/lib/strings";
import { pipe } from "fp-ts/lib/function";
import { sequenceS } from "fp-ts/lib/Apply";
import { Service } from "@pagopa/io-functions-admin-sdk/Service";
import { Subscription } from "@pagopa/io-functions-admin-sdk/Subscription";
import { UserInfo } from "@pagopa/io-functions-admin-sdk/UserInfo";
import { StandardServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/StandardServiceCategory";
import { APIClient } from "../clients/admin";
import { Service } from "../generated/api-admin/Service";
import { Subscription } from "../generated/api-admin/Subscription";
import { UserInfo } from "../generated/api-admin/UserInfo";
import { ServicePayload } from "../generated/definitions/ServicePayload";
import { ServiceWithSubscriptionKeys } from "../generated/definitions/ServiceWithSubscriptionKeys";
import { withApiRequestWrapper } from "../utils/api";
import { getLogger, ILogger } from "../utils/logging";
import { ErrorResponses, IResponseErrorUnauthorized } from "../utils/responses";
import { StandardServiceCategoryEnum } from "../generated/api-admin/StandardServiceCategory";

type ResponseTypes =
| IResponseSuccessJson<ServiceWithSubscriptionKeys>
Expand Down
2 changes: 1 addition & 1 deletion EmailNotification/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
NotificationModel,
RetrievedNotification
} from "@pagopa/io-functions-commons/dist/src/models/notification";
import { StandardServiceCategoryEnum } from "../../generated/api-admin/StandardServiceCategory";
import { StandardServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/StandardServiceCategory";

beforeEach(() => jest.clearAllMocks());

Expand Down
4 changes: 2 additions & 2 deletions GetService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { ContextMiddleware } from "@pagopa/io-functions-commons/dist/src/utils/m
import { pipe } from "fp-ts/lib/function";
import { TaskEither } from "fp-ts/lib/TaskEither";
import * as TE from "fp-ts/lib/TaskEither";
import { Service } from "@pagopa/io-functions-admin-sdk/Service";
import { SubscriptionKeys } from "@pagopa/io-functions-admin-sdk/SubscriptionKeys";
import { APIClient } from "../clients/admin";
import { Service } from "../generated/api-admin/Service";
import { SubscriptionKeys } from "../generated/api-admin/SubscriptionKeys";
import { ServiceWithSubscriptionKeys } from "../generated/definitions/ServiceWithSubscriptionKeys";
import { withApiRequestWrapper } from "../utils/api";
import { getLogger, ILogger } from "../utils/logging";
Expand Down
36 changes: 22 additions & 14 deletions GetUserServices/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { MaxAllowedPaymentAmount } from "@pagopa/io-functions-commons/dist/gener

import { left, right } from "fp-ts/lib/Either";
import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { Subscription } from "../../generated/api-admin/Subscription";
import { UserInfo } from "../../generated/api-admin/UserInfo";
import { Subscription } from "@pagopa/io-functions-admin-sdk/Subscription";
import { UserInfo } from "@pagopa/io-functions-admin-sdk/UserInfo";
import { GetUserServicesHandler } from "../handler";

const mockContext = {
Expand Down Expand Up @@ -91,7 +91,7 @@ const aUserAuthenticationDeveloper: IAzureApiAuthorization = {
describe("GetUserServicesHandler", () => {
it("should respond with a list of serviceId if requesting user is the owner", async () => {
const apiClientMock = {
getUser: jest.fn(() =>
getUserSubscriptions: jest.fn(() =>
Promise.resolve(right({ status: 200, value: aUserInfo }))
)
};
Expand All @@ -104,7 +104,7 @@ describe("GetUserServicesHandler", () => {
someUserAttributes
);

expect(apiClientMock.getUser).toHaveBeenCalledTimes(1);
expect(apiClientMock.getUserSubscriptions).toHaveBeenCalledTimes(1);
expect(result.kind).toBe("IResponseSuccessJson");
if (result.kind === "IResponseSuccessJson") {
expect(result.value).toEqual({
Expand All @@ -115,7 +115,7 @@ describe("GetUserServicesHandler", () => {

it("should respond with an internal error if getUser does not respond", async () => {
const apiClientMock = {
getUser: jest.fn(() => Promise.reject(new Error("Timeout")))
getUserSubscriptions: jest.fn(() => Promise.reject(new Error("Timeout")))
};

const getUserServicesHandler = GetUserServicesHandler(apiClientMock as any);
Expand All @@ -126,14 +126,16 @@ describe("GetUserServicesHandler", () => {
someUserAttributes
);

expect(apiClientMock.getUser).toHaveBeenCalledTimes(1);
expect(apiClientMock.getUserSubscriptions).toHaveBeenCalledTimes(1);

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

it("should respond with an internal error if getService returns Errors", async () => {
const apiClientMock = {
getUser: jest.fn(() => Promise.resolve(left({ err: "ValidationError" })))
getUserSubscriptions: jest.fn(() =>
Promise.resolve(left({ err: "ValidationError" }))
)
};

jest
Expand All @@ -147,14 +149,16 @@ describe("GetUserServicesHandler", () => {
someUserAttributes
);

expect(apiClientMock.getUser).toHaveBeenCalledTimes(1);
expect(apiClientMock.getUserSubscriptions).toHaveBeenCalledTimes(1);

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

it("should respond with Not found if no user was found", async () => {
const apiClientMock = {
getUser: jest.fn(() => Promise.resolve(right({ status: 404 })))
getUserSubscriptions: jest.fn(() =>
Promise.resolve(right({ status: 404 }))
)
};

const getUserServicesHandler = GetUserServicesHandler(apiClientMock as any);
Expand All @@ -165,7 +169,7 @@ describe("GetUserServicesHandler", () => {
someUserAttributes
);

expect(apiClientMock.getUser).toHaveBeenCalledTimes(1);
expect(apiClientMock.getUserSubscriptions).toHaveBeenCalledTimes(1);

expect(result.kind).toBe("IResponseErrorNotFound");
if (result.kind === "IResponseErrorNotFound") {
Expand All @@ -175,7 +179,9 @@ describe("GetUserServicesHandler", () => {

it("should respond with an internal error if getUser returns Bad request", async () => {
const apiClientMock = {
getUser: jest.fn(() => Promise.resolve(right({ status: 400 })))
getUserSubscriptions: jest.fn(() =>
Promise.resolve(right({ status: 400 }))
)
};

const getUserServicesHandler = GetUserServicesHandler(apiClientMock as any);
Expand All @@ -186,14 +192,16 @@ describe("GetUserServicesHandler", () => {
someUserAttributes
);

expect(apiClientMock.getUser).toHaveBeenCalledTimes(1);
expect(apiClientMock.getUserSubscriptions).toHaveBeenCalledTimes(1);

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

it("should respond with forbidden if getUser returns Forbidden", async () => {
const apiClientMock = {
getUser: jest.fn(() => Promise.resolve(right({ status: 403 })))
getUserSubscriptions: jest.fn(() =>
Promise.resolve(right({ status: 403 }))
)
};

const getUserServicesHandler = GetUserServicesHandler(apiClientMock as any);
Expand All @@ -204,7 +212,7 @@ describe("GetUserServicesHandler", () => {
someUserAttributes
);

expect(apiClientMock.getUser).toHaveBeenCalledTimes(1);
expect(apiClientMock.getUserSubscriptions).toHaveBeenCalledTimes(1);

expect(result.kind).toBe("IResponseErrorForbiddenNotAuthorized");
});
Expand Down
4 changes: 2 additions & 2 deletions GetUserServices/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import { ContextMiddleware } from "@pagopa/io-functions-commons/dist/src/utils/m
import { pipe } from "fp-ts/lib/function";
import * as TE from "fp-ts/lib/TaskEither";
import { TaskEither } from "fp-ts/lib/TaskEither";
import { UserInfo } from "@pagopa/io-functions-admin-sdk/UserInfo";
import { APIClient } from "../clients/admin";
import { UserInfo } from "../generated/api-admin/UserInfo";
import { ServiceIdCollection } from "../generated/definitions/ServiceIdCollection";
import { withApiRequestWrapper } from "../utils/api";
import { getLogger, ILogger } from "../utils/logging";
Expand Down Expand Up @@ -65,7 +65,7 @@ const getUserTask = (
withApiRequestWrapper(
logger,
() =>
apiClient.getUser({
apiClient.getUserSubscriptions({
email: userEmail
}),
200
Expand Down
2 changes: 1 addition & 1 deletion ProcessMessage/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import * as TE from "fp-ts/lib/TaskEither";
import { TaskEither } from "fp-ts/lib/TaskEither";
import { RejectionReasonEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/RejectionReason";
import { Ttl } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model_ttl";
import { SpecialServiceCategoryEnum } from "../generated/api-admin/SpecialServiceCategory";
import { SpecialServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/SpecialServiceCategory";
import { LegalData } from "../generated/definitions/LegalData";
import { PaymentData } from "../generated/definitions/PaymentData";
import { ThirdPartyData } from "../generated/definitions/ThirdPartyData";
Expand Down
4 changes: 2 additions & 2 deletions RegenerateServiceKey/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { MaxAllowedPaymentAmount } from "@pagopa/io-functions-commons/dist/gener

import { left, right } from "fp-ts/lib/Either";
import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { SubscriptionKeyTypeEnum } from "../../generated/api-admin/SubscriptionKeyType";
import { SubscriptionKeyTypePayload } from "../../generated/api-admin/SubscriptionKeyTypePayload";
import { SubscriptionKeyTypeEnum } from "@pagopa/io-functions-admin-sdk/SubscriptionKeyType";
import { SubscriptionKeyTypePayload } from "@pagopa/io-functions-admin-sdk/SubscriptionKeyTypePayload";
import { RegenerateServiceKeyHandler } from "../handler";

const mockContext = {
Expand Down
6 changes: 3 additions & 3 deletions UpdateService/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { MaxAllowedPaymentAmount } from "@pagopa/io-functions-commons/dist/gener
import { left, right } from "fp-ts/lib/Either";
import { ServiceScopeEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/ServiceScope";
import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { Service } from "../../generated/api-admin/Service";
import { Subscription } from "../../generated/api-admin/Subscription";
import { UserInfo } from "../../generated/api-admin/UserInfo";
import { Service } from "@pagopa/io-functions-admin-sdk/Service";
import { Subscription } from "@pagopa/io-functions-admin-sdk/Subscription";
import { UserInfo } from "@pagopa/io-functions-admin-sdk/UserInfo";
import { ServicePayload } from "../../generated/definitions/ServicePayload";
import { UpdateServiceHandler } from "../handler";
import { StandardServiceCategoryEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/StandardServiceCategory";
Expand Down
12 changes: 6 additions & 6 deletions UpdateService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ import * as TE from "fp-ts/lib/TaskEither";
import { initAppInsights } from "@pagopa/ts-commons/lib/appinsights";
import { EmailString, NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import { pipe } from "fp-ts/lib/function";
import { Service } from "@pagopa/io-functions-admin-sdk/Service";
import { SubscriptionKeys } from "@pagopa/io-functions-admin-sdk/SubscriptionKeys";
import { UserInfo } from "@pagopa/io-functions-admin-sdk/UserInfo";
import { StandardServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/StandardServiceCategory";
import { SpecialServiceMetadata } from "@pagopa/io-functions-admin-sdk/SpecialServiceMetadata";
import { SpecialServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/SpecialServiceCategory";
import { APIClient } from "../clients/admin";
import { Service } from "../generated/api-admin/Service";
import { SubscriptionKeys } from "../generated/api-admin/SubscriptionKeys";
import { UserInfo } from "../generated/api-admin/UserInfo";
import { ServicePayload } from "../generated/definitions/ServicePayload";
import { ServiceWithSubscriptionKeys } from "../generated/definitions/ServiceWithSubscriptionKeys";
import { withApiRequestWrapper } from "../utils/api";
import { getLogger, ILogger } from "../utils/logging";
import { ErrorResponses, IResponseErrorUnauthorized } from "../utils/responses";
import { serviceOwnerCheckTask } from "../utils/subscription";
import { StandardServiceCategoryEnum } from "../generated/api-admin/StandardServiceCategory";
import { SpecialServiceMetadata } from "../generated/api-admin/SpecialServiceMetadata";
import { SpecialServiceCategoryEnum } from "../generated/api-admin/SpecialServiceCategory";

type ResponseTypes =
| IResponseSuccessJson<ServiceWithSubscriptionKeys>
Expand Down
2 changes: 1 addition & 1 deletion UploadOrganizationLogo/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { MaxAllowedPaymentAmount } from "@pagopa/io-functions-commons/dist/gener

import { left, right } from "fp-ts/lib/Either";
import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { Logo } from "../../generated/api-admin/Logo";
import { Logo } from "@pagopa/io-functions-admin-sdk/Logo";
import { UploadOrganizationLogoHandler } from "../handler";

const mockContext = {
Expand Down
2 changes: 1 addition & 1 deletion UploadOrganizationLogo/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import { RequiredBodyPayloadMiddleware } from "@pagopa/io-functions-commons/dist
import { TaskEither } from "fp-ts/lib/TaskEither";
import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/function";
import { Logo } from "@pagopa/io-functions-admin-sdk/Logo";
import { APIClient } from "../clients/admin";
import { Logo } from "../generated/api-admin/Logo";
import { withApiRequestWrapper } from "../utils/api";
import { getLogger, ILogger } from "../utils/logging";
import {
Expand Down
2 changes: 1 addition & 1 deletion UploadServiceLogo/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { MaxAllowedPaymentAmount } from "@pagopa/io-functions-commons/dist/gener

import { left, right } from "fp-ts/lib/Either";
import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { Logo } from "../../generated/api-admin/Logo";
import { Logo } from "@pagopa/io-functions-admin-sdk/Logo";
import { UploadServiceLogoHandler } from "../handler";

const mockContext = {
Expand Down
2 changes: 1 addition & 1 deletion UploadServiceLogo/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import { RequiredBodyPayloadMiddleware } from "@pagopa/io-functions-commons/dist
import { pipe } from "fp-ts/lib/function";
import { TaskEither } from "fp-ts/lib/TaskEither";
import * as TE from "fp-ts/lib/TaskEither";
import { Logo } from "@pagopa/io-functions-admin-sdk/Logo";
import { APIClient } from "../clients/admin";
import { Logo } from "../generated/api-admin/Logo";
import { withApiRequestWrapper } from "../utils/api";
import { getLogger, ILogger } from "../utils/logging";
import { ErrorResponses, IResponseErrorUnauthorized } from "../utils/responses";
Expand Down
2 changes: 1 addition & 1 deletion WebhookNotification/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { Millisecond } from "@pagopa/ts-commons/lib/units";
import * as E from "fp-ts/lib/Either";
import * as TE from "fp-ts/lib/TaskEither";
import * as O from "fp-ts/lib/Option";
import { StandardServiceCategoryEnum } from "../../generated/api-admin/StandardServiceCategory";
import { StandardServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/StandardServiceCategory";

import { toInternalError, toNotFoundError } from "../../utils/domain-errors";
import { UserProfileReader } from "../../readers/user-profile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ResponseErrorInternal } from "@pagopa/ts-commons/lib/responses";
import { ResponseErrorNotFound } from "@pagopa/ts-commons/lib/responses";
import * as TE from "fp-ts/lib/TaskEither";
import { APIClient } from "../clients/admin";
import { ImpersonatedService } from "../generated/api-admin/ImpersonatedService";
import { ImpersonatedService } from "@pagopa/io-functions-admin-sdk/ImpersonatedService";
import { ILogger } from "../utils/logging";
import { ErrorResponses } from "../utils/responses";

Expand Down
2 changes: 1 addition & 1 deletion clients/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@pagopa/ts-commons/lib/fetch";
import { Millisecond } from "@pagopa/ts-commons/lib/units";
import nodeFetch from "node-fetch";
import { createClient } from "../generated/api-admin/client";
import { createClient } from "@pagopa/io-functions-admin-sdk/client";

import { getConfigOrThrow } from "../utils/config";

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"generate": "npm-run-all generate:*",
"generate:definitions": "rimraf ./generated/definitions && shx mkdir -p ./generated/definitions && gen-api-models --api-spec ./openapi/index.yaml --no-strict --out-dir ./generated/definitions",
"generate:api-notifications": "rimraf ./generated/notifications && shx mkdir -p ./generated/notifications && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-backend/master/api_notifications.yaml --out-dir ./generated/notifications --response-decoders --request-types",
"generate:api-admin": "rimraf generated/api-admin && shx mkdir -p generated/api-admin && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-functions-admin/master/openapi/index.yaml --no-strict --out-dir generated/api-admin --request-types --response-decoders --client",
"generate:payment-updater": "rimraf generated/payment-updater && shx mkdir -p generated/payment-updater && gen-api-models --api-spec ./openapi/payment-updater.yaml --no-strict --out-dir ./generated/payment-updater --request-types --response-decoders --client",
"openapi:bundle": "bundle-api-spec -i openapi/index.yaml.template -o openapi/index.yaml -V $npm_package_version",
"openapi:validate": "oval validate -p openapi/index.yaml",
Expand Down Expand Up @@ -63,6 +62,7 @@
"dependencies": {
"@azure/cosmos": "^3.17.1",
"@pagopa/express-azure-functions": "^2.0.0",
"@pagopa/io-functions-admin-sdk": "^0.31.0",
"@pagopa/io-functions-commons": "^26.2.1",
"@pagopa/ts-commons": "^10.10.0",
"applicationinsights": "^1.7.4",
Expand Down
2 changes: 1 addition & 1 deletion utils/__tests__/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { initTelemetryClient } from "../appinsights";
import { ServiceId } from "../../generated/definitions/ServiceId";
import { ActivationModel } from "@pagopa/io-functions-commons/dist/src/models/activation";
import { ActivationStatusEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/ActivationStatus";
import { SpecialServiceCategoryEnum } from "../../generated/api-admin/SpecialServiceCategory";
import { SpecialServiceCategoryEnum } from "@pagopa/io-functions-admin-sdk/SpecialServiceCategory";
import { ServiceScopeEnum } from "@pagopa/io-functions-commons/dist/generated/definitions/ServiceScope";
import { toCosmosErrorResponse } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model";
import { canSendMessageOnActivationWithGrace } from "../services";
Expand Down
Loading

0 comments on commit 7d9dab4

Please sign in to comment.