Add basic test
This commit is contained in:
parent
f722f9e2d6
commit
dcacd6bf17
|
@ -2,7 +2,7 @@ import env from "../environment"
|
||||||
import * as eventHelpers from "./events"
|
import * as eventHelpers from "./events"
|
||||||
import * as accountSdk from "../accounts"
|
import * as accountSdk from "../accounts"
|
||||||
import * as cache from "../cache"
|
import * as cache from "../cache"
|
||||||
import { doInTenant, getGlobalDB, getIdentity, getTenantId } from "../context"
|
import { getGlobalDB, getIdentity, getTenantId } from "../context"
|
||||||
import * as dbUtils from "../db"
|
import * as dbUtils from "../db"
|
||||||
import { EmailUnavailableError, HTTPError } from "../errors"
|
import { EmailUnavailableError, HTTPError } from "../errors"
|
||||||
import * as platform from "../platform"
|
import * as platform from "../platform"
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { cache, context, utils } from "@budibase/backend-core"
|
||||||
|
import { resetUpdate } from "../auth"
|
||||||
|
import { generator, structures } from "@budibase/backend-core/tests"
|
||||||
|
import { TestConfiguration } from "../../../tests"
|
||||||
|
|
||||||
|
describe("auth", () => {
|
||||||
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
|
describe("resetUpdate", () => {
|
||||||
|
it("providing a valid code will update the password", async () => {
|
||||||
|
await context.doInTenant(structures.tenant.id(), async () => {
|
||||||
|
const user = await config.createUser()
|
||||||
|
const previousPassword = user.password
|
||||||
|
|
||||||
|
const code = await cache.passwordReset.createCode(user._id!, {})
|
||||||
|
const newPassword = generator.hash()
|
||||||
|
|
||||||
|
await resetUpdate(code, newPassword)
|
||||||
|
|
||||||
|
const persistedUser = await config.getUser(user.email)
|
||||||
|
expect(persistedUser.password).not.toBe(previousPassword)
|
||||||
|
expect(
|
||||||
|
await utils.compare(newPassword, persistedUser.password!)
|
||||||
|
).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -1,6 +1,5 @@
|
||||||
import { structures, mocks } from "../../../tests"
|
import { structures, mocks } from "../../../tests"
|
||||||
import { env, context } from "@budibase/backend-core"
|
import { env, context } from "@budibase/backend-core"
|
||||||
import * as users from "../users"
|
|
||||||
import { db as userDb } from "../"
|
import { db as userDb } from "../"
|
||||||
import { CloudAccount } from "@budibase/types"
|
import { CloudAccount } from "@budibase/types"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue