-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add get and cancle to debug api and add test
- Loading branch information
Showing
3 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
26 changes: 21 additions & 5 deletions
26
src/modules/coreHttpApi/debug-controllers/IdentityDeletionController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters