Test search by email

This commit is contained in:
Adria Navarro 2023-05-10 14:53:30 +02:00
parent 999dcebb74
commit 0882046ea2
4 changed files with 72 additions and 33 deletions

@ -1 +1 @@
Subproject commit 7703fa7a50bd93571938e9335e58f100d56799fe
Subproject commit 375fbd3d1229a741ea3962dc42de479118020e95

View File

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

View File

@ -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,6 +162,7 @@ describe("/api/global/groups", () => {
})
})
describe("pagination", () => {
it("should return first page", async () => {
const result = await config.api.groups.searchUsers(groupId)
expect(result.body).toEqual({
@ -197,5 +194,41 @@ describe("/api/global/groups", () => {
})
})
})
describe("search by email", () => {
it('should be able to search "starting" by email', async () => {
const result = await config.api.groups.searchUsers(groupId, {
emailSearch: `user1`,
})
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,
})
})
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,
})
})
})
})
})
})

View File

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