From 3b08f9f8f1c29645161386d578440a4a1caf83d5 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 30 Sep 2022 15:03:38 +0100 Subject: [PATCH] create app tests --- qa-core/README.md | 22 ++++++++++ .../TestConfiguration/applications.ts | 22 +++++++++- .../internal-api/applications/create.spec.ts | 42 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 qa-core/README.md diff --git a/qa-core/README.md b/qa-core/README.md new file mode 100644 index 0000000000..b812742ab3 --- /dev/null +++ b/qa-core/README.md @@ -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` \ No newline at end of file diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index afee5d707a..20e40fa3f2 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -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]> { const response = await this.api.post(`/applications`, { body }) const json = await response.json() return [response, json] diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index a11640153c..dedff13e8e 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -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" + }) + }) })