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 }); 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) => { .post("/:appname/api/authenticate", async (ctx, next) => {
const user = await ctx.master.authenticate( const user = await ctx.master.authenticate(
ctx.sessionId, ctx.sessionId,

View File

@ -2,6 +2,7 @@ const app = require("./testApp")();
const authenticateMaster = require("./authenticate"); const authenticateMaster = require("./authenticate");
const createNewApp = require("./createNewApp"); const createNewApp = require("./createNewApp");
const multipleInstances = require("./multipleInstances"); const multipleInstances = require("./multipleInstances");
const serveui = require("./serveui");
beforeAll(async () => await app.start()) beforeAll(async () => await app.start())
@ -11,5 +12,6 @@ describe("authenticateMaster", () => authenticateMaster(app, "_master", "masterO
describe("createNewApp", () => createNewApp(app)); describe("createNewApp", () => createNewApp(app));
describe("authenticateTestApp", () => authenticateMaster(app, "testApp", "testAppUser1")); describe("authenticateTestApp", () => authenticateMaster(app, "testApp", "testAppUser1"));
describe("multipleInstances", () => multipleInstances(app)); 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)) join("..", getRuntimePackageDirectory(appname, versionId))
const publicPaths = (appPath) => ({ const publicPaths = (appPath) => ({
mainUiPath: join( mainUiPath: resolve(join(
appPath, "ui", "main", "public"), __dirname, appPath, "ui", "main", "public")),
unauthenticatedUiPath: join( unauthenticatedUiPath: resolve(join(
appPath, "ui", "unauthenticated", "public") __dirname, appPath, "ui", "unauthenticated", "public"))
}); });