Fix tests

This commit is contained in:
Adria Navarro 2024-01-03 11:41:57 +01:00
parent 1a0361e33f
commit 874c3f9dd4
2 changed files with 11 additions and 6 deletions

View File

@ -229,7 +229,7 @@ describe("/api/global/auth", () => {
) )
expect(res.body).toEqual({ expect(res.body).toEqual({
message: "Cannot reset password.", message: "Password change is disabled for this user",
status: 400, status: 400,
}) })
} }
@ -261,8 +261,13 @@ describe("/api/global/auth", () => {
) )
// convert to account owner now that password has been requested // convert to account owner now that password has been requested
const account = structures.accounts.ssoAccount() as CloudAccount const account: CloudAccount = {
mocks.accounts.getAccount.mockReturnValueOnce( ...structures.accounts.ssoAccount(),
budibaseUserId: user._id!,
email: user.email,
tenantId: config.getTenantId(),
}
mocks.accounts.getAccountByTenantId.mockReturnValueOnce(
Promise.resolve(account) Promise.resolve(account)
) )

View File

@ -74,14 +74,14 @@ export const reset = async (email: string) => {
* Perform the user password update if the provided reset code is valid. * Perform the user password update if the provided reset code is valid.
*/ */
export const resetUpdate = async (resetCode: string, password: string) => { export const resetUpdate = async (resetCode: string, password: string) => {
const { userId } = await cache.passwordReset.getCode(resetCode)
let user = await userSdk.db.getUser(userId)
const validation = security.validatePassword(password) const validation = security.validatePassword(password)
if (!validation.valid) { if (!validation.valid) {
throw new HTTPError(validation.error, 400) throw new HTTPError(validation.error, 400)
} }
const { userId } = await cache.passwordReset.getCode(resetCode)
let user = await userSdk.db.getUser(userId)
user.password = password user.password = password
user = await userSdk.db.save(user) user = await userSdk.db.save(user)