Merge pull request #10217 from Budibase/test/fix_flaky_test

Test - Fix flaky test
This commit is contained in:
Adria Navarro 2023-04-05 14:10:25 +02:00 committed by GitHub
commit b11818d2d6
1 changed files with 61 additions and 13 deletions

View File

@ -57,6 +57,7 @@ describe("/users", () => {
it("should be able to update the user", async () => { it("should be able to update the user", async () => {
const user = await config.createUser({ id: `us_update${utils.newid()}` }) const user = await config.createUser({ id: `us_update${utils.newid()}` })
user.roleId = BUILTIN_ROLE_IDS.BASIC user.roleId = BUILTIN_ROLE_IDS.BASIC
delete user._rev
const res = await request const res = await request
.put(`/api/users/metadata`) .put(`/api/users/metadata`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())
@ -65,6 +66,46 @@ describe("/users", () => {
.expect("Content-Type", /json/) .expect("Content-Type", /json/)
expect(res.body.ok).toEqual(true) 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", () => { describe("destroy", () => {
@ -92,6 +133,7 @@ describe("/users", () => {
expect(res.body.tableId).toBeDefined() expect(res.body.tableId).toBeDefined()
}) })
}) })
describe("setFlag", () => { describe("setFlag", () => {
it("should throw an error if a flag is not provided", async () => { it("should throw an error if a flag is not provided", async () => {
await config.createUser() await config.createUser()
@ -101,8 +143,9 @@ describe("/users", () => {
.send({ value: "test" }) .send({ value: "test" })
.expect(400) .expect(400)
.expect("Content-Type", /json/) .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 () => { it("should be able to set a flag on the user", async () => {
@ -146,8 +189,9 @@ describe("/users", () => {
.send({ value: "test" }) .send({ value: "test" })
.expect(400) .expect(400)
.expect("Content-Type", /json/) .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 () => { it("should be able to set a flag on the user", async () => {
@ -165,33 +209,37 @@ describe("/users", () => {
describe("syncUser", () => { describe("syncUser", () => {
it("should sync the user", async () => { it("should sync the user", async () => {
let user = await config.createUser() let user = await config.createUser()
await config.createApp('New App') await config.createApp("New App")
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())
.expect(200) .expect(200)
.expect("Content-Type", /json/) .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 () => { it("should sync the user when a previous user is specified", async () => {
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({
builder: false, builder: false,
admin: true, admin: true,
roles: { [app1.appId]: 'ADMIN' } roles: { [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())
.send({ previousUser: { ...user, roles: { ...user.roles, [app2.appId]: 'BASIC' } } }) .send({
previousUser: {
...user,
roles: { ...user.roles, [app2.appId]: "BASIC" },
},
})
.expect(200) .expect(200)
.expect("Content-Type", /json/) .expect("Content-Type", /json/)
expect(res.body.message).toEqual('User synced.') expect(res.body.message).toEqual("User synced.")
}) })
}) })
}) })