Test search by email
This commit is contained in:
parent
999dcebb74
commit
0882046ea2
|
@ -1 +1 @@
|
|||
Subproject commit 7703fa7a50bd93571938e9335e58f100d56799fe
|
||||
Subproject commit 375fbd3d1229a741ea3962dc42de479118020e95
|
|
@ -57,8 +57,8 @@ export type DatabaseDeleteIndexOpts = {
|
|||
|
||||
export type DatabaseQueryOpts = {
|
||||
include_docs?: boolean
|
||||
startkey?: string
|
||||
endkey?: string
|
||||
startkey?: string | string[]
|
||||
endkey?: string | string[]
|
||||
limit?: number
|
||||
skip?: number
|
||||
descending?: boolean
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import { events } from "@budibase/backend-core"
|
||||
import {
|
||||
structures,
|
||||
TestConfiguration,
|
||||
mocks,
|
||||
generator,
|
||||
} from "../../../../tests"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import { structures, TestConfiguration, mocks } from "../../../../tests"
|
||||
import { UserGroup } from "@budibase/types"
|
||||
|
||||
mocks.licenses.useGroups()
|
||||
|
@ -166,34 +162,71 @@ describe("/api/global/groups", () => {
|
|||
})
|
||||
})
|
||||
|
||||
it("should return first page", async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId)
|
||||
expect(result.body).toEqual({
|
||||
users: users.slice(0, 10),
|
||||
bookmark: users[10]._id,
|
||||
hasNextPage: true,
|
||||
describe("pagination", () => {
|
||||
it("should return first page", async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId)
|
||||
expect(result.body).toEqual({
|
||||
users: users.slice(0, 10),
|
||||
bookmark: users[10]._id,
|
||||
hasNextPage: true,
|
||||
})
|
||||
})
|
||||
|
||||
it("given a bookmark, should return skip items", async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId, {
|
||||
bookmark: users[7]._id,
|
||||
})
|
||||
expect(result.body).toEqual({
|
||||
users: users.slice(7, 17),
|
||||
bookmark: users[17]._id,
|
||||
hasNextPage: true,
|
||||
})
|
||||
})
|
||||
|
||||
it("bookmarking the last page, should return last page info", async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId, {
|
||||
bookmark: users[20]._id,
|
||||
})
|
||||
expect(result.body).toEqual({
|
||||
users: users.slice(20),
|
||||
bookmark: undefined,
|
||||
hasNextPage: false,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("given a bookmark, should return skip items", async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId, {
|
||||
bookmark: users[7]._id,
|
||||
})
|
||||
expect(result.body).toEqual({
|
||||
users: users.slice(7, 17),
|
||||
bookmark: users[17]._id,
|
||||
hasNextPage: true,
|
||||
})
|
||||
})
|
||||
describe("search by email", () => {
|
||||
it('should be able to search "starting" by email', async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId, {
|
||||
emailSearch: `user1`,
|
||||
})
|
||||
|
||||
it("bookmarking the last page, should return last page info", async () => {
|
||||
const result = await config.api.groups.searchUsers(groupId, {
|
||||
bookmark: users[20]._id,
|
||||
const matchedUsers = users
|
||||
.filter(u => u.email.startsWith("user1"))
|
||||
.sort((a, b) => a.email.localeCompare(b.email))
|
||||
|
||||
expect(result.body).toEqual({
|
||||
users: matchedUsers.slice(0, 10),
|
||||
bookmark: matchedUsers[10].email,
|
||||
hasNextPage: true,
|
||||
})
|
||||
})
|
||||
expect(result.body).toEqual({
|
||||
users: users.slice(20),
|
||||
bookmark: undefined,
|
||||
hasNextPage: false,
|
||||
|
||||
it("should be able to bookmark when searching by email", async () => {
|
||||
const matchedUsers = users
|
||||
.filter(u => u.email.startsWith("user1"))
|
||||
.sort((a, b) => a.email.localeCompare(b.email))
|
||||
|
||||
const result = await config.api.groups.searchUsers(groupId, {
|
||||
emailSearch: `user1`,
|
||||
bookmark: matchedUsers[4].email,
|
||||
})
|
||||
|
||||
expect(result.body).toEqual({
|
||||
users: matchedUsers.slice(4),
|
||||
bookmark: undefined,
|
||||
hasNextPage: false,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -24,11 +24,17 @@ export class GroupsAPI extends TestAPI {
|
|||
.expect(200)
|
||||
}
|
||||
|
||||
searchUsers = (id: string, params?: { bookmark?: string }) => {
|
||||
searchUsers = (
|
||||
id: string,
|
||||
params?: { bookmark?: string; emailSearch?: string }
|
||||
) => {
|
||||
let url = `/api/global/groups/${id}/users?`
|
||||
if (params?.bookmark) {
|
||||
url += `bookmark=${params.bookmark}&`
|
||||
}
|
||||
if (params?.emailSearch) {
|
||||
url += `emailSearch=${params.emailSearch}&`
|
||||
}
|
||||
return this.request
|
||||
.get(url)
|
||||
.set(this.config.defaultHeaders())
|
||||
|
|
Loading…
Reference in New Issue