diff --git a/README.md b/README.md index c6dff80a..92adce39 100644 --- a/README.md +++ b/README.md @@ -1320,6 +1320,12 @@ await descopeClient.management.user.createTestUser('desmond@descope.com', { userTenants: [{ tenantId: 'tenant-ID1', roleNames: ['role-name1'] }], }); +// Search all test users according to various parameters +const searchRes = await descopeClient.management.user.searchTestUsers(['id']); +searchRes.data.forEach((user) => { + // do something +}); + // Now test user got created, and this user will be available until you delete it, // you can use any management operation for test user CRUD. // You can also delete all test users. diff --git a/lib/management/paths.ts b/lib/management/paths.ts index 6b84b8e0..40c9da2b 100644 --- a/lib/management/paths.ts +++ b/lib/management/paths.ts @@ -2,6 +2,7 @@ export default { user: { create: '/v1/mgmt/user/create', + createTestUser: '/v1/mgmt/user/create/test', createBatch: '/v1/mgmt/user/create/batch', update: '/v1/mgmt/user/update', patch: '/v1/mgmt/user/patch', @@ -10,6 +11,7 @@ export default { load: '/v1/mgmt/user', logout: '/v1/mgmt/user/logout', search: '/v2/mgmt/user/search', + searchTestUsers: '/v2/mgmt/user/search/test', getProviderToken: '/v1/mgmt/user/provider/token', updateStatus: '/v1/mgmt/user/update/status', updateLoginId: '/v1/mgmt/user/update/loginid', diff --git a/lib/management/user.test.ts b/lib/management/user.test.ts index 0e79d76f..b0c3052a 100644 --- a/lib/management/user.test.ts +++ b/lib/management/user.test.ts @@ -204,7 +204,7 @@ describe('Management User', () => { ); expect(mockHttpClient.post).toHaveBeenCalledWith( - apiPaths.user.create, + apiPaths.user.createTestUser, { loginId: 'loginId', email: 'a@b.c', @@ -244,7 +244,7 @@ describe('Management User', () => { }); expect(mockHttpClient.post).toHaveBeenCalledWith( - apiPaths.user.create, + apiPaths.user.createTestUser, { loginId: 'loginId', email: 'a@b.c', diff --git a/lib/management/user.ts b/lib/management/user.ts index a5b697b9..e9962109 100644 --- a/lib/management/user.ts +++ b/lib/management/user.ts @@ -190,7 +190,7 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => { test: true, }; return transformResponse( - sdk.httpClient.post(apiPaths.user.create, body, { token: managementKey }), + sdk.httpClient.post(apiPaths.user.createTestUser, body, { token: managementKey }), (data) => data.user, ); } @@ -562,12 +562,21 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => { ), (data) => data.users, ), - /** - * Search all users. Results can be filtered according to tenants roles and more, - * Pagination is also available using the limit and page parameters. - * @param searchReq an object with all the constraints for this search - * @returns An array of UserResponse found by the query - */ + searchTestUsers: (searchReq: SearchRequest): Promise> => + transformResponse( + sdk.httpClient.post( + apiPaths.user.searchTestUsers, + { + ...searchReq, + withTestUser: true, + testUsersOnly: true, + roleNames: searchReq.roles, + roles: undefined, + }, + { token: managementKey }, + ), + (data) => data.users, + ), search: (searchReq: SearchRequest): Promise> => transformResponse( sdk.httpClient.post(