Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests/qa 22 improve qa core boilerplate #10539

Merged
merged 8 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,669 changes: 5,669 additions & 0 deletions qa-core/package-lock.json

Large diffs are not rendered by default.

76 changes: 28 additions & 48 deletions qa-core/src/internal-api/api/apis/AppAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,84 @@ import {
MessageResponse,
} from "../../../types"
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
import BaseAPI from "./BaseAPI"

export default class AppAPI {
client: BudibaseInternalAPIClient

export default class AppAPI extends BaseAPI {
constructor(client: BudibaseInternalAPIClient) {
this.client = client
super(client)
}

// TODO Fix the fetch apps to receive an optional number of apps and compare if the received app is more or less.
// each possible scenario should have its own method.
async fetchEmptyAppList(): Promise<[Response, App[]]> {
const [response, json] = await this.client.get(`/applications?status=all`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/applications?status=all`)
expect(json.length).toBeGreaterThanOrEqual(0)
return [response, json]
}

async fetchAllApplications(): Promise<[Response, App[]]> {
const [response, json] = await this.client.get(`/applications?status=all`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/applications?status=all`)
expect(json.length).toBeGreaterThanOrEqual(1)
return [response, json]
}

async canRender(): Promise<[Response, boolean]> {
const [response, json] = await this.client.get("/routing/client")
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get("/routing/client")
const publishedAppRenders = Object.keys(json.routes).length > 0
expect(publishedAppRenders).toBe(true)
return [response, publishedAppRenders]
}

async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
const [response, json] = await this.client.get(
`/applications/${appId}/appPackage`
)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/applications/${appId}/appPackage`)
expect(json.application.appId).toEqual(appId)
return [response, json]
}

async publish(appId: string | undefined): Promise<[Response, DeployConfig]> {
const [response, json] = await this.client.post(
`/applications/${appId}/publish`
)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/applications/${appId}/publish`)
return [response, json]
}

async create(body: any): Promise<App> {
const [response, json] = await this.client.post(`/applications`, { body })
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/applications`, body)
expect(json._id).toBeDefined()
return json
}

async read(id: string): Promise<[Response, App]> {
const [response, json] = await this.client.get(`/applications/${id}`)
const [response, json] = await this.get(`/applications/${id}`)
return [response, json.data]
}

async sync(appId: string): Promise<[Response, MessageResponse]> {
const [response, json] = await this.client.post(
`/applications/${appId}/sync`
)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/applications/${appId}/sync`)
return [response, json]
}

