1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Account Portal API Testing

This commit is contained in:
Mitch-Budibase 2023-07-13 12:36:50 +01:00
parent 8e24ae40f0
commit d8d4686e01
10 changed files with 230 additions and 0 deletions

View file

@ -20,6 +20,8 @@ export enum Header {
TYPE = "x-budibase-type",
PREVIEW_ROLE = "x-budibase-role",
TENANT_ID = "x-budibase-tenant-id",
VERIFICATION_CODE = "x-budibase-verification-code",
RETURN_VERIFICATION_CODE = "x-budibase-return-verification-code",
TOKEN = "x-budibase-token",
CSRF_TOKEN = "x-csrf-token",
CORRELATION_ID = "x-budibase-correlation-id",

View file

@ -72,4 +72,59 @@ export default class AccountAPI {
}
return response
}
async verifyAccount(
verificationCode: string,
opts: APIRequestOpts = { doExpect: true }
): Promise<Response> {
const [response, json] = await this.client.post(
`/api/accounts/verify`,
{
body: { verificationCode },
}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
return response
}
async verifyAccountSendEmail(
email: string,
opts: APIRequestOpts = { doExpect: true }
): Promise<Response> {
const [response, json] = await this.client.post(
`/api/accounts/verify/send`,
{
body: { email },
}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
return response
}
async search(
searchType: string,
search: 'email' | 'tenantId',
opts: APIRequestOpts = { doExpect: true }
): Promise<Response> {
let body: { email?: string; tenantId?: string } = {}
if (search === 'email') {
body.email = searchType;
} else if (search === 'tenantId') {
body.tenantId = searchType;
}
const [response, json] = await this.client.post(
`/api/accounts/search`,
{body: body}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
return response
}
}

View file

@ -0,0 +1,34 @@
import { AccountInternalAPI } from "../api"
import { BudibaseTestConfiguration } from "../../shared"
export default class TestConfiguration<T> extends BudibaseTestConfiguration {
// apis
api: AccountInternalAPI
context: T
constructor() {
super()
this.api = new AccountInternalAPI(this.state)
this.context = <T>{}
}
async beforeAll() {
await super.beforeAll()
await this.setApiKey()
}
async afterAll() {
await super.afterAll()
}
async setApiKey() {
const apiKeyResponse = await this.internalApi.self.getApiKey()
this.state.apiKey = apiKeyResponse.apiKey
}
async setCookieAuth() {
const apiKeyResponse = await this.internalApi.self.getApiKey()
this.state.apiKey = apiKeyResponse.apiKey
}
}

View file

@ -0,0 +1,20 @@
import { generator } from "../../shared"
import { Hosting, CreateAccountRequest } from "@budibase/types"
export const generateAccount = (): CreateAccountRequest => {
const uuid = generator.guid()
const email = `${uuid}@budibase.com`
const tenant = `tenant${uuid.replace(/-/g, "")}`
return {
email,
hosting: Hosting.CLOUD,
name: email,
password: uuid,
profession: "software_engineer",
size: "10+",
tenantId: tenant,
tenantName: tenant,
}
}

View file

@ -0,0 +1 @@
export * as accounts from "./accounts"

View file

@ -0,0 +1,20 @@
import TestConfiguration from "../../config/TestConfiguration"
import * as fixtures from "../../fixtures"
describe("Account API - Create Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("Creates a new account", async () => {
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
})
})

View file

@ -0,0 +1,25 @@
import TestConfiguration from "../../config/TestConfiguration"
import * as fixtures from "../../fixtures"
describe("Account API - Delete Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
// it("Deletes an account", async () => {
//
// })
it("Deletes an account by ID", async () => {
const [response, account] = await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
await config.api.accounts.delete(account.accountId)
})
})

View file

@ -0,0 +1,22 @@
import TestConfiguration from "../../config/TestConfiguration"
import { generator } from "../../../shared"
describe("Account API - Search for Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("Search account by email", async () => {
await config.api.accounts.search(generator.email(), "email")
})
it("Search account by tenantId", async () => {
await config.api.accounts.search(generator.word(), "tenantId")
})
})

View file

@ -0,0 +1,27 @@
import TestConfiguration from "../../config/TestConfiguration"
import { generator } from "../../../shared"
import * as fixtures from "../../fixtures";
describe("Account API - Validate Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
const tenant = generator.word({length: 6})
const email = `${tenant}@budibase.com`
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

@ -0,0 +1,24 @@
import TestConfiguration from "../../config/TestConfiguration"
import { generator } from "../../../shared"
import * as fixtures from "../../fixtures";
describe("Account API - Verify Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("Verify an account", async () => {
await config.api.accounts.verifyAccount()
})
it("Send account verification email ", async () => {
await config.api.accounts.verifyAccountSendEmail()
})
})