Merge pull request #10217 from Budibase/test/fix_flaky_test
Test - Fix flaky test
This commit is contained in:
commit
b11818d2d6
|
@ -57,6 +57,7 @@ describe("/users", () => {
|
|||
it("should be able to update the user", async () => {
|
||||
const user = await config.createUser({ id: `us_update${utils.newid()}` })
|
||||
user.roleId = BUILTIN_ROLE_IDS.BASIC
|
||||
delete user._rev
|
||||
const res = await request
|
||||
.put(`/api/users/metadata`)
|
||||
.set(config.defaultHeaders())
|
||||
|
@ -65,6 +66,46 @@ describe("/users", () => {
|
|||
.expect("Content-Type", /json/)
|
||||
expect(res.body.ok).toEqual(true)
|
||||
})
|
||||
|
||||
it("should be able to update the user multiple times", async () => {
|
||||
const user = await config.createUser()
|
||||
delete user._rev
|
||||
|
||||
const res1 = await request
|
||||
.put(`/api/users/metadata`)
|
||||
.set(config.defaultHeaders())
|
||||
.send({ ...user, roleId: BUILTIN_ROLE_IDS.BASIC })
|
||||
.expect(200)
|
||||
.expect("Content-Type", /json/)
|
||||
|
||||
const res = await request
|
||||
.put(`/api/users/metadata`)
|
||||
.set(config.defaultHeaders())
|
||||
.send({ ...user, _rev: res1.body.rev, roleId: BUILTIN_ROLE_IDS.POWER })
|
||||
.expect(200)
|
||||
.expect("Content-Type", /json/)
|
||||
|
||||
expect(res.body.ok).toEqual(true)
|
||||
})
|
||||
|
||||
it("should require the _rev field for multiple updates", async () => {
|
||||
const user = await config.createUser()
|
||||
delete user._rev
|
||||
|
||||
await request
|
||||
.put(`/api/users/metadata`)
|
||||
.set(config.defaultHeaders())
|
||||
.send({ ...user, roleId: BUILTIN_ROLE_IDS.BASIC })
|
||||
.expect(200)
|
||||
.expect("Content-Type", /json/)
|
||||
|
||||
await request
|
||||
.put(`/api/users/metadata`)
|
||||
.set(config.defaultHeaders())
|
||||
.send({ ...user, roleId: BUILTIN_ROLE_IDS.POWER })
|
||||
.expect(409)
|
||||
.expect("Content-Type", /json/)
|
||||
})
|
||||
})
|
||||
|
||||
describe("destroy", () => {
|
||||
|
@ -92,6 +133,7 @@ describe("/users", () => {
|
|||
expect(res.body.tableId).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("setFlag", () => {
|
||||
it("should throw an error if a flag is not provided", async () => {
|
||||
await config.createUser()
|
||||
|
@ -101,8 +143,9 @@ describe("/users", () => {
|
|||
.send({ value: "test" })
|
||||
.expect(400)
|
||||
.expect("Content-Type", /json/)
|
||||
expect(res.body.message).toEqual("Must supply a 'flag' field in request body.")
|
||||
|
||||
expect(res.body.message).toEqual(
|
||||
"Must supply a 'flag' field in request body."
|
||||
)
|
||||
})
|
||||
|
||||
it("should be able to set a flag on the user", async () => {
|
||||
|
@ -146,8 +189,9 @@ describe("/users", () => {
|
|||
.send({ value: "test" })
|
||||
.expect(400)
|
||||
.expect("Content-Type", /json/)
|
||||
expect(res.body.message).toEqual("Must supply a 'flag' field in request body.")
|
||||
|
||||
expect(res.body.message).toEqual(
|
||||
"Must supply a 'flag' field in request body."
|
||||
)
|
||||
})
|
||||
|
||||
it("should be able to set a flag on the user", async () => {
|
||||
|
@ -165,33 +209,37 @@ describe("/users", () => {
|
|||
describe("syncUser", () => {
|
||||
it("should sync the user", async () => {
|
||||
let user = await config.createUser()
|
||||
await config.createApp('New App')
|
||||
await config.createApp("New App")
|
||||
let res = await request
|
||||
.post(`/api/users/metadata/sync/${user._id}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect(200)
|
||||
.expect("Content-Type", /json/)
|
||||
expect(res.body.message).toEqual('User synced.')
|
||||
expect(res.body.message).toEqual("User synced.")
|
||||
})
|
||||
|
||||
|
||||
it("should sync the user when a previous user is specified", async () => {
|
||||
const app1 = await config.createApp('App 1')
|
||||
const app2 = await config.createApp('App 2')
|
||||
const app1 = await config.createApp("App 1")
|
||||
const app2 = await config.createApp("App 2")
|
||||
|
||||
let user = await config.createUser({
|
||||
builder: false,
|
||||
admin: true,
|
||||
roles: { [app1.appId]: 'ADMIN' }
|
||||
})
|
||||
roles: { [app1.appId]: "ADMIN" },
|
||||
})
|
||||
let res = await request
|
||||
.post(`/api/users/metadata/sync/${user._id}`)
|
||||
.set(config.defaultHeaders())
|
||||
.send({ previousUser: { ...user, roles: { ...user.roles, [app2.appId]: 'BASIC' } } })
|
||||
.send({
|
||||
previousUser: {
|
||||
...user,
|
||||
roles: { ...user.roles, [app2.appId]: "BASIC" },
|
||||
},
|
||||
})
|
||||
.expect(200)
|
||||
.expect("Content-Type", /json/)
|
||||
|
||||
expect(res.body.message).toEqual('User synced.')
|
||||
expect(res.body.message).toEqual("User synced.")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue