Updating test case which has been occasionally throwing 409 issues.

This commit is contained in:
mike12345567 2023-02-10 18:29:29 +00:00
parent 720e7019c2
commit 043b534138
3 changed files with 36 additions and 37 deletions

View File

@ -1,4 +1,4 @@
const { roles } = require("@budibase/backend-core") const { roles, utils } = require("@budibase/backend-core")
const { checkPermissionsEndpoint } = require("./utilities/TestFunctions") const { checkPermissionsEndpoint } = require("./utilities/TestFunctions")
const setup = require("./utilities") const setup = require("./utilities")
const { BUILTIN_ROLE_IDS } = roles const { BUILTIN_ROLE_IDS } = roles
@ -28,8 +28,8 @@ describe("/users", () => {
describe("fetch", () => { describe("fetch", () => {
it("returns a list of users from an instance db", async () => { it("returns a list of users from an instance db", async () => {
await config.createUser("uuidx") await config.createUser({ id: "uuidx" })
await config.createUser("uuidy") await config.createUser({ id: "uuidy" })
const res = await request const res = await request
.get(`/api/users/metadata`) .get(`/api/users/metadata`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())
@ -56,7 +56,7 @@ describe("/users", () => {
describe("update", () => { describe("update", () => {
it("should be able to update the user", async () => { it("should be able to update the user", async () => {
const user = await config.createUser() const user = await config.createUser({ id: `us_update${Math.random()}` })
user.roleId = BUILTIN_ROLE_IDS.BASIC user.roleId = BUILTIN_ROLE_IDS.BASIC
const res = await request const res = await request
.put(`/api/users/metadata`) .put(`/api/users/metadata`)
@ -180,14 +180,11 @@ describe("/users", () => {
const app1 = await config.createApp('App 1') const app1 = await config.createApp('App 1')
const app2 = await config.createApp('App 2') const app2 = await config.createApp('App 2')
let user = await config.createUser( let user = await config.createUser({
undefined, builder: false,
undefined, admin: true,
undefined, roles: { [app1.appId]: 'ADMIN' }
undefined, })
false,
true,
{ [app1.appId]: 'ADMIN' })
let res = await request let res = await request
.post(`/api/users/metadata/sync/${user._id}`) .post(`/api/users/metadata/sync/${user._id}`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())

View File

@ -93,24 +93,16 @@ describe("migrations", () => {
await clearMigrations() await clearMigrations()
const appId = config.prodAppId const appId = config.prodAppId
const roles = { [appId]: "role_12345" } const roles = { [appId]: "role_12345" }
await config.createUser( await config.createUser({
undefined, builder: false,
undefined, admin: true,
undefined, roles,
undefined, }) // admin only
false, await config.createUser({
true, builder: false,
roles admin: false,
) // admin only roles,
await config.createUser( }) // non admin non builder
undefined,
undefined,
undefined,
undefined,
false,
false,
roles
) // non admin non builder
await config.createTable() await config.createTable()
await config.createRow() await config.createRow()
await config.createRow() await config.createRow()

View File

@ -275,14 +275,24 @@ class TestConfiguration {
} }
async createUser( async createUser(
id = null, user: {
firstName = this.defaultUserValues.firstName, id?: string
lastName = this.defaultUserValues.lastName, firstName?: string
email = this.defaultUserValues.email, lastName?: string
builder = true, email?: string
admin = false, builder?: boolean
roles = {} admin?: boolean
roles?: any
} = {}
) { ) {
let { id, firstName, lastName, email, builder, admin, roles } = user
firstName = firstName || this.defaultUserValues.firstName
lastName = lastName || this.defaultUserValues.lastName
email = email || this.defaultUserValues.email
roles = roles || {}
if (builder == null) {
builder = true
}
const globalId = !id ? `us_${Math.random()}` : `us_${id}` const globalId = !id ? `us_${Math.random()}` : `us_${id}`
const resp = await this.globalUser({ const resp = await this.globalUser({
id: globalId, id: globalId,