1
0
Fork 0
mirror of synced 2024-07-13 10:15:49 +12:00
budibase/packages/server/tests/serveui.js

70 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-07-19 19:13:39 +12:00
const statusCodes = require("../utilities/statusCodes");
2019-07-27 04:08:59 +12:00
const { readFile } = require("fs-extra");
2019-07-19 19:13:39 +12:00
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/public/unauthenticated/index.html", "utf8");
2019-07-19 19:13:39 +12:00
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/public/unauthenticated/app.js", "utf8");
2019-07-19 19:13:39 +12:00
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/public/main/index.html", "utf8");
2019-07-19 19:13:39 +12:00
expect(response.text).toBe(expectedIndexHtml);
});
it("should serve specified files when authenticated", async () => {
2019-09-11 17:08:39 +12:00
const response = await app.get("/testApp/budibase-client.js")
2019-07-19 19:13:39 +12:00
.set("cookie", app.credentials.testAppUser1.cookie)
.expect(statusCodes.OK);
2019-09-11 17:08:39 +12:00
const expectedFile = await readFile("appPackages/testApp/public/main/budibase-client.js", "utf8");
2019-07-19 19:13:39 +12:00
expect(response.text).toBe(expectedFile);
});
2019-09-13 02:55:36 +12:00
it("should serve file from shared when authenticated", async () => {
const response = await app.get("/testApp/_shared/shared_file.txt")
.set("cookie", app.credentials.testAppUser1.cookie)
.expect(statusCodes.OK);
const expectedFile = await readFile("appPackages/testApp/public/_shared/shared_file.txt", "utf8");
expect(response.text).toBe(expectedFile);
});
it("should serve file from shared when not authenticated", async () => {
const response = await app.get("/testApp/_shared/shared_file.txt")
.expect(statusCodes.OK);
const expectedFile = await readFile("appPackages/testApp/public/_shared/shared_file.txt", "utf8");
expect(response.text).toBe(expectedFile);
});
2019-07-19 19:13:39 +12:00
}