Skip to content

Commit

Permalink
[#IC-346] Remove Visible services assets generation (#181)
Browse files Browse the repository at this point in the history
* [#IC-346] Remove Visible services assets generation
remove unused orchestrator

* [#IC-346] Remove unused Type and utility

* [#IC-346] Remove unused dependecy

* [#IC-346] Remove unused dependency from yarn.lock
  • Loading branch information
BurnedMarshal authored Mar 14, 2022
1 parent bbe171a commit d1b98eb
Show file tree
Hide file tree
Showing 21 changed files with 5 additions and 923 deletions.
52 changes: 0 additions & 52 deletions CreateService/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable sonar/sonar-max-lines-per-function */

import * as df from "durable-functions";
import * as lolex from "lolex";

import * as TE from "fp-ts/lib/TaskEither";
import { toCosmosErrorResponse } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model";
import {
Expand All @@ -12,21 +8,8 @@ import {
aSeralizedService,
aServicePayload
} from "../../__mocks__/mocks";
import { UpsertServiceEvent } from "../../utils/UpsertServiceEvent";
import { CreateServiceHandler } from "../handler";

// eslint-disable-next-line functional/no-let
let clock: lolex.InstalledClock;

beforeEach(() => {
(df.getClient as any).mockClear();
(df as any).mockStartNew.mockClear();
clock = lolex.install({ now: Date.now() });
});
afterEach(() => {
clock.uninstall();
});

describe("CreateServiceHandler", () => {
it("should return a query error if the service fails to be created", async () => {
const mockServiceModel = {
Expand Down Expand Up @@ -70,39 +53,4 @@ describe("CreateServiceHandler", () => {
expect(response.value).toEqual(aSeralizedService);
}
});

it("should start the orchestrator with an appropriate event after the service is created", async () => {
const mockServiceModel = {
create: jest.fn(_ => {
return TE.right(aRetrievedService);
})
};

const contextMock = {
log: jest.fn()
};

const createServiceHandler = CreateServiceHandler(mockServiceModel as any);

await createServiceHandler(
contextMock as any, // Not used
undefined as any, // Not used
aServicePayload
);

const upsertServiceEvent = UpsertServiceEvent.encode({
newService: aRetrievedService,
updatedAt: new Date()
});

expect(df.getClient).toHaveBeenCalledTimes(1);

const dfClient = df.getClient(contextMock);
expect(dfClient.startNew).toHaveBeenCalledTimes(1);
expect(dfClient.startNew).toHaveBeenCalledWith(
"UpsertServiceOrchestrator",
undefined,
upsertServiceEvent
);
});
});
20 changes: 2 additions & 18 deletions CreateService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Context } from "@azure/functions";

import * as express from "express";

import * as df from "durable-functions";

import { isLeft } from "fp-ts/lib/Either";

import {
Expand Down Expand Up @@ -34,7 +32,6 @@ import {
retrievedServiceToApiService
} from "../utils/conversions";
import { ServicePayloadMiddleware } from "../utils/middlewares/service";
import { UpsertServiceEvent } from "../utils/UpsertServiceEvent";

type ICreateServiceHandler = (
context: Context,
Expand Down Expand Up @@ -65,22 +62,9 @@ export function CreateServiceHandler(
);
}

const createdService = errorOrCreatedService.right;

const upsertServiceEvent = UpsertServiceEvent.encode({
newService: createdService,
updatedAt: new Date()
});

// Start orchestrator
const dfClient = df.getClient(context);
await dfClient.startNew(
"UpsertServiceOrchestrator",
undefined,
upsertServiceEvent
return ResponseSuccessJson(
retrievedServiceToApiService(errorOrCreatedService.right)
);

return ResponseSuccessJson(retrievedServiceToApiService(createdService));
};
}

Expand Down
60 changes: 1 addition & 59 deletions UpdateService/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable sonar/sonar-max-lines-per-function */

import * as df from "durable-functions";
import * as lolex from "lolex";

import { ServiceId } from "@pagopa/io-functions-commons/dist/generated/definitions/ServiceId";
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";

Expand All @@ -16,7 +13,6 @@ import {
aServicePayload
} from "../../__mocks__/mocks";
import { apiServiceToService } from "../../utils/conversions";
import { UpsertServiceEvent } from "../../utils/UpsertServiceEvent";
import { UpdateServiceHandler } from "../handler";

const aDepartmentName = "UpdateDept" as NonEmptyString;
Expand All @@ -29,16 +25,8 @@ const leftErrorFn = jest.fn(() => {
return TE.left(toCosmosErrorResponse({ kind: "COSMOS_ERROR_RESPONSE" }));
});

// eslint-disable-next-line functional/no-let
let clock: lolex.InstalledClock;
beforeEach(() => {
(df.getClient as any).mockClear();
(df as any).mockStartNew.mockClear();
clock = lolex.install({ now: Date.now() });
leftErrorFn.mockClear();
});
afterEach(() => {
clock.uninstall();
jest.clearAllMocks();
});

describe("UpdateServiceHandler", () => {
Expand Down Expand Up @@ -187,50 +175,4 @@ describe("UpdateServiceHandler", () => {
});
}
});

it("should start the orchestrator with an appropriate event after the service is updated", async () => {
const serviceModelMock = {
findOneByServiceId: jest.fn(() => {
return TE.right(O.some(aRetrievedService));
}),
update: jest.fn(() =>
TE.right({
...aRetrievedService,
...anUpdatedApiService
})
)
};

const contextMock = {
log: jest.fn()
};

const updateServiceHandler = UpdateServiceHandler(serviceModelMock as any);

await updateServiceHandler(
contextMock as any, // Not used
undefined as any, // Not used
aServicePayload.service_id,
{
...aServicePayload,
department_name: aDepartmentName
}
);

const upsertServiceEvent = UpsertServiceEvent.encode({
newService: { ...aRetrievedService, departmentName: aDepartmentName },
oldService: aRetrievedService,
updatedAt: new Date()
});

expect(df.getClient).toHaveBeenCalledTimes(1);

const dfClient = df.getClient(contextMock);
expect(dfClient.startNew).toHaveBeenCalledTimes(1);
expect(dfClient.startNew).toHaveBeenCalledWith(
"UpsertServiceOrchestrator",
undefined,
upsertServiceEvent
);
});
});
21 changes: 2 additions & 19 deletions UpdateService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Context } from "@azure/functions";

import * as express from "express";

import * as df from "durable-functions";

import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";

Expand Down Expand Up @@ -41,7 +39,6 @@ import {
} from "../utils/conversions";
import { ServicePayloadMiddleware } from "../utils/middlewares/service";
import { ServiceIdMiddleware } from "../utils/middlewares/serviceid";
import { UpsertServiceEvent } from "../utils/UpsertServiceEvent";

type IUpdateServiceHandler = (
context: Context,
Expand Down Expand Up @@ -102,23 +99,9 @@ export function UpdateServiceHandler(
);
}

const updatedService = errorOrUpdatedService.right;

const upsertServiceEvent = UpsertServiceEvent.encode({
newService: updatedService,
oldService: existingService,
updatedAt: new Date()
});

// Start orchestrator
const dfClient = df.getClient(context);
await dfClient.startNew(
"UpsertServiceOrchestrator",
undefined,
upsertServiceEvent
return ResponseSuccessJson(
retrievedServiceToApiService(errorOrUpdatedService.right)
);

return ResponseSuccessJson(retrievedServiceToApiService(updatedService));
};
}

Expand Down
10 changes: 0 additions & 10 deletions UpdateVisibleServicesActivity/function.json

This file was deleted.

Loading

0 comments on commit d1b98eb

Please sign in to comment.