1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12:00
budibase/packages/worker/src/tests/api/auth.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

import TestConfiguration from "../TestConfiguration"
2022-11-12 04:43:41 +13:00
import { TestAPI } from "./base"
2022-11-12 04:43:41 +13:00
export class AuthAPI extends TestAPI {
constructor(config: TestConfiguration) {
2022-11-12 04:43:41 +13:00
super(config)
}
updatePassword = (code: string) => {
return this.request
.post(`/api/global/auth/${this.config.getTenantId()}/reset/update`)
.send({
password: "newpassword",
resetCode: code,
})
.expect("Content-Type", /json/)
.expect(200)
}
logout = () => {
return this.request
.post("/api/global/auth/logout")
.set(this.config.defaultHeaders())
.expect(200)
}
requestPasswordReset = async (sendMailMock: any) => {
await this.config.saveSmtpConfig()
await this.config.saveSettingsConfig()
await this.config.createUser()
const res = await this.request
.post(`/api/global/auth/${this.config.getTenantId()}/reset`)
.send({
email: "test@test.com",
})
.expect("Content-Type", /json/)
.expect(200)
const emailCall = sendMailMock.mock.calls[0][0]
const parts = emailCall.html.split(
`http://localhost:10000/builder/auth/reset?code=`
)
const code = parts[1].split('"')[0].split("&")[0]
return { code, res }
}
}