1
0
Fork 0
mirror of synced 2024-05-18 11:23:28 +12:00
budibase/qa-core/src/config/internal-api/TestConfiguration/applications.ts

164 lines
5.4 KiB
TypeScript
Raw Normal View History

2022-10-04 22:59:53 +13:00
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
2022-10-01 03:03:38 +13:00
import { App } from "@budibase/types"
2022-09-27 04:54:14 +13:00
import { Response } from "node-fetch"
import InternalAPIClient from "./InternalAPIClient"
2022-10-12 04:47:02 +13:00
import { RouteConfig } from "../fixtures/types/routing"
import { AppPackageResponse } from "../fixtures/types/appPackage"
import { DeployConfig } from "../fixtures/types/deploy"
2022-10-19 05:29:13 +13:00
import { responseMessage } from "../fixtures/types/responseMessage"
2022-10-29 04:48:29 +13:00
import { UnpublishAppResponse } from "../fixtures/types/unpublishAppResponse"
2022-10-19 05:29:13 +13:00
2022-09-27 04:54:14 +13:00
export default class AppApi {
api: InternalAPIClient
constructor(apiClient: InternalAPIClient) {
this.api = apiClient
}
2022-11-10 22:45:02 +13:00
async fetchEmptyAppList(): Promise<[Response, Application[]]> {
2022-09-29 06:21:05 +13:00
const response = await this.api.get(`/applications?status=all`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
2022-11-10 22:45:02 +13:00
expect(json.length).toEqual(0)
return [response, json]
}
async fetchAllApplications(): Promise<[Response, Application[]]> {
const response = await this.api.get(`/applications?status=all`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.length).toBeGreaterThanOrEqual(1)
2022-09-29 06:21:05 +13:00
return [response, json]
}
2022-10-01 03:35:13 +13:00
async canRender(): Promise<[Response, boolean]> {
const response = await this.api.get("/routing/client")
const json = await response.json()
2022-11-08 04:48:24 +13:00
const publishedAppRenders = Object.keys(json.routes).length > 0
expect(response).toHaveStatusCode(200)
expect(publishedAppRenders).toBe(true)
return [response, publishedAppRenders]
2022-10-01 03:03:38 +13:00
}
2022-10-12 04:47:02 +13:00
async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
2022-10-01 03:03:38 +13:00
const response = await this.api.get(`/applications/${appId}/appPackage`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
2022-11-10 05:05:15 +13:00
expect(json.application.appId).toEqual(appId)
2022-10-01 03:03:38 +13:00
return [response, json]
}
2022-11-08 04:48:24 +13:00
async publish(appUrl: string): Promise<[Response, DeployConfig]> {
2022-10-01 03:03:38 +13:00
const response = await this.api.post("/deploy")
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
expect(json).toEqual({
_id: expect.any(String),
appUrl: appUrl,
status: "SUCCESS",
})
2022-10-01 03:03:38 +13:00
return [response, json]
}
2022-10-14 02:58:23 +13:00
async create(body: any): Promise<Partial<App>> {
2022-10-01 14:54:51 +13:00
const response = await this.api.post(`/applications`, { body })
2022-09-27 04:54:14 +13:00
const json = await response.json()
2022-10-14 02:58:23 +13:00
expect(response).toHaveStatusCode(200)
expect(json._id).toBeDefined()
return json
2022-09-27 04:54:14 +13:00
}
async read(id: string): Promise<[Response, Application]> {
const response = await this.api.get(`/applications/${id}`)
const json = await response.json()
return [response, json.data]
}
2022-10-05 04:11:19 +13:00
2022-10-19 05:29:13 +13:00
async sync(appId: string): Promise<[Response, responseMessage]> {
2022-10-05 04:11:19 +13:00
const response = await this.api.post(`/applications/${appId}/sync`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
2022-10-05 04:11:19 +13:00
return [response, json]
}
2022-11-10 22:45:02 +13:00
// TODO
2022-10-12 22:25:02 +13:00
async updateClient(
appId: string,
body: any
): Promise<[Response, Application]> {
const response = await this.api.put(
`/applications/${appId}/client/update`,
{ body }
)
2022-10-05 05:12:38 +13:00
const json = await response.json()
return [response, json]
}
2022-11-10 22:45:02 +13:00
async revertPublished(appId: string): Promise<[Response, responseMessage]> {
const response = await this.api.post(`/dev/${appId}/revert`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json).toEqual({
message: "Reverted changes successfully.",
})
return [response, json]
}
async revertUnpublished(appId: string): Promise<[Response, responseMessage]> {
const response = await this.api.post(`/dev/${appId}/revert`)
2022-10-05 05:12:38 +13:00
const json = await response.json()
2022-11-10 22:45:02 +13:00
expect(response).toHaveStatusCode(400)
expect(json).toEqual({
message: "App has not yet been deployed",
status: 400,
})
2022-10-05 05:12:38 +13:00
return [response, json]
}
2022-11-10 22:45:02 +13:00
2022-10-05 05:12:38 +13:00
async delete(appId: string): Promise<[Response, any]> {
const response = await this.api.del(`/applications/${appId}`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
2022-10-05 05:12:38 +13:00
return [response, json]
}
2022-11-08 04:48:24 +13:00
async update(appId: string, oldName: string, body: any): Promise<[Response, Application]> {
2022-10-08 00:19:00 +13:00
const response = await this.api.put(`/applications/${appId}`, { body })
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
expect(json.name).not.toEqual(oldName)
2022-10-08 00:19:00 +13:00
return [response, json]
}
async addScreentoApp(body: any): Promise<[Response, Application]> {
2022-10-08 06:05:58 +13:00
const response = await this.api.post(`/screens`, { body })
const json = await response.json()
return [response, json]
}
2022-11-08 04:48:24 +13:00
async getRoutes(screenExists?: boolean): Promise<[Response, RouteConfig]> {
2022-10-08 06:05:58 +13:00
const response = await this.api.get(`/routing`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
if (screenExists) {
expect(json.routes["/test"]).toBeTruthy()
} else {
expect(json.routes["/test"]).toBeUndefined()
}
2022-10-08 06:05:58 +13:00
return [response, json]
}
2022-10-29 04:48:29 +13:00
async unpublish(appId: string): Promise<[Response, UnpublishAppResponse]> {
const response = await this.api.del(`/applications/${appId}?unpublish=1`)
expect(response).toHaveStatusCode(200)
const json = await response.json()
expect(json.data.ok).toBe(true)
expect(json.ok).toBe(true)
expect(json.status).toBe(200)
return [response, json]
}
2022-09-27 04:54:14 +13:00
}