From 8ff4577f37bc902ae17b84d6cb059a3dfe7a7ec5 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Tue, 12 Nov 2024 15:27:02 +0100 Subject: [PATCH] feat: add get and cancle to debug api and add test --- .../IdentityDeletionController.ts | 26 +++++++++--- test/identityDeletionProcess.test.ts | 41 +++++++++++++++++++ test/lib/Launcher.ts | 4 +- 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 test/identityDeletionProcess.test.ts diff --git a/src/modules/coreHttpApi/debug-controllers/IdentityDeletionController.ts b/src/modules/coreHttpApi/debug-controllers/IdentityDeletionController.ts index 7677e61b..7fbdedf5 100644 --- a/src/modules/coreHttpApi/debug-controllers/IdentityDeletionController.ts +++ b/src/modules/coreHttpApi/debug-controllers/IdentityDeletionController.ts @@ -1,20 +1,36 @@ import { TransportServices } from "@nmshd/runtime"; import { Inject } from "@nmshd/typescript-ioc"; -import { Accept, DELETE, Path } from "@nmshd/typescript-rest"; +import { Accept, GET, Path, POST } from "@nmshd/typescript-rest"; import { Envelope } from "../../../infrastructure"; import { BaseController } from "../common/BaseController"; -@Path("/api/v2/IdentityDeletion") -export class IdentityDeletionController extends BaseController { +@Path("/api/v2/IdentityDeletionProcess") +export class IdentityDeletionProcessController extends BaseController { public constructor(@Inject private readonly transportServices: TransportServices) { super(); } - @DELETE + @POST @Path("/") @Accept("application/json") - public async getIdentityInfo(): Promise { + public async initiateIdentityDeletionProcess(): Promise { const result = await this.transportServices.identityDeletionProcesses.initiateIdentityDeletionProcess(); return this.ok(result); } + + @GET + @Path("/") + @Accept("application/json") + public async getActiveIdentityDeletionProcess(): Promise { + const result = await this.transportServices.identityDeletionProcesses.getActiveIdentityDeletionProcess(); + return this.ok(result); + } + + @POST + @Path("/cancel") + @Accept("application/json") + public async cancelIdentityDeletionProcess(): Promise { + const result = await this.transportServices.identityDeletionProcesses.cancelIdentityDeletionProcess(); + return this.ok(result); + } } diff --git a/test/identityDeletionProcess.test.ts b/test/identityDeletionProcess.test.ts new file mode 100644 index 00000000..fa54c145 --- /dev/null +++ b/test/identityDeletionProcess.test.ts @@ -0,0 +1,41 @@ +import { ConnectorClient } from "@nmshd/connector-sdk"; +import { AxiosInstance } from "axios"; +import { DateTime } from "luxon"; +import { Launcher } from "./lib/Launcher"; +import { getTimeout } from "./lib/setTimeout"; + +const launcher = new Launcher(); +let client: ConnectorClient; +let axiosInstance: AxiosInstance; + +beforeEach(async () => { + [client] = await launcher.launch(1); + + axiosInstance = (client.account as any).httpClient; +}, getTimeout(30000)); +afterEach(() => launcher.stop()); + +describe("Identity Deletion Process", () => { + test("should start an identity deletion and get its status", async () => { + const identityDeletionProcesses = await axiosInstance.post("/api/v2/IdentityDeletionProcess"); + expect(identityDeletionProcesses.status).toBe(200); + expect(identityDeletionProcesses.data.result.status).toBe("Approved"); + expect(DateTime.fromISO(identityDeletionProcesses.data.result.gracePeriodEndsAt).toMillis()).toBeGreaterThan(DateTime.now().toMillis()); + + const activeIdentityDeletionProcess = await axiosInstance.get("/api/v2/IdentityDeletionProcess"); + expect(activeIdentityDeletionProcess.status).toBe(200); + expect(activeIdentityDeletionProcess.data.result.status).toBe(identityDeletionProcesses.data.result.status); + expect(activeIdentityDeletionProcess.data.result.gracePeriodEndsAt).toBe(identityDeletionProcesses.data.result.gracePeriodEndsAt); + }); + + test("should cancel an identity deletion", async () => { + const identityDeletionProcesses = await axiosInstance.post("/api/v2/IdentityDeletionProcess"); + expect(identityDeletionProcesses.status).toBe(200); + expect(identityDeletionProcesses.data.result.status).toBe("Approved"); + expect(DateTime.fromISO(identityDeletionProcesses.data.result.gracePeriodEndsAt).toMillis()).toBeGreaterThan(DateTime.now().toMillis()); + + const cancelIdentityDeletionProcess = await axiosInstance.post("/api/v2/IdentityDeletionProcess/cancel"); + expect(cancelIdentityDeletionProcess.status).toBe(200); + expect(cancelIdentityDeletionProcess.data.result.status).toBe("Cancelled"); + }); +}); diff --git a/test/lib/Launcher.ts b/test/lib/Launcher.ts index 15fc1bda..4d5b01e4 100644 --- a/test/lib/Launcher.ts +++ b/test/lib/Launcher.ts @@ -143,6 +143,8 @@ export class Launcher { public stopClient(connector: ChildProcess, webhookServer: Server | undefined): void { connector.kill(); - webhookServer?.close(); + connector.on("exit", () => { + webhookServer?.close(); + }); } }