2019-07-26 16:13:15 +02: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 derivedComponent1 = require("../appPackages/testApp/components/myTextBox.json");
|
|
|
|
const derivedComponent2 = require("../appPackages/testApp/components/subfolder/otherTextBox.json");
|
2019-07-27 08:31:31 +02:00
|
|
|
const { readJSON, pathExists, unlink } = require("fs-extra");
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
const app = require("./testApp")();
|
2019-09-07 07:50:35 +02:00
|
|
|
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 () => {
|
|
|
|
|
|
|
|
const testComponent = "./appPackages/testApp/components/newTextBox.json";
|
|
|
|
const testComponentAfterMove = "./appPackages/testApp/components/anotherSubFolder/newTextBox.json";
|
|
|
|
|
|
|
|
if(await pathExists(testComponent)) await unlink(testComponent);
|
|
|
|
if(await pathExists(testComponentAfterMove)) await unlink(testComponentAfterMove);
|
|
|
|
|
|
|
|
await app.start();
|
|
|
|
});
|
2019-07-26 16:13:15 +02:00
|
|
|
afterAll(async () => await app.destroy());
|
|
|
|
|
|
|
|
|
|
|
|
it("/apppackage should get appDefinition", async () => {
|
|
|
|
|
|
|
|
const {body} = await app.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
|
|
|
|
expect(body.appDefinition).toEqual(testAppDef);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("/apppackage should get access levels", async () => {
|
|
|
|
|
|
|
|
const {body} = await app.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
|
|
|
|
expect(body.accessLevels).toEqual(testAccessLevels);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("/apppackage should get pages", async () => {
|
|
|
|
|
|
|
|
const {body} = await app.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
expect(body.pages).toEqual(testPages);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("/apppackage should get rootComponents", async () => {
|
|
|
|
|
|
|
|
const {body} = await app.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
|
|
|
|
expect(body.rootComponents["./customComponents/textbox"]).toBeDefined();
|
|
|
|
expect(body.rootComponents["./moreCustomComponents/textbox"]).toBeDefined();
|
|
|
|
|
|
|
|
expect(body.rootComponents["./customComponents/textbox"])
|
|
|
|
.toEqual(testComponents.textbox);
|
|
|
|
|
|
|
|
expect(body.rootComponents["./moreCustomComponents/textbox"])
|
|
|
|
.toEqual(testMoreComponents.textbox);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("/apppackage should get derivedComponents", async () => {
|
|
|
|
|
|
|
|
const {body} = await app.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
|
|
|
|
const expectedComponents = {
|
2019-07-28 09:03:11 +02:00
|
|
|
"myTextBox" : {...derivedComponent1, name:"myTextBox"},
|
|
|
|
"subfolder/otherTextBox": {...derivedComponent2, name:"subfolder/otherTextBox"}
|
2019-07-26 16:13:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(body.derivedComponents).toEqual(expectedComponents);
|
|
|
|
});
|
2019-07-26 18:08:59 +02:00
|
|
|
|
|
|
|
it("should be able to create new derived component", async () => {
|
|
|
|
const newDerivedComponent = {
|
2019-07-28 09:03:11 +02:00
|
|
|
name: "newTextBox",
|
|
|
|
inherits: "./customComponents/textbox",
|
|
|
|
props: {
|
|
|
|
label: "something"
|
|
|
|
}
|
2019-07-26 18:08:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
await app.post("/_builder/api/testApp/derivedcomponent", newDerivedComponent)
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
|
|
|
|
const componentFile = "./appPackages/testApp/components/newTextBox.json";
|
|
|
|
expect(await pathExists(componentFile)).toBe(true);
|
|
|
|
expect(await readJSON(componentFile)).toEqual(newDerivedComponent);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to update derived component", async () => {
|
|
|
|
const updatedDerivedComponent = {
|
2019-07-28 09:03:11 +02:00
|
|
|
name: "newTextBox",
|
|
|
|
inherits: "./customComponents/textbox",
|
|
|
|
props: {
|
|
|
|
label: "something else"
|
|
|
|
}
|
2019-07-26 18:08:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
await app.post("/_builder/api/testApp/derivedcomponent", updatedDerivedComponent)
|
|
|
|
.expect(statusCodes.OK);
|
|
|
|
|
|
|
|
const componentFile = "./appPackages/testApp/components/newTextBox.json";
|
|
|
|
expect(await readJSON(componentFile)).toEqual(updatedDerivedComponent);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to rename derived component", async () => {
|
2019-07-27 08:31:31 +02:00
|
|
|
await app.patch("/_builder/api/testApp/derivedcomponent", {
|
|
|
|
oldname: "newTextBox", newname: "anotherSubFolder/newTextBox"
|
2019-07-26 18:08:59 +02:00
|
|
|
}).expect(statusCodes.OK);
|
2019-07-27 08:31:31 +02:00
|
|
|
|
2019-07-26 18:08:59 +02: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);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to delete derived component", async () => {
|
2019-07-27 08:43:03 +02:00
|
|
|
await app.delete("/_builder/api/testApp/derivedcomponent/anotherSubFolder/newTextBox")
|
|
|
|
.expect(statusCodes.OK);
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2019-07-27 08:43:03 +02:00
|
|
|
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-07-26 18:08:59 +02:00
|
|
|
});
|