Test cases for updated API.

This commit is contained in:
mike12345567 2023-10-12 19:19:05 +01:00
parent 162f2cb938
commit bd182d5b3b
2 changed files with 40 additions and 0 deletions

View File

@ -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()

View File

@ -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}`)