diff --git a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts index ce33a623b2..2dc0487095 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts @@ -49,12 +49,17 @@ class InternalAPIClient { // @ts-ignore const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions) - if (response.status == 404 || response.status == 500) { + if ( + response.status == 404 || + response.status == 500 || + response.status == 403 + ) { console.error("Error in apiCall") console.error("Response:") console.error(response) + const json = await response.json() console.error("Response body:") - console.error(response.body) + console.error(json) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index 0cff3eb840..d9f4aa4816 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -59,8 +59,16 @@ class PublicAPIClient { // @ts-ignore const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions) - if (response.status !== 200) { + if ( + response.status == 404 || + response.status == 500 || + response.status == 403 + ) { + console.error("Error in apiCall") + console.error("Response:") console.error(response) + console.error("Response body:") + console.error(response.body) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/auth.ts b/qa-core/src/config/public-api/TestConfiguration/auth.ts index ceb10b8bfc..3eb4df2245 100644 --- a/qa-core/src/config/public-api/TestConfiguration/auth.ts +++ b/qa-core/src/config/public-api/TestConfiguration/auth.ts @@ -22,9 +22,9 @@ export default class AuthApi { } async login(email: String, password: String): Promise<[Response, any]> { - const response = await this.api.post(`/auth/login`, { + const response = await this.api.post(`/global/auth/default/login`, { body: { - email: email, + username: email, password: password, }, }) diff --git a/qa-core/src/config/public-api/TestConfiguration/index.ts b/qa-core/src/config/public-api/TestConfiguration/index.ts index fc2d2fd572..a869448b36 100644 --- a/qa-core/src/config/public-api/TestConfiguration/index.ts +++ b/qa-core/src/config/public-api/TestConfiguration/index.ts @@ -7,6 +7,9 @@ import AuthApi from "./auth" import AccountsApiClient from "./accountsAPIClient" import AccountsApi from "./accounts" import { generateAccount } from "../fixtures/accounts" +import internalApplicationsApi from "../../internal-api/TestConfiguration/applications" + +import InternalAPIClient from "../../internal-api/TestConfiguration/InternalAPIClient" export default class TestConfiguration { applications: ApplicationApi @@ -18,20 +21,28 @@ export default class TestConfiguration { accounts: AccountsApi apiClient: PublicAPIClient accountsApiClient: AccountsApiClient + internalApiClient: InternalAPIClient + internalApplicationsApi: internalApplicationsApi constructor( apiClient: PublicAPIClient, - accountsApiClient: AccountsApiClient + accountsApiClient: AccountsApiClient, + internalApiClient: InternalAPIClient ) { this.apiClient = apiClient this.accountsApiClient = accountsApiClient + this.internalApiClient = internalApiClient - this.auth = new AuthApi(this.accountsApiClient) + this.auth = new AuthApi(this.internalApiClient) this.accounts = new AccountsApi(this.accountsApiClient) this.applications = new ApplicationApi(apiClient) this.users = new UserApi(apiClient) this.tables = new TableApi(apiClient) this.rows = new RowApi(apiClient) + this.internalApplicationsApi = new internalApplicationsApi( + internalApiClient + ) + this.context = {} } @@ -43,7 +54,13 @@ export default class TestConfiguration { await this.accounts.create(account) await this.updateApiClients(account.tenantName) await this.auth.login(account.email, account.password) - await this.applications.createFirstApp() + const body = { + name: "My first app", + url: "my-first-app", + useTemplate: false, + sampleData: true, + } + await this.internalApplicationsApi.create(body) } async setApiKey() { @@ -54,7 +71,11 @@ export default class TestConfiguration { this.apiClient.setTenantName(tenantName) this.applications = new ApplicationApi(this.apiClient) this.rows = new RowApi(this.apiClient) - + this.internalApiClient.setTenantName(tenantName) + this.internalApplicationsApi = new internalApplicationsApi( + this.internalApiClient + ) + this.auth = new AuthApi(this.internalApiClient) this.context = {} } diff --git a/qa-core/src/tests/public-api/applications/applications.spec.ts b/qa-core/src/tests/public-api/applications/applications.spec.ts index e651194452..a5c0ed3691 100644 --- a/qa-core/src/tests/public-api/applications/applications.spec.ts +++ b/qa-core/src/tests/public-api/applications/applications.spec.ts @@ -4,14 +4,22 @@ import AccountsAPIClient from "../../../config/public-api/TestConfiguration/acco import generateApp from "../../../config/public-api/fixtures/applications" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { db as dbCore } from "@budibase/backend-core" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -describe.skip("Public API - /applications endpoints", () => { +describe("Public API - /applications endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration( + api, + accountsAPI, + internalAPI + ) beforeAll(async () => { - await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() + const [response, app] = await config.applications.seed() config.context = app }) diff --git a/qa-core/src/tests/public-api/tables/rows.spec.ts b/qa-core/src/tests/public-api/tables/rows.spec.ts index 3cb339570d..d21b61e41a 100644 --- a/qa-core/src/tests/public-api/tables/rows.spec.ts +++ b/qa-core/src/tests/public-api/tables/rows.spec.ts @@ -3,14 +3,18 @@ import { generateRow } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -describe.skip("Public API - /rows endpoints", () => { +describe("Public API - /rows endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration(api, accountsAPI, internalAPI) beforeAll(async () => { - await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() + const [aResp, app] = await config.applications.seed() config.tables.api.appId = app._id diff --git a/qa-core/src/tests/public-api/tables/tables.spec.ts b/qa-core/src/tests/public-api/tables/tables.spec.ts index 5d96194599..fc506d7bb6 100644 --- a/qa-core/src/tests/public-api/tables/tables.spec.ts +++ b/qa-core/src/tests/public-api/tables/tables.spec.ts @@ -3,14 +3,18 @@ import { generateTable } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -describe.skip("Public API - /tables endpoints", () => { +describe("Public API - /tables endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration
(api, accountsAPI, internalAPI) beforeAll(async () => { - await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() + const [appResp, app] = await config.applications.seed() config.tables.api.appId = app._id diff --git a/qa-core/src/tests/public-api/users/users.spec.ts b/qa-core/src/tests/public-api/users/users.spec.ts index d72b265386..597a8ff2dd 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -3,11 +3,13 @@ import PublicAPIClient from "../../../config/public-api/TestConfiguration/Public import generateUser from "../../../config/public-api/fixtures/users" import { User } from "@budibase/server/api/controllers/public/mapping/types" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" describe("Public API - /users endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration(api, accountsAPI, internalAPI) beforeAll(async () => { await config.setupAccountAndTenant()