create app tests

This commit is contained in:
Martin McKeaveney 2022-09-30 15:03:38 +01:00
parent 69982abfc0
commit 3b08f9f8f1
3 changed files with 85 additions and 1 deletions

22
qa-core/README.md Normal file
View File

@ -0,0 +1,22 @@
# QA Core API Tests
The QA Core API tests are a jest suite that run directly against the budibase backend APIs.
## Auto Setup
You can run the whole test suite with one command, that spins up the budibase server and runs the jest tests:
`yarn api:test`
## Setup Server Only
You can also just stand up the budibase server alone.
`yarn api:server:setup`
## Run Tests
If you configured the server using the previous command, you can run the whole test suite by using:
`yarn test`
for watch mode, where the tests will run on every change:
`yarn test:watch`

View File

@ -1,6 +1,7 @@
import {
Application,
} from "@budibase/server/api/controllers/public/mapping/types"
import { App } from "@budibase/types"
import { Response } from "node-fetch"
import InternalAPIClient from "./InternalAPIClient"
@ -17,9 +18,28 @@ export default class AppApi {
return [response, json]
}
async canRender(appId: string): Promise<[Response, string]> {
const response = await this.api.get(`/${appId}`, {})
const html = await response.text()
return [response, html]
}
async getAppPackage(appId: string): Promise<[Response, any]> {
const response = await this.api.get(`/applications/${appId}/appPackage`)
const json = await response.json()
return [response, json]
}
// TODO: 500 Error: Missing/invalid DB name when called
async publish(): Promise<[Response, string]> {
const response = await this.api.post("/deploy")
const json = await response.json()
return [response, json]
}
async create(
body: any
): Promise<[Response, Application]> {
): Promise<[Response, Partial<App>]> {
const response = await this.api.post(`/applications`, { body })
const json = await response.json()
return [response, json]

View File

@ -2,6 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import generateApp from "../../../config/internal-api/fixtures/applications"
import generator from "../../../config/generator"
describe("Internal API - /applications endpoints", () => {
const api = new InternalAPIClient()
@ -37,4 +38,45 @@ describe("Internal API - /applications endpoints", () => {
expect(response).toHaveStatusCode(200)
expect(app._id).toBeDefined()
})
it("POST - Create an application from a template", async () => {
const appName = generator.word()
const [response, app] = await config.applications.create({
name: appName,
url: `/${generator.word()}`,
useTemplate: true,
templateName: "Car Rental Admin Panel",
templateKey: "app/car-rental-admin-panel",
templateFile: undefined
})
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
const [_, appPackage] = await config.applications.getAppPackage(app.appId as string)
expect(appPackage.application.appId).toBe(app.appId)
expect(appPackage.application.name).toBe(appName)
})
it("POST - Publish app from template", async () => {
const appUrl = `/${generator.word()}`
const [response, app] = await config.applications.create({
name: generator.word(),
url: appUrl,
useTemplate: true,
templateName: "Car Rental Admin Panel",
templateKey: "app/car-rental-admin-panel",
templateFile: undefined
})
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
config.applications.api.appId = app.appId
const [publishResponse, json] = await config.applications.publish()
expect(publishResponse).toHaveStatusCode(200)
expect(json).toEqual({
_id: expect.any(String),
appUrl,
status: "SUCCESS"
})
})
})