QA Core tests for app creation
This commit is contained in:
parent
d5455bdc50
commit
65c70cca4c
|
@ -25,7 +25,8 @@
|
|||
"moduleNameMapper": {
|
||||
"@budibase/types": "<rootDir>/../packages/types/src",
|
||||
"@budibase/server": "<rootDir>/../packages/server/src",
|
||||
"@budibase/backend-core": "<rootDir>/../packages/backend-core/src"
|
||||
"@budibase/backend-core": "<rootDir>/../packages/backend-core/src",
|
||||
"@budibase/backend-core/(.*)": "<rootDir>/../packages/backend-core/$1"
|
||||
},
|
||||
"setupFiles": [
|
||||
"./scripts/jestSetup.js"
|
||||
|
@ -54,4 +55,4 @@
|
|||
"form-data": "^4.0.0",
|
||||
"node-fetch": "2"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,3 +15,5 @@ tk.freeze(MOCK_DATE)
|
|||
if (!process.env.DEBUG) {
|
||||
global.console.log = jest.fn() // console.log are ignored in tests
|
||||
}
|
||||
|
||||
jest.setTimeout(10000)
|
||||
|
|
|
@ -29,7 +29,7 @@ class InternalAPIClient {
|
|||
async (url = "", options: ApiOptions = {}) => {
|
||||
const requestOptions = {
|
||||
method,
|
||||
body: options.body,
|
||||
body: JSON.stringify(options.body),
|
||||
headers: {
|
||||
"x-budibase-app-id": this.appId,
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
@ -40,14 +40,7 @@ export default class AppApi {
|
|||
async create(
|
||||
body: any
|
||||
): Promise<[Response, Partial<App>]> {
|
||||
const data = new FormData()
|
||||
data.append("name", body.name)
|
||||
data.append("url", body.url)
|
||||
data.append("useTemplate", true)
|
||||
data.append("templateName", body.templateName)
|
||||
data.append("templateKey", body.templateKey)
|
||||
|
||||
const response = await this.api.post(`/applications`, { body: data })
|
||||
const response = await this.api.post(`/applications`, { body })
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
|
|
|
@ -13,9 +13,12 @@ export default class TestConfiguration<T> {
|
|||
this.context = <T>{}
|
||||
}
|
||||
|
||||
async beforeAll() {}
|
||||
async beforeAll() {
|
||||
await this.auth.login()
|
||||
}
|
||||
|
||||
async afterAll() {
|
||||
this.context = <T>{}
|
||||
await this.auth.logout()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
declare module "@budibase/backend-core/tenancy"
|
||||
declare module "@budibase/backend-core/db"
|
||||
declare module "@budibase/backend-core/context"
|
||||
declare module "@budibase/backend-core/cache"
|
||||
declare module "@budibase/backend-core/permissions"
|
||||
declare module "@budibase/backend-core/roles"
|
||||
declare module "@budibase/backend-core/constants"
|
||||
declare module "@budibase/backend-core/auth"
|
||||
declare module "@budibase/backend-core/sessions"
|
||||
declare module "@budibase/backend-core/encryption"
|
||||
declare module "@budibase/backend-core/utils"
|
||||
declare module "@budibase/backend-core/redis"
|
||||
declare module "@budibase/backend-core/objectStore"
|
||||
declare module "@budibase/backend-core/plugins"
|
|
@ -1,5 +1,6 @@
|
|||
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import { db } from "@budibase/backend-core"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||
import generator from "../../../config/generator"
|
||||
|
@ -10,20 +11,24 @@ describe("Internal API - /applications endpoints", () => {
|
|||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.auth.login()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await config.afterAll()
|
||||
await config.auth.logout()
|
||||
})
|
||||
|
||||
xit("POST - Can login", async () => {
|
||||
const [response] = await config.auth.login()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
})
|
||||
async function createAppFromTemplate() {
|
||||
return config.applications.create({
|
||||
name: generator.word(),
|
||||
url: `/${generator.word()}`,
|
||||
useTemplate: "true",
|
||||
templateName: "Near Miss Register",
|
||||
templateKey: "app/near-miss-register",
|
||||
templateFile: undefined
|
||||
})
|
||||
}
|
||||
|
||||
xit("GET - fetch applications", async () => {
|
||||
it("GET - fetch applications", async () => {
|
||||
await config.applications.create({
|
||||
...generateApp(),
|
||||
useTemplate: false
|
||||
|
@ -33,51 +38,49 @@ describe("Internal API - /applications endpoints", () => {
|
|||
expect(apps.length).toBeGreaterThanOrEqual(1)
|
||||
})
|
||||
|
||||
xit("POST - Create an application", async () => {
|
||||
it("POST - Create an application", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app._id).toBeDefined()
|
||||
})
|
||||
|
||||
it("POST - Create an application from a template and check it renders", 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
|
||||
})
|
||||
it("POST - Publish application", async () => {
|
||||
// create app
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
|
||||
// publish app
|
||||
config.applications.api.appId = app.appId
|
||||
const [_, renderable] = await config.applications.canRender()
|
||||
expect(renderable).toBe(true)
|
||||
})
|
||||
|
||||
xit("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()
|
||||
const [publishResponse, publish] = await config.applications.publish()
|
||||
expect(publishResponse).toHaveStatusCode(200)
|
||||
expect(json).toEqual({
|
||||
expect(publish).toEqual({
|
||||
_id: expect.any(String),
|
||||
appUrl,
|
||||
appUrl: app.url,
|
||||
status: "SUCCESS"
|
||||
})
|
||||
})
|
||||
|
||||
it("POST - Create an application from a template, publish and check it renders", async () => {
|
||||
// create the app
|
||||
const appName = generator.word()
|
||||
const [response, app] = await createAppFromTemplate({ name: appName })
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// check preview renders
|
||||
const [previewResponse, previewRenders] = await config.applications.canRender()
|
||||
expect(previewResponse).toHaveStatusCode(200)
|
||||
expect(previewRenders).toBe(true)
|
||||
|
||||
// publish app
|
||||
await config.applications.publish()
|
||||
|
||||
// check published app renders
|
||||
config.applications.api.appId = db.getProdAppID(app.appId)
|
||||
const [publishedAppResponse, publishedAppRenders] = await config.applications.canRender()
|
||||
expect(publishedAppRenders).toBe(true)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"@budibase/types": ["../packages/types/src"],
|
||||
"@budibase/backend-core": ["../packages/backend-core"],
|
||||
"@budibase/backend-core": ["../packages/backend-core/src"],
|
||||
"@budibase/backend-core/*": ["../packages/backend-core/*"],
|
||||
"@budibase/server/*": ["../packages/server/src/*"],
|
||||
}
|
||||
},
|
||||
|
@ -23,6 +24,7 @@
|
|||
},
|
||||
"references": [
|
||||
{ "path": "../packages/types" },
|
||||
{ "path": "../packages/backend-core" },
|
||||
],
|
||||
"include": [
|
||||
"src/**/*",
|
||||
|
|
Loading…
Reference in New Issue