-
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.
Add identity deletion debug APIs (#310)
* chore: add debug api for identity deletion * chore: test only non debug api's * feat: add get and cancle to debug api and add test * chore: make code pretty and usable * fix: change to delete * chore: one-liner --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Julian König <[email protected]>
- Loading branch information
1 parent
de54d46
commit 79d6366
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { TransportServices } from "@nmshd/runtime"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { Accept, DELETE, GET, Path, POST } from "@nmshd/typescript-rest"; | ||
import { Envelope } from "../../../infrastructure"; | ||
import { BaseController } from "../common/BaseController"; | ||
|
||
@Path("/api/v2/IdentityDeletionProcess") | ||
export class IdentityDeletionProcessController extends BaseController { | ||
public constructor(@Inject private readonly transportServices: TransportServices) { | ||
super(); | ||
} | ||
|
||
@POST | ||
@Accept("application/json") | ||
public async initiateIdentityDeletionProcess(): Promise<Envelope> { | ||
const result = await this.transportServices.identityDeletionProcesses.initiateIdentityDeletionProcess(); | ||
return this.ok(result); | ||
} | ||
|
||
@GET | ||
@Accept("application/json") | ||
public async getActiveIdentityDeletionProcess(): Promise<Envelope> { | ||
const result = await this.transportServices.identityDeletionProcesses.getActiveIdentityDeletionProcess(); | ||
return this.ok(result); | ||
} | ||
|
||
@DELETE | ||
@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,80 @@ | ||
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; | ||
|
||
beforeAll(async () => { | ||
[client] = await launcher.launch(1); | ||
|
||
axiosInstance = (client.account as any).httpClient; | ||
}, getTimeout(30000)); | ||
afterAll(() => launcher.stop()); | ||
|
||
interface IdentityDeletionProcess { | ||
id: string; | ||
status: "WaitingForApproval" | "Rejected" | "Approved" | "Cancelled"; | ||
createdAt?: string; | ||
createdByDevice?: string; | ||
approvalPeriodEndsAt?: string; | ||
rejectedAt?: string; | ||
rejectedByDevice?: string; | ||
approvedAt?: string; | ||
approvedByDevice?: string; | ||
gracePeriodEndsAt?: string; | ||
cancelledAt?: string; | ||
cancelledByDevice?: string; | ||
} | ||
|
||
describe("Identity Deletion Process", () => { | ||
afterEach(async () => await axiosInstance.delete("/api/v2/IdentityDeletionProcess")); | ||
|
||
test("should return 400 when no identity deletion process is active", async () => { | ||
const getResult = await axiosInstance.get("/api/v2/IdentityDeletionProcess"); | ||
expect(getResult.status).toBe(400); | ||
}); | ||
|
||
test("should start an identity deletion and get its status", async () => { | ||
const response = await axiosInstance.post<{ result: IdentityDeletionProcess }>("/api/v2/IdentityDeletionProcess"); | ||
|
||
expect(response.status).toBe(200); | ||
const identityDeletionProcess = response.data.result; | ||
expect(identityDeletionProcess.status).toBe("Approved"); | ||
expect(DateTime.fromISO(identityDeletionProcess.gracePeriodEndsAt!).toMillis()).toBeGreaterThan(DateTime.now().toMillis()); | ||
}); | ||
|
||
test("should get the active identity deletion process", async () => { | ||
const initiateResult = await axiosInstance.post<{ result: IdentityDeletionProcess }>("/api/v2/IdentityDeletionProcess"); | ||
expect(initiateResult.status).toBe(200); | ||
const identityDeletionProcess = initiateResult.data.result; | ||
|
||
const getResult = await axiosInstance.get<{ result: IdentityDeletionProcess }>("/api/v2/IdentityDeletionProcess"); | ||
expect(getResult.status).toBe(200); | ||
expect(getResult.data.result.status).toBe(identityDeletionProcess.status); | ||
expect(getResult.data.result.gracePeriodEndsAt).toBe(identityDeletionProcess.gracePeriodEndsAt); | ||
}); | ||
|
||
test("should return 400 when trying to start a new identity deletion process", async () => { | ||
const initiateResult = await axiosInstance.post<{ result: IdentityDeletionProcess }>("/api/v2/IdentityDeletionProcess"); | ||
expect(initiateResult.status).toBe(200); | ||
|
||
const initiateResult2 = await axiosInstance.post("/api/v2/IdentityDeletionProcess"); | ||
expect(initiateResult2.status).toBe(400); | ||
}); | ||
|
||
test("should cancel an identity deletion", async () => { | ||
const initiateResult = await axiosInstance.post<{ result: IdentityDeletionProcess }>("/api/v2/IdentityDeletionProcess"); | ||
expect(initiateResult.status).toBe(200); | ||
|
||
const cancelResult = await axiosInstance.delete("/api/v2/IdentityDeletionProcess"); | ||
expect(cancelResult.status).toBe(200); | ||
expect(cancelResult.data.result.status).toBe("Cancelled"); | ||
|
||
const getResult = await axiosInstance.get("/api/v2/IdentityDeletionProcess"); | ||
expect(getResult.status).toBe(400); | ||
}); | ||
}); |
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
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