@budibase/worker 3.13.18 → 3.13.20

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": "3.13.18",
4
+ "version": "3.13.20",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -114,5 +114,5 @@
114
114
  }
115
115
  }
116
116
  },
117
- "gitHead": "6d3c3c8002c3ba2682b5bfb2299b4457195fda82"
117
+ "gitHead": "6d7096e4d28a12b872d1aa83cee09a3ac431a9ae"
118
118
  }
@@ -349,4 +349,101 @@ describe("/api/global/groups", () => {
349
349
  })
350
350
  })
351
351
  })
352
+
353
+ describe("bulk add users via CSV", () => {
354
+ let groupId: string
355
+ let existingUsers: { _id: string; email: string }[] = []
356
+
357
+ beforeAll(async () => {
358
+ groupId = (
359
+ await config.api.groups.saveGroup(structures.groups.UserGroup())
360
+ ).body._id
361
+
362
+ await Promise.all(
363
+ Array.from({ length: 5 }).map(async (_, i) => {
364
+ const email = `bulkuser${i}+${generator.guid()}@example.com`
365
+ const user = await config.api.users.saveUser({
366
+ ...structures.users.user(),
367
+ email,
368
+ })
369
+ existingUsers.push({ _id: user.body._id, email })
370
+ })
371
+ )
372
+ })
373
+
374
+ it("should add existing users to group via CSV with email column", async () => {
375
+ const csvContent = [
376
+ "email",
377
+ existingUsers[0].email,
378
+ existingUsers[1].email,
379
+ ].join("\n")
380
+
381
+ const result = await config.api.groups.bulkAddUsers(groupId, csvContent)
382
+
383
+ expect(result.body).toEqual({
384
+ added: expect.arrayContaining([
385
+ expect.objectContaining({ email: existingUsers[0].email }),
386
+ expect.objectContaining({ email: existingUsers[1].email }),
387
+ ]),
388
+ skipped: [],
389
+ })
390
+ })
391
+
392
+ it("should skip non-existent users", async () => {
393
+ const csvContent = [
394
+ "email",
395
+ existingUsers[2].email,
396
+ "nonexistent@example.com",
397
+ ].join("\n")
398
+
399
+ const result = await config.api.groups.bulkAddUsers(groupId, csvContent)
400
+
401
+ expect(result.body.added).toHaveLength(1)
402
+ expect(result.body.added[0].email).toBe(existingUsers[2].email)
403
+ expect(result.body.skipped).toEqual([
404
+ { email: "nonexistent@example.com", reason: "User not found" },
405
+ ])
406
+ })
407
+
408
+ it("should handle CSV with different column names", async () => {
409
+ const csvContent = ["Email Address", existingUsers[3].email].join("\n")
410
+
411
+ const result = await config.api.groups.bulkAddUsers(groupId, csvContent)
412
+
413
+ expect(result.body.added).toHaveLength(1)
414
+ expect(result.body.added[0].email).toBe(existingUsers[3].email)
415
+ })
416
+
417
+ it("should handle CSV with multiple columns", async () => {
418
+ const csvContent = [
419
+ "name,email,department",
420
+ `User Name,${existingUsers[4].email},Engineering`,
421
+ ].join("\n")
422
+
423
+ const result = await config.api.groups.bulkAddUsers(groupId, csvContent)
424
+
425
+ expect(result.body.added).toHaveLength(1)
426
+ expect(result.body.added[0].email).toBe(existingUsers[4].email)
427
+ })
428
+
429
+ it("should return error for invalid CSV", async () => {
430
+ const csvContent = "invalid csv content without headers"
431
+
432
+ await config.api.groups.bulkAddUsers(groupId, csvContent, { expect: 400 })
433
+ })
434
+
435
+ it("should return error for CSV without email column", async () => {
436
+ const csvContent = ["name,department", "John Doe,Engineering"].join("\n")
437
+
438
+ await config.api.groups.bulkAddUsers(groupId, csvContent, { expect: 400 })
439
+ })
440
+
441
+ it("should return error for non-existent group", async () => {
442
+ const csvContent = ["email", existingUsers[0].email].join("\n")
443
+
444
+ await config.api.groups.bulkAddUsers("invalid_group_id", csvContent, {
445
+ expect: 404,
446
+ })
447
+ })
448
+ })
352
449
  })
@@ -81,4 +81,17 @@ export class GroupsAPI extends TestAPI {
81
81
  .expect("Content-Type", /json/)
82
82
  .expect(expect)
83
83
  }
84
+
85
+ bulkAddUsers = (
86
+ id: string,
87
+ csvContent: string,
88
+ { expect } = { expect: 200 }
89
+ ) => {
90
+ return this.request
91
+ .post(`/api/global/groups/${id}/users/bulk`)
92
+ .send({ csvContent })
93
+ .set(this.config.defaultHeaders())
94
+ .expect("Content-Type", /json/)
95
+ .expect(expect)
96
+ }
84
97
  }