Update account search tests / add email to state
This commit is contained in:
parent
c464e5c91d
commit
278f6f8df3
|
@ -1,5 +1,5 @@
|
|||
import { Response } from "node-fetch"
|
||||
import { Account, CreateAccountRequest } from "@budibase/types"
|
||||
import { Account, CreateAccountRequest, SearchAccountsRequest, SearchAccountsResponse } from "@budibase/types"
|
||||
import AccountInternalAPIClient from "../AccountInternalAPIClient"
|
||||
import { APIRequestOpts } from "../../../types"
|
||||
|
||||
|
@ -116,8 +116,8 @@ export default class AccountAPI {
|
|||
searchType: string,
|
||||
search: 'email' | 'tenantId',
|
||||
opts: APIRequestOpts = { doExpect: true }
|
||||
): Promise<Response> {
|
||||
let body: { email?: string; tenantId?: string } = {}
|
||||
): Promise<[Response, SearchAccountsResponse]> {
|
||||
let body: SearchAccountsRequest = {}
|
||||
|
||||
if (search === 'email') {
|
||||
body.email = searchType;
|
||||
|
@ -132,6 +132,6 @@ export default class AccountAPI {
|
|||
if (opts.doExpect) {
|
||||
expect(response).toHaveStatusCode(200)
|
||||
}
|
||||
return response
|
||||
return [response, json]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,4 @@ export default class TestConfiguration<T> extends BudibaseTestConfiguration {
|
|||
const apiKeyResponse = await this.internalApi.self.getApiKey()
|
||||
this.state.apiKey = apiKeyResponse.apiKey
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,11 +12,32 @@ describe("Account API - Search for Account", () => {
|
|||
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")
|
||||
describe("POST /api/accounts/search", () => {
|
||||
describe("by tenant", () => {
|
||||
it("returns 200 + empty", async () => {
|
||||
const tenantId = generator.string()
|
||||
const [res, body] = await config.api.accounts.search(tenantId, "tenantId")
|
||||
expect(res.status).toBe(200)
|
||||
expect(body.length).toBe(0)
|
||||
})
|
||||
|
||||
it("returns 200 + found", async () => {
|
||||
const [res, body] = await config.api.accounts.search(config.state.tenantId!, "tenantId")
|
||||
expect(res.status).toBe(200)
|
||||
expect(body.length).toBe(1)
|
||||
expect(body[0].tenantId).toBe(config.state.tenantId)
|
||||
})
|
||||
})
|
||||
|
||||
describe("by email", () => {
|
||||
it("returns 200 + empty", async () => {
|
||||
await config.api.accounts.search(generator.word(), "email")
|
||||
})
|
||||
|
||||
it("returns 200 + found", async () => {
|
||||
await config.api.accounts.search(generator.word(), "email")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
|
@ -89,6 +89,8 @@ async function setup() {
|
|||
// @ts-ignore
|
||||
global.qa.tenantId = account.tenantId
|
||||
// @ts-ignore
|
||||
global.qa.email = account.email
|
||||
// @ts-ignore
|
||||
global.qa.accountId = newAccount.accountId
|
||||
await loginAsAccount(account)
|
||||
} else {
|
||||
|
|
|
@ -23,6 +23,8 @@ export default class BudibaseTestConfiguration {
|
|||
// @ts-ignore
|
||||
this.state.tenantId = global.qa.tenantId
|
||||
// @ts-ignore
|
||||
this.state.email = global.qa.email
|
||||
// @ts-ignore
|
||||
this.state.cookie = global.qa.authCookie
|
||||
}
|
||||
|
||||
|
@ -53,6 +55,7 @@ export default class BudibaseTestConfiguration {
|
|||
this.state.cookie = state.cookie
|
||||
this.state.tableId = state.tableId
|
||||
this.state.tenantId = state.tenantId
|
||||
this.state.email = state.email
|
||||
|
||||
await task()
|
||||
|
||||
|
@ -62,6 +65,7 @@ export default class BudibaseTestConfiguration {
|
|||
this.state.cookie = original.cookie
|
||||
this.state.tableId = original.tableId
|
||||
this.state.tenantId = original.tenantId
|
||||
this.state.email = original.email
|
||||
}
|
||||
|
||||
async login(email: string, password: string, tenantId?: string) {
|
||||
|
|
|
@ -4,4 +4,5 @@ export interface State {
|
|||
cookie?: string
|
||||
tableId?: string
|
||||
tenantId?: string
|
||||
email?: string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue