Add tests
This commit is contained in:
parent
63244e1dde
commit
3de3ddfa62
|
@ -1,5 +1,10 @@
|
|||
import { events } from "@budibase/backend-core"
|
||||
import { structures, TestConfiguration, mocks } from "../../../../tests"
|
||||
import {
|
||||
structures,
|
||||
TestConfiguration,
|
||||
mocks,
|
||||
generator,
|
||||
} from "../../../../tests"
|
||||
import { UserGroup } from "@budibase/types"
|
||||
|
||||
mocks.licenses.useGroups()
|
||||
|
@ -134,5 +139,52 @@ describe("/api/global/groups", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("existing users", () => {
|
||||
let groupId: string
|
||||
let users: { _id: string; email: string }[] = []
|
||||
|
||||
beforeAll(async () => {
|
||||
groupId = (
|
||||
await config.api.groups.saveGroup(structures.groups.UserGroup())
|
||||
).body._id
|
||||
|
||||
await Promise.all(
|
||||
Array.from({ length: 30 }).map(async (_, i) => {
|
||||
const email = `user${i}@${generator.domain()}`
|
||||
const user = await config.api.users.saveUser({
|
||||
...structures.users.user(),
|
||||
email,
|
||||
})
|
||||
users.push({ _id: user.body._id, email })
|
||||
})
|
||||
)
|
||||
users = users.sort((a, b) => a._id.localeCompare(b._id))
|
||||
await config.api.groups.updateGroupUsers(groupId, {
|
||||
add: users.map(u => u._id),
|
||||
remove: [],
|
||||
})
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -24,9 +24,25 @@ export class GroupsAPI extends TestAPI {
|
|||
.expect(200)
|
||||
}
|
||||
|
||||
searchUsers = (id: string) => {
|
||||
searchUsers = (id: string, params?: { bookmark?: string }) => {
|
||||
let url = `/api/global/groups/${id}/users?`
|
||||
if (params?.bookmark) {
|
||||
url += `bookmark=${params.bookmark}&`
|
||||
}
|
||||
return this.request
|
||||
.get(`/api/global/groups/${id}/users`)
|
||||
.get(url)
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
}
|
||||
|
||||
updateGroupUsers = (
|
||||
id: string,
|
||||
body: { add: string[]; remove: string[] }
|
||||
) => {
|
||||
return this.request
|
||||
.post(`/api/global/groups/${id}/users`)
|
||||
.send(body)
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
|
|
Loading…
Reference in New Issue