2020-02-03 10:24:25 +01:00
|
|
|
const testAppDef = require("../appPackages/testApp/appDefinition.json")
|
|
|
|
const testAccessLevels = require("../appPackages/testApp/access_levels.json")
|
|
|
|
const testPages = require("../appPackages/testApp/pages.json")
|
|
|
|
const testComponents = require("../appPackages/testApp/customComponents/components.json")
|
|
|
|
const testMoreComponents = require("../appPackages/testApp/moreCustomComponents/components.json")
|
|
|
|
const statusCodes = require("../utilities/statusCodes")
|
|
|
|
const screen1 = require("../appPackages/testApp/components/myTextBox.json")
|
|
|
|
const screen2 = require("../appPackages/testApp/components/subfolder/otherTextBox.json")
|
|
|
|
const { readJSON, pathExists, unlink } = require("fs-extra")
|
|
|
|
|
|
|
|
const app = require("./testApp")()
|
|
|
|
testComponents.textbox.name = `./customComponents/textbox`
|
|
|
|
testMoreComponents.textbox.name = `./moreCustomComponents/textbox`
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2019-07-27 08:31:31 +02:00
|
|
|
beforeAll(async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const testComponent = "./appPackages/testApp/components/newTextBox.json"
|
|
|
|
const testComponentAfterMove =
|
|
|
|
"./appPackages/testApp/components/anotherSubFolder/newTextBox.json"
|
2019-07-27 08:31:31 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
if (await pathExists(testComponent)) await unlink(testComponent)
|
|
|
|
if (await pathExists(testComponentAfterMove))
|
|
|
|
await unlink(testComponentAfterMove)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
await app.start()
|
|
|
|
})
|
|
|
|
afterAll(async () => await app.destroy())
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
it("/apppackage should get appDefinition", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.appDefinition).toEqual(testAppDef)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
it("/apppackage should get access levels", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.accessLevels).toEqual(testAccessLevels)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
it("/apppackage should get pages", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
|
|
|
expect(body.pages).toEqual(testPages)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
it("/apppackage should get components", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.components["./customComponents/textbox"]).toBeDefined()
|
|
|
|
expect(body.components["./moreCustomComponents/textbox"]).toBeDefined()
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.components["./customComponents/textbox"]).toEqual(
|
|
|
|
testComponents.textbox
|
|
|
|
)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.components["./moreCustomComponents/textbox"]).toEqual(
|
|
|
|
testMoreComponents.textbox
|
|
|
|
)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
it("/apppackage should get screens", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const expectedComponents = {
|
|
|
|
myTextBox: { ...screen1, name: "myTextBox" },
|
|
|
|
"subfolder/otherTextBox": { ...screen2, name: "subfolder/otherTextBox" },
|
|
|
|
}
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.screens).toEqual(expectedComponents)
|
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
|
|
|
it("should be able to create new derived component", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const newscreen = {
|
|
|
|
name: "newTextBox",
|
|
|
|
inherits: "./customComponents/textbox",
|
|
|
|
props: {
|
|
|
|
label: "something",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
await app
|
|
|
|
.post("/_builder/api/testApp/screen", newscreen)
|
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
|
|
|
const componentFile = "./appPackages/testApp/components/newTextBox.json"
|
|
|
|
expect(await pathExists(componentFile)).toBe(true)
|
|
|
|
expect(await readJSON(componentFile)).toEqual(newscreen)
|
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
|
|
|
it("should be able to update derived component", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const updatedscreen = {
|
|
|
|
name: "newTextBox",
|
|
|
|
inherits: "./customComponents/textbox",
|
|
|
|
props: {
|
|
|
|
label: "something else",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
await app
|
|
|
|
.post("/_builder/api/testApp/screen", updatedscreen)
|
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
|
|
|
const componentFile = "./appPackages/testApp/components/newTextBox.json"
|
|
|
|
expect(await readJSON(componentFile)).toEqual(updatedscreen)
|
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
|
|
|
it("should be able to rename derived component", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
await app
|
|
|
|
.patch("/_builder/api/testApp/screen", {
|
|
|
|
oldname: "newTextBox",
|
|
|
|
newname: "anotherSubFolder/newTextBox",
|
|
|
|
})
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const oldcomponentFile = "./appPackages/testApp/components/newTextBox.json"
|
|
|
|
const newcomponentFile =
|
|
|
|
"./appPackages/testApp/components/anotherSubFolder/newTextBox.json"
|
|
|
|
expect(await pathExists(oldcomponentFile)).toBe(false)
|
|
|
|
expect(await pathExists(newcomponentFile)).toBe(true)
|
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
|
|
|
it("should be able to delete derived component", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
await app
|
|
|
|
.delete("/_builder/api/testApp/screen/anotherSubFolder/newTextBox")
|
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
|
|
|
const componentFile =
|
|
|
|
"./appPackages/testApp/components/anotherSubFolder/newTextBox.json"
|
|
|
|
const componentDir = "./appPackages/testApp/components/anotherSubFolder"
|
|
|
|
expect(await pathExists(componentFile)).toBe(false)
|
|
|
|
expect(await pathExists(componentDir)).toBe(false)
|
|
|
|
})
|
2019-09-09 06:24:14 +02:00
|
|
|
|
|
|
|
it("/savePackage should prepare all necessary client files", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
await app
|
|
|
|
.post("/_builder/api/testApp/appPackage", {
|
|
|
|
appDefinition: testAppDef,
|
|
|
|
accessLevels: testAccessLevels,
|
|
|
|
pages: testPages,
|
2019-09-09 06:24:14 +02:00
|
|
|
})
|
2020-02-03 10:24:25 +01:00
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
|
|
|
const publicFolderMain = relative =>
|
|
|
|
"./appPackages/testApp/public/main" + relative
|
|
|
|
const publicFolderUnauth = relative =>
|
|
|
|
"./appPackages/testApp/public/unauthenticated" + relative
|
|
|
|
|
|
|
|
expect(await pathExists(publicFolderMain("/index.html"))).toBe(true)
|
|
|
|
expect(await pathExists(publicFolderUnauth("/index.html"))).toBe(true)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await pathExists(publicFolderMain("/lib/customComponents/index.js"))
|
|
|
|
).toBe(true)
|
|
|
|
expect(
|
|
|
|
await pathExists(publicFolderUnauth("/lib/customComponents/index.js"))
|
|
|
|
).toBe(true)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await pathExists(publicFolderMain("/lib/moreCustomComponents/index.js"))
|
|
|
|
).toBe(true)
|
|
|
|
expect(
|
|
|
|
await pathExists(publicFolderUnauth("/lib/moreCustomComponents/index.js"))
|
|
|
|
).toBe(true)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await pathExists(
|
|
|
|
publicFolderMain(
|
|
|
|
"/lib/node_modules/@budibase/standard-components/dist/index.js"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).toBe(true)
|
|
|
|
expect(
|
|
|
|
await pathExists(
|
|
|
|
publicFolderUnauth(
|
|
|
|
"/lib/node_modules/@budibase/standard-components/dist/index.js"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).toBe(true)
|
|
|
|
|
|
|
|
expect(await pathExists(publicFolderUnauth("/budibase-client.js"))).toBe(true)
|
|
|
|
expect(await pathExists(publicFolderUnauth("/clientAppDefinition.js"))).toBe(
|
|
|
|
true
|
|
|
|
)
|
2019-09-09 06:24:14 +02:00
|
|
|
})
|