diff --git a/packages/worker/src/api/routes/global/tests/users.spec.ts b/packages/worker/src/api/routes/global/tests/users.spec.ts index e4504eccfe..a446d10ed0 100644 --- a/packages/worker/src/api/routes/global/tests/users.spec.ts +++ b/packages/worker/src/api/routes/global/tests/users.spec.ts @@ -544,6 +544,36 @@ describe("/api/global/users", () => { }) }) + describe("POST /api/global/users/search", () => { + it("should be able to search by email", async () => { + const user = await config.createUser() + const response = await config.api.users.searchUsers({ + query: { string: { email: user.email } }, + }) + expect(response.body.data.length).toBe(1) + expect(response.body.data[0].email).toBe(user.email) + }) + + it("should be able to search by _id", async () => { + const user = await config.createUser() + const response = await config.api.users.searchUsers({ + query: { equal: { _id: user._id } }, + }) + expect(response.body.data.length).toBe(1) + expect(response.body.data[0]._id).toBe(user._id) + }) + + it("should throw an error when unimplemented options used", async () => { + const user = await config.createUser() + await config.api.users.searchUsers( + { + query: { equal: { firstName: user.firstName } }, + }, + 501 + ) + }) + }) + describe("DELETE /api/global/users/:userId", () => { it("should be able to destroy a basic user", async () => { const user = await config.createUser() diff --git a/packages/worker/src/tests/api/users.ts b/packages/worker/src/tests/api/users.ts index e96209eca6..b2a19bcb28 100644 --- a/packages/worker/src/tests/api/users.ts +++ b/packages/worker/src/tests/api/users.ts @@ -4,6 +4,7 @@ import { InviteUsersRequest, User, CreateAdminUserRequest, + SearchQuery, } from "@budibase/types" import structures from "../structures" import { generator } from "@budibase/backend-core/tests" @@ -133,6 +134,15 @@ export class UserAPI extends TestAPI { .expect(status ? status : 200) } + searchUsers = ({ query }: { query?: SearchQuery }, status = 200) => { + return this.request + .post("/api/global/users/search") + .set(this.config.defaultHeaders()) + .send({ query }) + .expect("Content-Type", /json/) + .expect(status ? status : 200) + } + getUser = (userId: string, opts?: TestAPIOpts) => { return this.request .get(`/api/global/users/${userId}`)