@budibase/worker 2.6.8-alpha.10 → 2.6.8-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.6.8-alpha.10",
4
+ "version": "2.6.8-alpha.12",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -37,10 +37,10 @@
37
37
  "author": "Budibase",
38
38
  "license": "GPL-3.0",
39
39
  "dependencies": {
40
- "@budibase/backend-core": "2.6.8-alpha.10",
41
- "@budibase/pro": "2.6.8-alpha.10",
42
- "@budibase/string-templates": "2.6.8-alpha.10",
43
- "@budibase/types": "2.6.8-alpha.10",
40
+ "@budibase/backend-core": "2.6.8-alpha.12",
41
+ "@budibase/pro": "2.6.8-alpha.12",
42
+ "@budibase/string-templates": "2.6.8-alpha.12",
43
+ "@budibase/types": "2.6.8-alpha.12",
44
44
  "@koa/router": "8.0.8",
45
45
  "@sentry/node": "6.17.7",
46
46
  "@techpass/passport-openidconnect": "0.3.2",
@@ -102,5 +102,5 @@
102
102
  "typescript": "4.7.3",
103
103
  "update-dotenv": "1.1.1"
104
104
  },
105
- "gitHead": "bcc68ebca7f6a471883eca92678c9ab4ab34dc2a"
105
+ "gitHead": "90d65824eb665b2b57181153a40fc140a607e7ff"
106
106
  }
@@ -1,5 +1,9 @@
1
1
  import { events } from "@budibase/backend-core"
2
+ import { generator } from "@budibase/backend-core/tests"
2
3
  import { structures, TestConfiguration, mocks } from "../../../../tests"
4
+ import { UserGroup } from "@budibase/types"
5
+
6
+ mocks.licenses.useGroups()
3
7
 
4
8
  describe("/api/global/groups", () => {
5
9
  const config = new TestConfiguration()
@@ -113,4 +117,118 @@ describe("/api/global/groups", () => {
113
117
  })
114
118
  })
115
119
  })
120
+
121
+ describe("find users", () => {
122
+ describe("without users", () => {
123
+ let group: UserGroup
124
+ beforeAll(async () => {
125
+ group = structures.groups.UserGroup()
126
+ await config.api.groups.saveGroup(group)
127
+ })
128
+
129
+ it("should return empty", async () => {
130
+ const result = await config.api.groups.searchUsers(group._id!)
131
+ expect(result.body).toEqual({
132
+ users: [],
133
+ bookmark: undefined,
134
+ hasNextPage: false,
135
+ })
136
+ })
137
+ })
138
+
139
+ describe("existing users", () => {
140
+ let groupId: string
141
+ let users: { _id: string; email: string }[] = []
142
+
143
+ beforeAll(async () => {
144
+ groupId = (
145
+ await config.api.groups.saveGroup(structures.groups.UserGroup())
146
+ ).body._id
147
+
148
+ await Promise.all(
149
+ Array.from({ length: 30 }).map(async (_, i) => {
150
+ const email = `user${i}@${generator.domain()}`
151
+ const user = await config.api.users.saveUser({
152
+ ...structures.users.user(),
153
+ email,
154
+ })
155
+ users.push({ _id: user.body._id, email })
156
+ })
157
+ )
158
+ users = users.sort((a, b) => a._id.localeCompare(b._id))
159
+ await config.api.groups.updateGroupUsers(groupId, {
160
+ add: users.map(u => u._id),
161
+ remove: [],
162
+ })
163
+ })
164
+
165
+ describe("pagination", () => {
166
+ it("should return first page", async () => {
167
+ const result = await config.api.groups.searchUsers(groupId)
168
+ expect(result.body).toEqual({
169
+ users: users.slice(0, 10),
170
+ bookmark: users[10]._id,
171
+ hasNextPage: true,
172
+ })
173
+ })
174
+
175
+ it("given a bookmark, should return skip items", async () => {
176
+ const result = await config.api.groups.searchUsers(groupId, {
177
+ bookmark: users[7]._id,
178
+ })
179
+ expect(result.body).toEqual({
180
+ users: users.slice(7, 17),
181
+ bookmark: users[17]._id,
182
+ hasNextPage: true,
183
+ })
184
+ })
185
+
186
+ it("bookmarking the last page, should return last page info", async () => {
187
+ const result = await config.api.groups.searchUsers(groupId, {
188
+ bookmark: users[20]._id,
189
+ })
190
+ expect(result.body).toEqual({
191
+ users: users.slice(20),
192
+ bookmark: undefined,
193
+ hasNextPage: false,
194
+ })
195
+ })
196
+ })
197
+
198
+ describe("search by email", () => {
199
+ it('should be able to search "starting" by email', async () => {
200
+ const result = await config.api.groups.searchUsers(groupId, {
201
+ emailSearch: `user1`,
202
+ })
203
+
204
+ const matchedUsers = users
205
+ .filter(u => u.email.startsWith("user1"))
206
+ .sort((a, b) => a.email.localeCompare(b.email))
207
+
208
+ expect(result.body).toEqual({
209
+ users: matchedUsers.slice(0, 10),
210
+ bookmark: matchedUsers[10].email,
211
+ hasNextPage: true,
212
+ })
213
+ })
214
+
215
+ it("should be able to bookmark when searching by email", async () => {
216
+ const matchedUsers = users
217
+ .filter(u => u.email.startsWith("user1"))
218
+ .sort((a, b) => a.email.localeCompare(b.email))
219
+
220
+ const result = await config.api.groups.searchUsers(groupId, {
221
+ emailSearch: `user1`,
222
+ bookmark: matchedUsers[4].email,
223
+ })
224
+
225
+ expect(result.body).toEqual({
226
+ users: matchedUsers.slice(4),
227
+ bookmark: undefined,
228
+ hasNextPage: false,
229
+ })
230
+ })
231
+ })
232
+ })
233
+ })
116
234
  })
@@ -23,4 +23,34 @@ export class GroupsAPI extends TestAPI {
23
23
  .expect("Content-Type", /json/)
24
24
  .expect(200)
25
25
  }
26
+
27
+ searchUsers = (
28
+ id: string,
29
+ params?: { bookmark?: string; emailSearch?: string }
30
+ ) => {
31
+ let url = `/api/global/groups/${id}/users?`
32
+ if (params?.bookmark) {
33
+ url += `bookmark=${params.bookmark}&`
34
+ }
35
+ if (params?.emailSearch) {
36
+ url += `emailSearch=${params.emailSearch}&`
37
+ }
38
+ return this.request
39
+ .get(url)
40
+ .set(this.config.defaultHeaders())
41
+ .expect("Content-Type", /json/)
42
+ .expect(200)
43
+ }
44
+
45
+ updateGroupUsers = (
46
+ id: string,
47
+ body: { add: string[]; remove: string[] }
48
+ ) => {
49
+ return this.request
50
+ .post(`/api/global/groups/${id}/users`)
51
+ .send(body)
52
+ .set(this.config.defaultHeaders())
53
+ .expect("Content-Type", /json/)
54
+ .expect(200)
55
+ }
26
56
  }