diff --git a/packages/server/src/api/controllers/debug.ts b/packages/server/src/api/controllers/debug.ts index 8210971749..6ed52973cd 100644 --- a/packages/server/src/api/controllers/debug.ts +++ b/packages/server/src/api/controllers/debug.ts @@ -1,8 +1,11 @@ import os from "os" import process from "process" import { env } from "@budibase/backend-core" +import { GetDiagnosticsResponse, UserCtx } from "@budibase/types" -export async function systemDebugInfo(ctx: any) { +export async function systemDebugInfo( + ctx: UserCtx +) { const { days, hours, minutes } = secondsToHMS(os.uptime()) const totalMemory = convertBytes(os.totalmem()) diff --git a/packages/server/src/api/routes/tests/debug.spec.ts b/packages/server/src/api/routes/tests/debug.spec.ts new file mode 100644 index 0000000000..23ee43fc73 --- /dev/null +++ b/packages/server/src/api/routes/tests/debug.spec.ts @@ -0,0 +1,64 @@ +const { checkBuilderEndpoint } = require("./utilities/TestFunctions") +const setup = require("./utilities") +import os from "os" + +jest.mock("process", () => ({ + arch: "arm64", + version: "v14.20.1", + platform: "darwin", +})) + +describe("/component", () => { + let request = setup.getRequest() + let config = setup.getConfig() + + afterAll(setup.afterAll) + + beforeAll(async () => { + await config.init() + os.cpus = () => [ + { + model: "test", + speed: 12323, + times: { + user: 0, + nice: 0, + sys: 0, + idle: 0, + irq: 0, + }, + }, + ] + os.uptime = () => 123123123123 + os.totalmem = () => 10000000000 + }) + + describe("/api/debug", () => { + it("should return debug information to the frontend", async () => { + const res = await request + .get(`/api/debug/diagnostics`) + .set(config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(200) + expect(res.body).toEqual({ + budibaseVersion: "0.0.0", + cpuArch: "arm64", + cpuCores: 1, + cpuInfo: "test", + hosting: "docker-compose", + nodeVersion: "v14.20.1", + platform: "darwin", + totalMemory: "9.313225746154785GB", + uptime: "1425036 day(s), 3 hour(s), 32 minute(s)", + }) + }) + + it("should apply authorization to endpoint", async () => { + await checkBuilderEndpoint({ + config, + method: "GET", + url: `/api/debug/diagnostics`, + }) + }) + }) +}) diff --git a/packages/types/src/api/web/debug.ts b/packages/types/src/api/web/debug.ts new file mode 100644 index 0000000000..ea6ee8829f --- /dev/null +++ b/packages/types/src/api/web/debug.ts @@ -0,0 +1,11 @@ +export interface GetDiagnosticsResponse { + budibaseVersion: string + hosting: string + nodeVersion: string + platform: string + cpuArch: string + cpuCores: number + cpuInfo: string + totalMemory: string + uptime: string +} diff --git a/packages/types/src/api/web/index.ts b/packages/types/src/api/web/index.ts index 6d3b4124f5..0e0527eb7f 100644 --- a/packages/types/src/api/web/index.ts +++ b/packages/types/src/api/web/index.ts @@ -2,6 +2,7 @@ export * from "./analytics" export * from "./auth" export * from "./user" export * from "./errors" +export * from "./debug" export * from "./schedule" export * from "./system" export * from "./app"