code review and test

This commit is contained in:
Martin McKeaveney 2023-07-17 22:33:37 +01:00
parent 962b96fffc
commit fb1ecbb5c9
4 changed files with 80 additions and 1 deletions

View File

@ -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<void, GetDiagnosticsResponse>
) {
const { days, hours, minutes } = secondsToHMS(os.uptime())
const totalMemory = convertBytes(os.totalmem())

View File

@ -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`,
})
})
})
})

View File

@ -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
}

View File

@ -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"