diff --git a/packages/pro b/packages/pro index 7703fa7a50..375fbd3d12 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 7703fa7a50bd93571938e9335e58f100d56799fe +Subproject commit 375fbd3d1229a741ea3962dc42de479118020e95 diff --git a/packages/types/src/sdk/db.ts b/packages/types/src/sdk/db.ts index 58b3b7e5bc..023f6382e7 100644 --- a/packages/types/src/sdk/db.ts +++ b/packages/types/src/sdk/db.ts @@ -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 diff --git a/packages/worker/src/api/routes/global/tests/groups.spec.ts b/packages/worker/src/api/routes/global/tests/groups.spec.ts index 102c22af8a..afeaae952c 100644 --- a/packages/worker/src/api/routes/global/tests/groups.spec.ts +++ b/packages/worker/src/api/routes/global/tests/groups.spec.ts @@ -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, + }) }) }) }) diff --git a/packages/worker/src/tests/api/groups.ts b/packages/worker/src/tests/api/groups.ts index 950d3b1364..91f7c92c7d 100644 --- a/packages/worker/src/tests/api/groups.ts +++ b/packages/worker/src/tests/api/groups.ts @@ -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())