import { describe, expect, it } from "vitest"; import { repos } from "@cfdm/db"; import { buildApp } from "../src/app.js"; import { loadConfig } from "../src/config.js"; async function authHeaders(app: Awaited>) { const config = loadConfig(); const res = await app.inject({ method: "POST", url: "/api/v1/auth/login", payload: { username: config.adminUsername, password: "admin" }, }); expect(res.statusCode).toBe(200); const { token } = res.json() as { token: string }; return { authorization: `Bearer ${token}` }; } describe("service nodes API", () => { it("creates and lists nodes without changing empty DNS pool until bound", async () => { const app = await buildApp({ config: { ...loadConfig(), staticDir: null }, memory: true, }); const headers = await authHeaders(app); const service = repos.createService(app.db, "Panel", "panel"); const created = await app.inject({ method: "POST", url: `/api/v1/services/${service.id}/nodes`, headers, payload: { address: "10.0.0.8", protocol: "tcp" }, }); expect(created.statusCode).toBe(200); const node = created.json() as { address: string }; expect(node.address).toBe("10.0.0.8"); expect(repos.listServiceIps(app.db, service.id)).toContain("10.0.0.8"); const listed = await app.inject({ method: "GET", url: `/api/v1/services/${service.id}/nodes`, headers, }); expect(listed.statusCode).toBe(200); expect(listed.json()).toHaveLength(1); const overview = await app.inject({ method: "GET", url: `/api/v1/services/${service.id}/overview`, headers, }); expect(overview.statusCode).toBe(200); await app.close(); }); });