1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

routes for serving UI, now tested

This commit is contained in:
michael shanks 2019-07-19 08:13:39 +01:00
parent 7bc6dfbdd3
commit 601755f17a
9 changed files with 62 additions and 8 deletions

View file

@ -0,0 +1 @@
console.log("test app 1 - main");

View file

@ -0,0 +1,3 @@
<html>
<body>MAIN - TEST APP 1</body>
</html>

View file

@ -0,0 +1 @@
console.log("test app 1 - unauthenticated");

View file

@ -0,0 +1,3 @@
<html>
<body>UNAUTHENTICATED - TEST APP 1</body>
</html>

View file

@ -69,10 +69,6 @@ module.exports = (config, app) => {
await send(ctx, path, { root: builderPath });
}
})
.get("/:appname", async (ctx) => {
ctx.response.status = StatusCodes.OK;
ctx.response.body = "UI Served Here";
})
.post("/:appname/api/authenticate", async (ctx, next) => {
const user = await ctx.master.authenticate(
ctx.sessionId,

View file

@ -2,6 +2,7 @@ const app = require("./testApp")();
const authenticateMaster = require("./authenticate");
const createNewApp = require("./createNewApp");
const multipleInstances = require("./multipleInstances");
const serveui = require("./serveui");
beforeAll(async () => await app.start())
@ -11,5 +12,6 @@ describe("authenticateMaster", () => authenticateMaster(app, "_master", "masterO
describe("createNewApp", () => createNewApp(app));
describe("authenticateTestApp", () => authenticateMaster(app, "testApp", "testAppUser1"));
describe("multipleInstances", () => multipleInstances(app));
describe("serveUi", () => serveui(app));

View file

@ -0,0 +1,48 @@
const statusCodes = require("../utilities/statusCodes");
const { readFile } = require("../utilities/fsawait");
module.exports = (app) => {
it("should serve unauthenticated index.html as default", async () => {
const response = await app.get("/testApp")
.expect(statusCodes.OK);
const expectedIndexHtml = await readFile("appPackages/testApp/ui/unauthenticated/public/index.html", "utf8");
expect(response.text).toBe(expectedIndexHtml);
});
it("should serve specified files when unauthenticated", async () => {
const response = await app.get("/testApp/app.js")
.expect(statusCodes.OK);
const expectedFile = await readFile("appPackages/testApp/ui/unauthenticated/public/app.js", "utf8");
expect(response.text).toBe(expectedFile);
});
it("should serve main index.html as default when authenticated", async () => {
const response = await app.get("/testApp")
.set("cookie", app.credentials.testAppUser1.cookie)
.expect(statusCodes.OK);
const expectedIndexHtml = await readFile("appPackages/testApp/ui/main/public/index.html", "utf8");
expect(response.text).toBe(expectedIndexHtml);
});
it("should serve specified files when authenticated", async () => {
const response = await app.get("/testApp/app.js")
.set("cookie", app.credentials.testAppUser1.cookie)
.expect(statusCodes.OK);
const expectedFile = await readFile("appPackages/testApp/ui/main/public/app.js", "utf8");
expect(response.text).toBe(expectedFile);
});
}

View file

@ -64,10 +64,10 @@ const applictionVersionPath = (appname, versionId) =>
join("..", getRuntimePackageDirectory(appname, versionId))
const publicPaths = (appPath) => ({
mainUiPath: join(
appPath, "ui", "main", "public"),
unauthenticatedUiPath: join(
appPath, "ui", "unauthenticated", "public")
mainUiPath: resolve(join(
__dirname, appPath, "ui", "main", "public")),
unauthenticatedUiPath: resolve(join(
__dirname, appPath, "ui", "unauthenticated", "public"))
});