Files
cloudflare-domain-manager/apps/api/test/nodes-api.test.ts
T
Denozordec 3f6f402872
quality / commitlint (push) Skipped
CD / update-wiki (push) Failing after 8s
quality / changes (push) Successful in 5s
quality / docker-check (push) Skipped
quality / web (push) Successful in 50s
quality / api (push) Successful in 41s
CD / quality (push) Successful in 1m40s
CD / publish (push) Successful in 1m33s
feat(health-checks): enhance health check functionality and add new routes
- Introduced origin health check routes and integrated them into the application.
- Updated health check configuration to include success recovery thresholds.
- Expanded error handling with new error codes for health check failures.
- Added new service routes for managing health checks, including creation and listing.
- Improved health check service logic to track consecutive successes and failures.

This commit enhances the health check capabilities, providing better monitoring and management of service health.
2026-08-19 12:26:12 +07:00

55 lines
1.7 KiB
TypeScript

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<ReturnType<typeof buildApp>>) {
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();
});
});