From 6ab9ab2c599eff1596a75c0c9b4e795b854c79bd Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 27 Aug 2024 08:13:52 +0200 Subject: [PATCH] feat(core): Add delete user functionality and necessary tests --- changelog.md | 7 +++++++ test/test.ts | 15 ++++++++++++--- ts/00_commitinfo_data.ts | 2 +- ts/classes.zitadelclient.ts | 8 +++++++- ts/classes.zitadeluser.ts | 9 +++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 0e83349..1c6eeac 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2024-08-27 - 1.1.0 - feat(core) +Add delete user functionality and necessary tests + +- Implemented delete method in ZitadelUser class. +- Extended tests to cover user deletion functionality. +- Refactored createUser method to return a ZitadelUser instance. + ## 2024-08-26 - 1.0.9 - fix(dependencies) Update dependencies to latest versions diff --git a/test/test.ts b/test/test.ts index 5fda5d5..9a44237 100644 --- a/test/test.ts +++ b/test/test.ts @@ -24,15 +24,24 @@ tap.test('should list users', async () => { const users = await testZitadel.listUsers(); expect(users).toBeArray(); expect(users[0]).toBeInstanceOf(zitadel.ZitaldelUser); - console.log(users); + console.log(JSON.stringify(users, null, 2)); }) -tap.test('should invite user', async () => { - await testZitadel.createUser({ +const createUserTest = tap.test('should invite user', async (toolsArg) => { + const user = await testZitadel.createUser({ email: await testQenv.getEnvVarOnDemand('ZITADEL_TEST_EMAIL'), firstName: 'firstname', lastName: 'lastname', }) + await toolsArg.delayFor(5000); + return user; +}) + +tap.test('should delete user', async () => { + const createdUser: zitadel.ZitaldelUser = (await createUserTest.testResultPromise) as any; + expect(createdUser).toBeInstanceOf(zitadel.ZitaldelUser); + await createdUser.delete(); + }) export default tap.start() diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 8b71c24..0aee37e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@apiclient.xyz/zitadel', - version: '1.0.9', + version: '1.1.0', description: 'An unofficial client for interacting with Zitadel API, enabling user and project management functionalities.' } diff --git a/ts/classes.zitadelclient.ts b/ts/classes.zitadelclient.ts index ce6b554..96fb0b3 100644 --- a/ts/classes.zitadelclient.ts +++ b/ts/classes.zitadelclient.ts @@ -79,6 +79,12 @@ export class ZitaldelClient { familyName: optionsArg.lastName, } }); - console.log(response); + // const allUsers = await this.listUsers(); + // console.log(JSON.stringify(allUsers, null, 2)); + return new ZitaldelUser(this, { + id: response.userId, + lastLogin: null, + username: optionsArg.email, + }); } } diff --git a/ts/classes.zitadeluser.ts b/ts/classes.zitadeluser.ts index bbacdd7..9607ca5 100644 --- a/ts/classes.zitadeluser.ts +++ b/ts/classes.zitadeluser.ts @@ -64,4 +64,13 @@ export class ZitaldelUser { userId: this.data.id, }); } + + /** + * deletes the user + */ + public async delete() { + const response = await this.zitadelclientRef.userClient.deleteUser({ + userId: this.data.id, + }); + } }