Files
cloudflare-domain-manager/apps/api/test/change-domain.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

77 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { repos } from "@cfdm/db";
import type { CloudflareClient } from "../src/lib/cf-client.js";
import { buildApp } from "../src/app.js";
import { loadConfig } from "../src/config.js";
import { changeServiceDomain } from "../src/services/change-domain-service.js";
import { updateConfig } from "../src/services/service-config-service.js";
function mockCf(): CloudflareClient {
return {
listDnsRecords: async () => [],
createDnsRecord: async (_zoneId: string, payload: { type: string; name: string; content: string }) => ({
id: `cf-${payload.name}-${payload.content}`,
type: payload.type,
name: payload.name,
content: payload.content,
ttl: 1,
proxied: false,
}),
updateDnsRecord: async (
_zoneId: string,
id: string,
payload: { type: string; name: string; content: string },
) => ({
id,
type: payload.type,
name: payload.name,
content: payload.content,
ttl: 1,
proxied: false,
}),
patchDnsRecord: async (
_zoneId: string,
id: string,
payload: { content?: string },
) => ({
id,
type: "A",
name: "app.example.com",
content: payload.content ?? "1.1.1.1",
ttl: 1,
proxied: false,
}),
deleteDnsRecord: async () => undefined,
listZones: async () => [
{ id: "zone-1", name: "example.com", status: "active" },
{ id: "zone-2", name: "other.com", status: "active" },
],
} as unknown as CloudflareClient;
}
describe("change-domain", () => {
it("dry-run lists FQDN from → to", async () => {
const app = await buildApp({
config: { ...loadConfig(), staticDir: null },
memory: true,
});
const cf = mockCf();
const from = repos.createDomain(app.db, null, "example.com", "zone-1");
const to = repos.createDomain(app.db, null, "other.com", "zone-2");
const service = repos.createService(app.db, "App", "app");
await updateConfig(app.db, cf, service.id, {
ips: ["1.1.1.1"],
domains: [{ fqdn: "app.example.com", target_ips: ["1.1.1.1"] }],
});
const preview = await changeServiceDomain(app.db, cf, service.id, {
from_domain_id: from.id,
to_domain_id: to.id,
dry_run: true,
});
expect(preview.applied).toBe(false);
expect(preview.items[0]?.from_fqdn).toBe("app.example.com");
expect(preview.items[0]?.to_fqdn).toBe("app.other.com");
await app.close();
});
});