Test cases for updated API.
This commit is contained in:
parent
162f2cb938
commit
bd182d5b3b
|
@ -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", () => {
|
describe("DELETE /api/global/users/:userId", () => {
|
||||||
it("should be able to destroy a basic user", async () => {
|
it("should be able to destroy a basic user", async () => {
|
||||||
const user = await config.createUser()
|
const user = await config.createUser()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
InviteUsersRequest,
|
InviteUsersRequest,
|
||||||
User,
|
User,
|
||||||
CreateAdminUserRequest,
|
CreateAdminUserRequest,
|
||||||
|
SearchQuery,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import structures from "../structures"
|
import structures from "../structures"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
@ -133,6 +134,15 @@ export class UserAPI extends TestAPI {
|
||||||
.expect(status ? status : 200)
|
.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) => {
|
getUser = (userId: string, opts?: TestAPIOpts) => {
|
||||||
return this.request
|
return this.request
|
||||||
.get(`/api/global/users/${userId}`)
|
.get(`/api/global/users/${userId}`)
|
||||||
|
|
Loading…
Reference in New Issue