|
|
|
@ -7,7 +7,10 @@ const workerRequests = require("../../../utilities/workerRequests") |
|
|
|
jest.mock("../../../utilities/workerRequests", () => ({ |
|
|
|
getGlobalUsers: jest.fn(), |
|
|
|
saveGlobalUser: jest.fn(() => { |
|
|
|
return {} |
|
|
|
const uuid = require("uuid/v4") |
|
|
|
return { |
|
|
|
_id: `us_${uuid()}` |
|
|
|
} |
|
|
|
}), |
|
|
|
deleteGlobalUser: jest.fn(), |
|
|
|
})) |
|
|
|
@ -26,10 +29,10 @@ describe("/users", () => { |
|
|
|
beforeEach(() => { |
|
|
|
workerRequests.getGlobalUsers.mockImplementationOnce(() => ([ |
|
|
|
{ |
|
|
|
email: "brenda@brenda.com" |
|
|
|
_id: "us_uuid1", |
|
|
|
}, |
|
|
|
{ |
|
|
|
email: "pam@pam.com" |
|
|
|
_id: "us_uuid2", |
|
|
|
} |
|
|
|
] |
|
|
|
)) |
|
|
|
@ -45,8 +48,8 @@ describe("/users", () => { |
|
|
|
.expect(200) |
|
|
|
|
|
|
|
expect(res.body.length).toBe(2) |
|
|
|
expect(res.body.find(u => u.email === "brenda@brenda.com")).toBeDefined() |
|
|
|
expect(res.body.find(u => u.email === "pam@pam.com")).toBeDefined() |
|
|
|
expect(res.body.find(u => u._id === `ro_ta_users_us_uuid1`)).toBeDefined() |
|
|
|
expect(res.body.find(u => u._id === `ro_ta_users_us_uuid2`)).toBeDefined() |
|
|
|
}) |
|
|
|
|
|
|
|
it("should apply authorization to endpoint", async () => { |
|
|
|
@ -66,10 +69,10 @@ describe("/users", () => { |
|
|
|
beforeEach(() => { |
|
|
|
workerRequests.getGlobalUsers.mockImplementationOnce(() => ([ |
|
|
|
{ |
|
|
|
email: "bill@budibase.com" |
|
|
|
_id: "us_uuid1", |
|
|
|
}, |
|
|
|
{ |
|
|
|
email: "brandNewUser@user.com" |
|
|
|
_id: "us_uuid2", |
|
|
|
} |
|
|
|
] |
|
|
|
)) |
|
|
|
@ -86,7 +89,6 @@ describe("/users", () => { |
|
|
|
|
|
|
|
it("returns a success message when a user is successfully created", async () => { |
|
|
|
const body = basicUser(BUILTIN_ROLE_IDS.POWER) |
|
|
|
body.email = "bill@budibase.com" |
|
|
|
const res = await create(body) |
|
|
|
|
|
|
|
expect(res.res.statusMessage).toEqual("OK") |
|
|
|
@ -95,7 +97,6 @@ describe("/users", () => { |
|
|
|
|
|
|
|
it("should apply authorization to endpoint", async () => { |
|
|
|
const body = basicUser(BUILTIN_ROLE_IDS.POWER) |
|
|
|
body.email = "brandNewUser@user.com" |
|
|
|
await checkPermissionsEndpoint({ |
|
|
|
config, |
|
|
|
method: "POST", |
|
|
|
@ -110,13 +111,6 @@ describe("/users", () => { |
|
|
|
const user = basicUser(null) |
|
|
|
await create(user, 400) |
|
|
|
}) |
|
|
|
|
|
|
|
it("should throw error if user exists already", async () => { |
|
|
|
await config.createUser("test@test.com") |
|
|
|
const user = basicUser(BUILTIN_ROLE_IDS.POWER) |
|
|
|
user.email = "test@test.com" |
|
|
|
await create(user, 409) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("update", () => { |
|
|
|
@ -141,10 +135,9 @@ describe("/users", () => { |
|
|
|
|
|
|
|
describe("destroy", () => { |
|
|
|
it("should be able to delete the user", async () => { |
|
|
|
const email = "test@test.com" |
|
|
|
await config.createUser(email) |
|
|
|
const user = await config.createUser() |
|
|
|
const res = await request |
|
|
|
.delete(`/api/users/metadata/${email}`) |
|
|
|
.delete(`/api/users/metadata/${user._id}`) |
|
|
|
.set(config.defaultHeaders()) |
|
|
|
.expect(200) |
|
|
|
.expect("Content-Type", /json/) |
|
|
|
@ -156,21 +149,23 @@ describe("/users", () => { |
|
|
|
describe("find", () => { |
|
|
|
beforeEach(() => { |
|
|
|
jest.resetAllMocks() |
|
|
|
workerRequests.saveGlobalUser.mockImplementationOnce(() => ({ |
|
|
|
_id: "us_uuid1", |
|
|
|
})) |
|
|
|
workerRequests.getGlobalUsers.mockImplementationOnce(() => ({ |
|
|
|
email: "test@test.com", |
|
|
|
_id: "us_uuid1", |
|
|
|
roleId: BUILTIN_ROLE_IDS.POWER, |
|
|
|
})) |
|
|
|
}) |
|
|
|
|
|
|
|
it("should be able to find the user", async () => { |
|
|
|
const email = "test@test.com" |
|
|
|
await config.createUser(email) |
|
|
|
const user = await config.createUser() |
|
|
|
const res = await request |
|
|
|
.get(`/api/users/metadata/${email}`) |
|
|
|
.get(`/api/users/metadata/${user._id}`) |
|
|
|
.set(config.defaultHeaders()) |
|
|
|
.expect(200) |
|
|
|
.expect("Content-Type", /json/) |
|
|
|
expect(res.body.email).toEqual(email) |
|
|
|
expect(res.body._id).toEqual(user._id) |
|
|
|
expect(res.body.roleId).toEqual(BUILTIN_ROLE_IDS.POWER) |
|
|
|
expect(res.body.tableId).toBeDefined() |
|
|
|
}) |
|
|
|
|