From 7def2059f7f4d27ae447069dce56fafb94b0d61b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 10 Feb 2023 18:29:29 +0000 Subject: [PATCH] Updating test case which has been occasionally throwing 409 issues. --- .../server/src/api/routes/tests/user.spec.js | 21 ++++++-------- .../server/src/migrations/tests/index.spec.ts | 28 +++++++------------ .../src/tests/utilities/TestConfiguration.ts | 24 +++++++++++----- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/packages/server/src/api/routes/tests/user.spec.js b/packages/server/src/api/routes/tests/user.spec.js index e5e280009e..bae784cf3d 100644 --- a/packages/server/src/api/routes/tests/user.spec.js +++ b/packages/server/src/api/routes/tests/user.spec.js @@ -1,4 +1,4 @@ -const { roles } = require("@budibase/backend-core") +const { roles, utils } = require("@budibase/backend-core") const { checkPermissionsEndpoint } = require("./utilities/TestFunctions") const setup = require("./utilities") const { BUILTIN_ROLE_IDS } = roles @@ -28,8 +28,8 @@ describe("/users", () => { describe("fetch", () => { it("returns a list of users from an instance db", async () => { - await config.createUser("uuidx") - await config.createUser("uuidy") + await config.createUser({ id: "uuidx" }) + await config.createUser({ id: "uuidy" }) const res = await request .get(`/api/users/metadata`) .set(config.defaultHeaders()) @@ -56,7 +56,7 @@ describe("/users", () => { describe("update", () => { 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 const res = await request .put(`/api/users/metadata`) @@ -180,14 +180,11 @@ describe("/users", () => { const app1 = await config.createApp('App 1') const app2 = await config.createApp('App 2') - let user = await config.createUser( - undefined, - undefined, - undefined, - undefined, - false, - true, - { [app1.appId]: 'ADMIN' }) + let user = await config.createUser({ + builder: false, + admin: true, + roles: { [app1.appId]: 'ADMIN' } + }) let res = await request .post(`/api/users/metadata/sync/${user._id}`) .set(config.defaultHeaders()) diff --git a/packages/server/src/migrations/tests/index.spec.ts b/packages/server/src/migrations/tests/index.spec.ts index 8e52831c5e..b0fd971f42 100644 --- a/packages/server/src/migrations/tests/index.spec.ts +++ b/packages/server/src/migrations/tests/index.spec.ts @@ -93,24 +93,16 @@ describe("migrations", () => { await clearMigrations() const appId = config.prodAppId const roles = { [appId]: "role_12345" } - await config.createUser( - undefined, - undefined, - undefined, - undefined, - false, - true, - roles - ) // admin only - await config.createUser( - undefined, - undefined, - undefined, - undefined, - false, - false, - roles - ) // non admin non builder + await config.createUser({ + builder: false, + admin: true, + roles, + }) // admin only + await config.createUser({ + builder: false, + admin: false, + roles, + }) // non admin non builder await config.createTable() await config.createRow() await config.createRow() diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 5c45f89a2b..aa149b092c 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -275,14 +275,24 @@ class TestConfiguration { } async createUser( - id = null, - firstName = this.defaultUserValues.firstName, - lastName = this.defaultUserValues.lastName, - email = this.defaultUserValues.email, - builder = true, - admin = false, - roles = {} + user: { + id?: string + firstName?: string + lastName?: string + email?: string + builder?: boolean + 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 resp = await this.globalUser({ id: globalId,