forked from tsai/budibase
12 changed files with 174 additions and 53 deletions
@ -0,0 +1,58 @@ |
|||
jest.mock("nodemailer") |
|||
const { config, request } = require("../../../tests") |
|||
const { events, utils } = require("@budibase/backend-core") |
|||
|
|||
describe("/api/global/self", () => { |
|||
|
|||
beforeAll(async () => { |
|||
await config.beforeAll() |
|||
}) |
|||
|
|||
afterAll(async () => { |
|||
await config.afterAll() |
|||
}) |
|||
|
|||
beforeEach(() => { |
|||
jest.clearAllMocks() |
|||
}) |
|||
|
|||
const updateSelf = async (user) => { |
|||
const res = await request |
|||
.post(`/api/global/self`) |
|||
.send(user) |
|||
.set(config.defaultHeaders()) |
|||
.expect("Content-Type", /json/) |
|||
.expect(200) |
|||
return res |
|||
} |
|||
|
|||
describe("update", () => { |
|||
|
|||
it("should update self", async () => { |
|||
const user = await config.createUser() |
|||
|
|||
const res = await updateSelf(user) |
|||
|
|||
delete user.password |
|||
expect(res.body._id).toBe(user._id) |
|||
expect(events.user.updated).toBeCalledTimes(1) |
|||
expect(events.user.updated).toBeCalledWith(user) |
|||
expect(events.user.passwordUpdated).not.toBeCalled() |
|||
}) |
|||
|
|||
it("should update password", async () => { |
|||
const user = await config.createUser() |
|||
const password = "newPassword" |
|||
user.password = password |
|||
|
|||
const res = await updateSelf(user) |
|||
|
|||
delete user.password |
|||
expect(res.body._id).toBe(user._id) |
|||
expect(events.user.updated).toBeCalledTimes(1) |
|||
expect(events.user.updated).toBeCalledWith(user) |
|||
expect(events.user.passwordUpdated).toBeCalledTimes(1) |
|||
expect(events.user.passwordUpdated).toBeCalledWith(user) |
|||
}) |
|||
}) |
|||
}) |
|||
Loading…
Reference in new issue