Skip to content

Commit

Permalink
feat: add get and cancle to debug api and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbi08 committed Nov 12, 2024
1 parent cd972e5 commit 8ff4577
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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<Envelope> {
public async initiateIdentityDeletionProcess(): Promise<Envelope> {
const result = await this.transportServices.identityDeletionProcesses.initiateIdentityDeletionProcess();
return this.ok(result);
}

@GET
@Path("/")
@Accept("application/json")
public async getActiveIdentityDeletionProcess(): Promise<Envelope> {
const result = await this.transportServices.identityDeletionProcesses.getActiveIdentityDeletionProcess();
return this.ok(result);
}

@POST
@Path("/cancel")
@Accept("application/json")
public async cancelIdentityDeletionProcess(): Promise<Envelope> {
const result = await this.transportServices.identityDeletionProcesses.cancelIdentityDeletionProcess();
return this.ok(result);
}
}
41 changes: 41 additions & 0 deletions test/identityDeletionProcess.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
4 changes: 3 additions & 1 deletion test/lib/Launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class Launcher {

public stopClient(connector: ChildProcess, webhookServer: Server | undefined): void {
connector.kill();
webhookServer?.close();
connector.on("exit", () => {
webhookServer?.close();
});
}
}

0 comments on commit 8ff4577

Please sign in to comment.