create app tests
This commit is contained in:
parent
69982abfc0
commit
3b08f9f8f1
|
@ -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`
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
Application,
|
Application,
|
||||||
} from "@budibase/server/api/controllers/public/mapping/types"
|
} from "@budibase/server/api/controllers/public/mapping/types"
|
||||||
|
import { App } from "@budibase/types"
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import InternalAPIClient from "./InternalAPIClient"
|
import InternalAPIClient from "./InternalAPIClient"
|
||||||
|
|
||||||
|
@ -17,9 +18,28 @@ export default class AppApi {
|
||||||
return [response, json]
|
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(
|
async create(
|
||||||
body: any
|
body: any
|
||||||
): Promise<[Response, Application]> {
|
): Promise<[Response, Partial<App>]> {
|
||||||
const response = await this.api.post(`/applications`, { body })
|
const response = await this.api.post(`/applications`, { body })
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json]
|
return [response, json]
|
||||||
|
|
|
@ -2,6 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||||
|
import generator from "../../../config/generator"
|
||||||
|
|
||||||
describe("Internal API - /applications endpoints", () => {
|
describe("Internal API - /applications endpoints", () => {
|
||||||
const api = new InternalAPIClient()
|
const api = new InternalAPIClient()
|
||||||
|
@ -37,4 +38,45 @@ describe("Internal API - /applications endpoints", () => {
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
expect(app._id).toBeDefined()
|
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"
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue