File tree Expand file tree Collapse file tree 3 files changed +87
-1
lines changed
Expand file tree Collapse file tree 3 files changed +87
-1
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ export * from "./security/permissions.list.ts"
8787
8888// User
8989export * from "./user/user.initialize-in-keycloak.ts"
90+ export * from "./user/user.delete.ts"
9091
9192// Scenario
9293export * from "./scenario/scenario.create.ts"
Original file line number Diff line number Diff line change 1+ import { Type } from "@sinclair/typebox"
2+ import { Command } from "../../common/command.ts"
3+ import { parseResponseHelper } from "../../utils/parse-response-helper.ts"
4+ import type { Static , TObject , TString } from "@sinclair/typebox"
5+
6+ /**
7+ * The input for deleting the current authenticated user
8+ * No input parameters needed - checks current authenticated user
9+ */
10+ export type UserDeleteInput = Record < PropertyKey , never >
11+
12+ /**
13+ * The output for deleting the current authenticated user
14+ */
15+ export type UserDeleteOutput = Static < typeof responseSchema >
16+
17+ const responseSchema : TObject < {
18+ id : TString
19+ } > = Type . Object ( {
20+ id : Type . String ( ) ,
21+ } )
22+
23+ /**
24+ * Delete current authenticated user
25+ */
26+ export class UserDeleteCommand extends Command <
27+ UserDeleteInput ,
28+ UserDeleteOutput
29+ > {
30+ /**
31+ * The allowed modes for the command
32+ */
33+ protected override allowedModes : ( "apiKey" | "bearer" ) [ ] = [ "bearer" ]
34+
35+ /**
36+ * Get the base URL for the request
37+ */
38+ protected override getBaseUrl ( ) : string {
39+ return "https://user-2.api.flowcore.io"
40+ }
41+
42+ /**
43+ * Get the method
44+ */
45+ protected override getMethod ( ) : string {
46+ return "DELETE"
47+ }
48+
49+ /**
50+ * Get the path for the request
51+ */
52+ protected override getPath ( ) : string {
53+ return `/api/users`
54+ }
55+
56+ /**
57+ * Parse the response
58+ */
59+ protected override parseResponse ( rawResponse : unknown ) : UserDeleteOutput {
60+ const response = parseResponseHelper ( responseSchema , rawResponse )
61+ return response
62+ }
63+ }
Original file line number Diff line number Diff line change 11import { assertEquals } from "@std/assert"
22import { afterAll , afterEach , describe , it } from "@std/testing/bdd"
3- import { FlowcoreClient , UserInitializeInKeycloakCommand } from "../../../src/mod.ts"
3+ import { FlowcoreClient , UserDeleteCommand , UserInitializeInKeycloakCommand } from "../../../src/mod.ts"
44import { FetchMocker } from "../../fixtures/fetch.fixture.ts"
55
66describe ( "User" , ( ) => {
@@ -68,4 +68,26 @@ describe("User", () => {
6868 assertEquals ( response , userData )
6969 } )
7070 } )
71+
72+ describe ( "UserDeleteCommand" , ( ) => {
73+ it ( "should DELETE /api/users with an empty body and return id" , async ( ) => {
74+ // arrange
75+ const responseData = { id : "user123" }
76+
77+ fetchMockerBuilder . delete ( "/api/users" )
78+ . matchHeaders ( {
79+ Authorization : "Bearer BEARER_TOKEN" ,
80+ "Content-Type" : "application/json" ,
81+ } )
82+ . matchBody ( { } )
83+ . respondWith ( 200 , responseData )
84+
85+ // act
86+ const command = new UserDeleteCommand ( { } )
87+ const response = await flowcoreClient . execute ( command )
88+
89+ // assert
90+ assertEquals ( response , responseData )
91+ } )
92+ } )
7193} )
You can’t perform that action at this time.
0 commit comments