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