2022-09-27 04:54:14 +13:00
|
|
|
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
|
|
|
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
2022-10-01 14:54:51 +13:00
|
|
|
import { db } from "@budibase/backend-core"
|
2022-09-27 04:54:14 +13:00
|
|
|
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
2022-09-29 06:21:05 +13:00
|
|
|
import generateApp from "../../../config/internal-api/fixtures/applications"
|
2022-10-01 03:03:38 +13:00
|
|
|
import generator from "../../../config/generator"
|
2022-10-08 06:05:58 +13:00
|
|
|
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
2022-09-27 04:54:14 +13:00
|
|
|
|
|
|
|
describe("Internal API - /applications endpoints", () => {
|
|
|
|
const api = new InternalAPIClient()
|
|
|
|
const config = new TestConfiguration<Application>(api)
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await config.beforeAll()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await config.afterAll()
|
|
|
|
})
|
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
async function createAppFromTemplate() {
|
|
|
|
return config.applications.create({
|
|
|
|
name: generator.word(),
|
|
|
|
url: `/${generator.word()}`,
|
|
|
|
useTemplate: "true",
|
|
|
|
templateName: "Near Miss Register",
|
|
|
|
templateKey: "app/near-miss-register",
|
2022-10-04 22:59:53 +13:00
|
|
|
templateFile: undefined,
|
2022-10-01 14:54:51 +13:00
|
|
|
})
|
|
|
|
}
|
2022-09-27 04:54:14 +13:00
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
it("GET - fetch applications", async () => {
|
2022-09-29 06:21:05 +13:00
|
|
|
await config.applications.create({
|
|
|
|
...generateApp(),
|
2022-10-04 22:59:53 +13:00
|
|
|
useTemplate: false,
|
2022-09-29 06:21:05 +13:00
|
|
|
})
|
|
|
|
const [response, apps] = await config.applications.fetch()
|
|
|
|
expect(response).toHaveStatusCode(200)
|
2022-10-01 03:35:13 +13:00
|
|
|
expect(apps.length).toBeGreaterThanOrEqual(1)
|
2022-09-29 06:21:05 +13:00
|
|
|
})
|
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
it("POST - Create an application", async () => {
|
2022-09-29 21:33:48 +13:00
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
2022-09-27 04:54:14 +13:00
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app._id).toBeDefined()
|
|
|
|
})
|
2022-10-01 03:03:38 +13:00
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
it("POST - Publish application", async () => {
|
|
|
|
// create app
|
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
2022-10-01 03:03:38 +13:00
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
2022-10-01 03:35:13 +13:00
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
// publish app
|
2022-10-01 03:35:13 +13:00
|
|
|
config.applications.api.appId = app.appId
|
2022-10-01 14:54:51 +13:00
|
|
|
const [publishResponse, publish] = await config.applications.publish()
|
|
|
|
expect(publishResponse).toHaveStatusCode(200)
|
|
|
|
expect(publish).toEqual({
|
|
|
|
_id: expect.any(String),
|
|
|
|
appUrl: app.url,
|
2022-10-04 22:59:53 +13:00
|
|
|
status: "SUCCESS",
|
2022-10-01 14:54:51 +13:00
|
|
|
})
|
2022-10-01 03:03:38 +13:00
|
|
|
})
|
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
it("POST - Create an application from a template, publish and check it renders", async () => {
|
|
|
|
// create the app
|
|
|
|
const appName = generator.word()
|
2022-10-01 14:56:08 +13:00
|
|
|
const [response, app] = await createAppFromTemplate()
|
2022-10-01 03:03:38 +13:00
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
2022-10-01 14:54:51 +13:00
|
|
|
// check preview renders
|
2022-10-04 22:59:53 +13:00
|
|
|
const [previewResponse, previewRenders] =
|
|
|
|
await config.applications.canRender()
|
2022-10-01 14:54:51 +13:00
|
|
|
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)
|
2022-10-04 22:59:53 +13:00
|
|
|
const [publishedAppResponse, publishedAppRenders] =
|
|
|
|
await config.applications.canRender()
|
2022-10-01 14:54:51 +13:00
|
|
|
expect(publishedAppRenders).toBe(true)
|
2022-10-01 03:03:38 +13:00
|
|
|
})
|
2022-10-08 00:19:00 +13:00
|
|
|
|
|
|
|
it("POST - Sync application before deployment", async () => {
|
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
const [syncResponse, sync] = await config.applications.sync(app.appId ? app.appId : "")
|
|
|
|
expect(syncResponse).toHaveStatusCode(200)
|
|
|
|
expect(sync).toEqual({
|
|
|
|
message: "App sync not required, app not deployed."
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("POST - Sync application after deployment", async () => {
|
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
// publish app
|
|
|
|
await config.applications.publish()
|
|
|
|
|
|
|
|
const [syncResponse, sync] = await config.applications.sync(app.appId ? app.appId : "")
|
|
|
|
expect(syncResponse).toHaveStatusCode(200)
|
|
|
|
expect(sync).toEqual({
|
|
|
|
message: "App sync completed successfully."
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("PUT - Update an application", async () => {
|
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
2022-10-08 06:05:58 +13:00
|
|
|
config.applications.api.appId = app.appId
|
2022-10-08 00:19:00 +13:00
|
|
|
|
2022-10-08 06:05:58 +13:00
|
|
|
const [updateResponse, updatedApp] = await config.applications.update(app.appId ? app.appId : "", {
|
|
|
|
name: generator.word(),
|
|
|
|
})
|
|
|
|
expect(updateResponse).toHaveStatusCode(200)
|
|
|
|
expect(updatedApp.name).not.toEqual(app.name)
|
2022-10-08 00:19:00 +13:00
|
|
|
})
|
|
|
|
|
2022-10-08 06:05:58 +13:00
|
|
|
// Skip this test because of the if line 44 in InternalAPIClient.ts
|
|
|
|
it.skip("POST - Revert Changes without changes", async () => {
|
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
|
|
|
config.applications.api.appId = app.appId
|
2022-10-08 00:19:00 +13:00
|
|
|
|
2022-10-08 06:05:58 +13:00
|
|
|
const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "")
|
|
|
|
expect(revertResponse).toHaveStatusCode(400)
|
|
|
|
expect(revert).toEqual({
|
|
|
|
message: "There is no version to revert to",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("POST - Revert Changes", async () => {
|
2022-10-08 00:19:00 +13:00
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
2022-10-08 06:05:58 +13:00
|
|
|
config.applications.api.appId = app.appId
|
2022-10-08 00:19:00 +13:00
|
|
|
|
|
|
|
// publish app
|
2022-10-08 06:05:58 +13:00
|
|
|
const [publishResponse, publish] = await config.applications.publish()
|
|
|
|
expect(publishResponse).toHaveStatusCode(200)
|
|
|
|
expect(publish.status).toEqual("SUCCESS")
|
|
|
|
|
|
|
|
// Change/add component to the app
|
|
|
|
const [screenResponse, screen] = await config.applications.addScreentoApp(generateScreen())
|
|
|
|
expect(screenResponse).toHaveStatusCode(200)
|
|
|
|
expect(screen._id).toBeDefined()
|
2022-10-08 00:19:00 +13:00
|
|
|
|
2022-10-10 07:31:35 +13:00
|
|
|
// // Revert the app to published state
|
|
|
|
const [revertResponse, revert] = await config.applications.revert(app.appId as string)
|
2022-10-08 00:19:00 +13:00
|
|
|
expect(revertResponse).toHaveStatusCode(200)
|
|
|
|
expect(revert).toEqual({
|
2022-10-10 07:31:35 +13:00
|
|
|
message: "Reverted changes successfully."
|
2022-10-08 00:19:00 +13:00
|
|
|
})
|
2022-10-08 06:05:58 +13:00
|
|
|
|
|
|
|
// Check screen is removed
|
|
|
|
const [routesResponse, routes] = await config.applications.getRoutes()
|
|
|
|
expect(routesResponse).toHaveStatusCode(200)
|
|
|
|
expect(routes.routes["/test"]).toBeUndefined()
|
|
|
|
|
2022-10-08 00:19:00 +13:00
|
|
|
})
|
|
|
|
|
|
|
|
it("DELETE - Delete an application", async () => {
|
|
|
|
const [response, app] = await config.applications.create(generateApp())
|
|
|
|
expect(response).toHaveStatusCode(200)
|
|
|
|
expect(app.appId).toBeDefined()
|
|
|
|
|
|
|
|
const [deleteResponse] = await config.applications.delete(app.appId ? app.appId : "")
|
|
|
|
expect(deleteResponse).toHaveStatusCode(200)
|
|
|
|
})
|
2022-09-27 04:54:14 +13:00
|
|
|
})
|