Enhance CDN Manager: Add Cloudflare API token support, update documentation, and introduce new routes for managing nodes, aliases, and topology. Improve UI components and status badges for better user experience.
quality / commitlint (push) Skipped
quality / changes (push) Successful in 5s
quality / docker-check (push) Skipped
CD / update-wiki (push) Successful in 6s
quality / web (push) Successful in 53s
quality / api (push) Successful in 49s
CD / quality (push) Successful in 1m57s
CD / publish (push) Successful in 27s
quality / commitlint (push) Skipped
quality / changes (push) Successful in 5s
quality / docker-check (push) Skipped
CD / update-wiki (push) Successful in 6s
quality / web (push) Successful in 53s
quality / api (push) Successful in 49s
CD / quality (push) Successful in 1m57s
CD / publish (push) Successful in 27s
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
||||
import { buildApp } from "../src/app.js";
|
||||
import { loadConfig } from "../src/config.js";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
describe("fleet api", () => {
|
||||
let app: FastifyInstance;
|
||||
let authHeader: { authorization: string };
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await buildApp({
|
||||
config: { ...loadConfig(), staticDir: null, authRequired: false },
|
||||
memory: true,
|
||||
});
|
||||
const login = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/auth/login",
|
||||
payload: { username: "admin", password: "admin" },
|
||||
});
|
||||
expect(login.statusCode).toBe(200);
|
||||
const token = login.json().token as string;
|
||||
authHeader = { authorization: `Bearer ${token}` };
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it("lists seeded locations", async () => {
|
||||
const res = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/v1/locations",
|
||||
headers: authHeader,
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
expect(body.length).toBeGreaterThanOrEqual(5);
|
||||
expect(body.some((l: { code: string }) => l.code === "msk")).toBe(true);
|
||||
});
|
||||
|
||||
it("creates zone, node, alias and exports bind", async () => {
|
||||
const zoneRes = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/zones",
|
||||
headers: authHeader,
|
||||
payload: { name: "rtnt.top" },
|
||||
});
|
||||
expect(zoneRes.statusCode).toBe(200);
|
||||
const zone = zoneRes.json();
|
||||
|
||||
const locs = (
|
||||
await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/v1/locations",
|
||||
headers: authHeader,
|
||||
})
|
||||
).json();
|
||||
const msk = locs.find((l: { code: string }) => l.code === "msk");
|
||||
|
||||
const nodeRes = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/nodes",
|
||||
headers: authHeader,
|
||||
payload: {
|
||||
zoneId: zone.id,
|
||||
locationId: msk.id,
|
||||
role: "hub",
|
||||
indexNum: 1,
|
||||
ipv4: "94.142.140.141",
|
||||
},
|
||||
});
|
||||
expect(nodeRes.statusCode).toBe(200);
|
||||
const node = nodeRes.json();
|
||||
expect(node.hostname).toBe("msk-hub01.rtnt.top");
|
||||
|
||||
const aliasRes = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/aliases",
|
||||
headers: authHeader,
|
||||
payload: {
|
||||
zoneId: zone.id,
|
||||
name: "msk.rtnt.top",
|
||||
purpose: "geo",
|
||||
mode: "primary",
|
||||
targetNodeId: node.id,
|
||||
},
|
||||
});
|
||||
expect(aliasRes.statusCode).toBe(200);
|
||||
|
||||
const bind = await app.inject({
|
||||
method: "GET",
|
||||
url: `/api/v1/zones/${zone.id}/export/bind`,
|
||||
headers: authHeader,
|
||||
});
|
||||
expect(bind.statusCode).toBe(200);
|
||||
expect(bind.json().content).toContain("msk-hub01.rtnt.top");
|
||||
expect(bind.json().content).toContain("msk.rtnt.top");
|
||||
|
||||
const stats = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/v1/dashboard/stats",
|
||||
headers: authHeader,
|
||||
});
|
||||
expect(stats.statusCode).toBe(200);
|
||||
expect(stats.json().nodes).toBe(1);
|
||||
expect(stats.json().aliases).toBe(1);
|
||||
|
||||
const topo = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/v1/topology",
|
||||
headers: authHeader,
|
||||
});
|
||||
expect(topo.statusCode).toBe(200);
|
||||
expect(topo.json().nodes).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user