// TODO
async updateClient(appId: string, body: any): Promise<[Response, App]> {
const [response, json] = await this.client.put(
const [response, json] = await this.put(
`/applications/${appId}/client/update`,
{ body }
)
return [response, json]
}

async revertPublished(appId: string): Promise<[Response, MessageResponse]> {
const [response, json] = await this.client.post(`/dev/${appId}/revert`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/dev/${appId}/revert`)
expect(json).toEqual({
message: "Reverted changes successfully.",
})
return [response, json]
}

async revertUnpublished(appId: string): Promise<[Response, MessageResponse]> {
const [response, json] = await this.client.post(`/dev/${appId}/revert`)
expect(response).toHaveStatusCode(400)
const [response, json] = await this.post(
`/dev/${appId}/revert`,
undefined,
400
)
expect(json).toEqual({
message: "App has not yet been deployed",
status: 400,
Expand All @@ -105,8 +93,7 @@ export default class AppAPI {
}

async delete(appId: string): Promise<Response> {
const [response, _] = await this.client.del(`/applications/${appId}`)
expect(response).toHaveStatusCode(200)
const [response, _] = await this.del(`/applications/${appId}`)
return response
}

Expand All @@ -115,22 +102,18 @@ export default class AppAPI {
oldName: string,
body: any
): Promise<[Response, App]> {
const [response, json] = await this.client.put(`/applications/${appId}`, {
body,
})
expect(response).toHaveStatusCode(200)
const [response, json] = await this.put(`/applications/${appId}`, body)
expect(json.name).not.toEqual(oldName)
return [response, json]
}

async addScreentoApp(body: any): Promise<[Response, App]> {
const [response, json] = await this.client.post(`/screens`, { body })
const [response, json] = await this.post(`/screens`, body)
return [response, json]
}

async getRoutes(screenExists?: boolean): Promise<[Response, RouteConfig]> {
const [response, json] = await this.client.get(`/routing`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/routing`)
if (screenExists) {
expect(json.routes["/test"]).toBeTruthy()
} else {
Expand All @@ -141,16 +124,16 @@ export default class AppAPI {
}

async unpublish(appId: string): Promise<[Response]> {
const [response, json] = await this.client.post(
`/applications/${appId}/unpublish`
const [response, json] = await this.post(
`/applications/${appId}/unpublish`,
undefined,
204
)
expect(response).toHaveStatusCode(204)
return [response]
}

async unlock(appId: string): Promise<[Response, MessageResponse]> {
const [response, json] = await this.client.del(`/dev/${appId}/lock`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.del(`/dev/${appId}/lock`)
expect(json.message).toEqual("Lock released successfully.")
return [response, json]
}
Expand All @@ -162,10 +145,7 @@ export default class AppAPI {
color: "var(--spectrum-global-color-red-400)",
},
}
const [response, json] = await this.client.put(`/applications/${appId}`, {
body,
})
expect(response).toHaveStatusCode(200)
const [response, json] = await this.put(`/applications/${appId}`, body)
expect(json.icon.name).toEqual(body.icon.name)
expect(json.icon.color).toEqual(body.icon.color)
return [response, json]
Expand Down
56 changes: 56 additions & 0 deletions qa-core/src/internal-api/api/apis/BaseAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Response } from "node-fetch"
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"

export default class BaseAPI {
client: BudibaseInternalAPIClient

constructor(client: BudibaseInternalAPIClient) {
this.client = client
}

async get(url: string): Promise<[Response, any]> {
const [response, json] = await this.client.get(url)
expect(response).toHaveStatusCode(200)
return [response, json]
}

async post(
url: string,
body?: any,
statusCode?: number
): Promise<[Response, any]> {
const [response, json] = await this.client.post(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}

async put(
url: string,
body?: any,
statusCode?: number
): Promise<[Response, any]> {
const [response, json] = await this.client.put(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}

async patch(
url: string,
body?: any,
statusCode?: number
): Promise<[Response, any]> {
const [response, json] = await this.client.patch(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}

async del(
url: string,
statusCode?: number,
body?: any
): Promise<[Response, any]> {
const [response, json] = await this.client.del(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}
}
48 changes: 16 additions & 32 deletions qa-core/src/internal-api/api/apis/DatasourcesAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,75 @@ import {
UpdateDatasourceResponse,
} from "@budibase/types"
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
import BaseAPI from "./BaseAPI"

export default class DatasourcesAPI {
client: BudibaseInternalAPIClient

export default class DatasourcesAPI extends BaseAPI {
constructor(client: BudibaseInternalAPIClient) {
this.client = client
super(client)
}

async getIntegrations(): Promise<[Response, any]> {
const [response, json] = await this.client.get(`/integrations`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/integrations`)
const integrationsCount = Object.keys(json).length
expect(integrationsCount).toBe(16)
return [response, json]
}

async getAll(): Promise<[Response, Datasource[]]> {
const [response, json] = await this.client.get(`/datasources`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/datasources`)
expect(json.length).toBeGreaterThan(0)
return [response, json]
}

async getTable(dataSourceId: string): Promise<[Response, Datasource]> {
const [response, json] = await this.client.get(
`/datasources/${dataSourceId}`
)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/datasources/${dataSourceId}`)
expect(json._id).toEqual(dataSourceId)
return [response, json]
}

async add(body: any): Promise<[Response, CreateDatasourceResponse]> {
const [response, json] = await this.client.post(`/datasources`, { body })
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/datasources`, body)
expect(json.datasource._id).toBeDefined()
expect(json.datasource._rev).toBeDefined()

return [response, json]
}

async update(body: any): Promise<[Response, UpdateDatasourceResponse]> {
const [response, json] = await this.client.put(`/datasources/${body._id}`, {
body,
})
expect(response).toHaveStatusCode(200)
const [response, json] = await this.put(`/datasources/${body._id}`, body)
expect(json.datasource._id).toBeDefined()
expect(json.datasource._rev).toBeDefined()

return [response, json]
}

async previewQuery(body: any): Promise<[Response, any]> {
const [response, json] = await this.client.post(`/queries/preview`, {
body,
})
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/queries/preview`, body)
return [response, json]
}

async saveQuery(body: any): Promise<[Response, any]> {
const [response, json] = await this.client.post(`/queries`, {
body,
})
expect(response).toHaveStatusCode(200)
const [response, json] = await this.post(`/queries`, body)
return [response, json]
}

async getQuery(queryId: string): Promise<[Response, any]> {
const [response, json] = await this.client.get(`/queries/${queryId}`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/queries/${queryId}`)

return [response, json]
}

async getQueryPermissions(queryId: string): Promise<[Response, any]> {
const [response, json] = await this.client.get(`/permissions/${queryId}`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/permissions/${queryId}`)

return [response, json]
}

async delete(dataSourceId: string, revId: string): Promise<Response> {
const [response, json] = await this.client.del(
const [response, json] = await this.del(
`/datasources/${dataSourceId}/${revId}`
)
expect(response).toHaveStatusCode(200)

return response
}
}
10 changes: 4 additions & 6 deletions qa-core/src/internal-api/api/apis/IntegrationsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Response } from "node-fetch"
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
import BaseAPI from "./BaseAPI"

export default class IntegrationsAPI {
client: BudibaseInternalAPIClient

export default class IntegrationsAPI extends BaseAPI {
constructor(client: BudibaseInternalAPIClient) {
this.client = client
super(client)
}

async getAll(): Promise<[Response, any]> {
const [response, json] = await this.client.get(`/integrations`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/integrations`)
const integrationsCount = Object.keys(json).length
expect(integrationsCount).toBeGreaterThan(0)
return [response, json]
Expand Down
10 changes: 4 additions & 6 deletions qa-core/src/internal-api/api/apis/PermissionsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Response } from "node-fetch"
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
import BaseAPI from "./BaseAPI"

export default class PermissionsAPI {
client: BudibaseInternalAPIClient

export default class PermissionsAPI extends BaseAPI {
constructor(client: BudibaseInternalAPIClient) {
this.client = client
super(client)
}

async getAll(id: string): Promise<[Response, any]> {
const [response, json] = await this.client.get(`/permissions/${id}`)
expect(response).toHaveStatusCode(200)
const [response, json] = await this.get(`/permissions/${id}`)
return [response, json]
}
}
Loading