forked from tsai/budibase
8 changed files with 171 additions and 4 deletions
@ -1,5 +1,7 @@ |
|||
const env = require("../../environment") |
|||
|
|||
exports.isEnabled = async function(ctx) { |
|||
ctx.body = JSON.stringify(env.ENABLE_ANALYTICS === "true") |
|||
ctx.body = { |
|||
enabled: env.ENABLE_ANALYTICS === "true", |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,38 @@ |
|||
const setup = require("./utilities") |
|||
|
|||
describe("/analytics", () => { |
|||
let request = setup.getRequest() |
|||
let config = setup.getConfig() |
|||
|
|||
afterAll(setup.afterAll) |
|||
|
|||
beforeEach(async () => { |
|||
await config.init() |
|||
}) |
|||
|
|||
describe("isEnabled", () => { |
|||
it("check if analytics enabled", async () => { |
|||
const res = await request |
|||
.get(`/api/analytics`) |
|||
.set(config.defaultHeaders()) |
|||
.expect("Content-Type", /json/) |
|||
.expect(200) |
|||
expect(typeof res.body.enabled).toEqual("boolean") |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
describe("/health", () => { |
|||
it("should confirm healthy", async () => { |
|||
let config = setup.getConfig() |
|||
await config.getRequest().get("/health").expect(200) |
|||
}) |
|||
}) |
|||
|
|||
describe("/version", () => { |
|||
it("should confirm version", async () => { |
|||
const config = setup.getConfig() |
|||
const res = await config.getRequest().get("/version").expect(200) |
|||
expect(res.text.split(".").length).toEqual(3) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,77 @@ |
|||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions") |
|||
const setup = require("./utilities") |
|||
const { basicScreen } = require("./utilities/structures") |
|||
|
|||
describe("/screens", () => { |
|||
let request = setup.getRequest() |
|||
let config = setup.getConfig() |
|||
let screen |
|||
|
|||
afterAll(setup.afterAll) |
|||
|
|||
beforeEach(async () => { |
|||
await config.init() |
|||
screen = await config.createScreen() |
|||
}) |
|||
|
|||
describe("fetch", () => { |
|||
it("should be able to create a layout", async () => { |
|||
const res = await request |
|||
.get(`/api/screens`) |
|||
.set(config.defaultHeaders()) |
|||
.expect("Content-Type", /json/) |
|||
.expect(200) |
|||
expect(res.body.length).toEqual(1) |
|||
expect(res.body[0]._id).toEqual(screen._id) |
|||
}) |
|||
|
|||
it("should apply authorization to endpoint", async () => { |
|||
await checkBuilderEndpoint({ |
|||
config, |
|||
method: "GET", |
|||
url: `/api/screens`, |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
describe("save", () => { |
|||
it("should be able to save a screen", async () => { |
|||
const screenCfg = basicScreen() |
|||
const res = await request |
|||
.post(`/api/screens`) |
|||
.send(screenCfg) |
|||
.set(config.defaultHeaders()) |
|||
.expect("Content-Type", /json/) |
|||
.expect(200) |
|||
expect(res.body._rev).toBeDefined() |
|||
expect(res.body.name).toEqual(screenCfg.name) |
|||
}) |
|||
|
|||
it("should apply authorization to endpoint", async () => { |
|||
await checkBuilderEndpoint({ |
|||
config, |
|||
method: "POST", |
|||
url: `/api/screens`, |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
describe("destroy", () => { |
|||
it("should be able to delete the screen", async () => { |
|||
const res = await request |
|||
.delete(`/api/screens/${screen._id}/${screen._rev}`) |
|||
.set(config.defaultHeaders()) |
|||
.expect("Content-Type", /json/) |
|||
.expect(200) |
|||
expect(res.body.message).toBeDefined() |
|||
}) |
|||
|
|||
it("should apply authorization to endpoint", async () => { |
|||
await checkBuilderEndpoint({ |
|||
config, |
|||
method: "DELETE", |
|||
url: `/api/screens/${screen._id}/${screen._rev}`, |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
|||
Loading…
Reference in new issue