Changes for Account API Testing

This commit is contained in:
Mitch-Budibase 2023-07-14 14:24:01 +01:00
parent 6f7ef18084
commit fa94b8b9fc
9 changed files with 51 additions and 10 deletions

View File

@ -53,6 +53,8 @@ async function passportCallback(
}
export const login = async (ctx: Ctx<LoginRequest>, next: any) => {
const tenantId = context.getTenantId()
console.log(tenantId)
const email = ctx.request.body.username
const user = await userSdk.getUserByEmail(email)

View File

@ -73,6 +73,13 @@ export default class AccountAPI {
return response
}
async deleteCurrentAccount() {
const [response, json] = await this.client.del(
`/api/accounts`
)
return response
}
async verifyAccount(
verificationCode: string,
opts: APIRequestOpts = { doExpect: true }

View File

@ -18,7 +18,7 @@ export default class AuthAPI {
`/api/auth/login`,
{
body: {
username: email,
email: email,
password: password,
},
}

View File

@ -27,8 +27,6 @@ export default class TestConfiguration<T> extends BudibaseTestConfiguration {
this.state.apiKey = apiKeyResponse.apiKey
}
async setCookieAuth() {
const apiKeyResponse = await this.internalApi.self.getApiKey()
this.state.apiKey = apiKeyResponse.apiKey
}
}

View File

@ -14,7 +14,7 @@ describe("Account API - Create Account", () => {
it("Creates a new account", async () => {
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
...fixtures.accounts.generateAccount()
})
})
})

View File

@ -12,9 +12,26 @@ describe("Account API - Delete Account", () => {
await config.afterAll()
})
// it("Deletes an account", async () => {
//
// })
it("Deletes an account", async () => {
// Create account
const createAccountRequest = fixtures.accounts.generateAccount()
await config.api.accounts.create(
createAccountRequest
)
// Login - Get cookie
await config.login(
createAccountRequest.email,
createAccountRequest.password,
createAccountRequest.tenantId
)
// Delete account
const [ res ] = await config.api.accounts.deleteCurrentAccount()
expect(res.status).toBe(204)
})
it("Deletes an account by ID", async () => {
const [response, account] = await config.api.accounts.create({

View File

@ -18,10 +18,12 @@ describe("Account API - Validate Account", () => {
it("Validates an email", async () => {
await config.api.accounts.validateEmail(email)
})
it("Validates a tenant ID", async () => {
await config.api.accounts.validateTenantId(tenant)
})
})

View File

@ -15,10 +15,24 @@ describe("Account API - Verify Account", () => {
it("Verify an account", async () => {
// Create account
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
// Invite user
// Verify account via code
await config.api.accounts.verifyAccount()
})
it("Send account verification email ", async () => {
// Create account
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
// Invite user
// Verify account via email
await config.api.accounts.verifyAccountSendEmail()
})
})

View File

@ -43,7 +43,8 @@ export default class BudibaseTestConfiguration {
async login(email: string, password: string, tenantId?: string) {
if (!tenantId && this.state.tenantId) {
tenantId = this.state.tenantId
} else {
}
if (!tenantId) {
throw new Error("Could not determine tenant id")
}
const [res, cookie] = await this.internalApi.auth.login(