Files
caddy-proxy-manager/tests/unit/api-routes/openapi.test.ts
fuomag9 28f61082ce test: comprehensive API test coverage with full input variations
- OpenAPI endpoint: 5 tests (spec structure, paths, headers, schemas)
- Proxy hosts: POST/PUT/GET with all nested fields (authentik, load_balancer,
  dns_resolver, geoblock, waf, mtls, redirects, rewrite) + error cases
- L4 proxy hosts: TCP+TLS, UDP, matcher/protocol variations + error cases
- Certificates: managed with provider_options, imported with PEM fields
- Client certificates: all required fields, revoke with revoked_at
- Access lists: seed users, entry add with username/password + error cases
- Settings: GET+PUT for all 11 groups (was 3), full data shapes
- API auth: empty Bearer, CSRF session vs Bearer, apiErrorResponse variants
- API tokens integration: cross-user isolation, admin visibility, inactive user
- CA certificates: PUT/DELETE error cases

646 tests total (54 new)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 10:15:22 +01:00

48 lines
1.7 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { GET } from '@/app/api/v1/openapi.json/route';
describe('GET /api/v1/openapi.json', () => {
it('returns 200', async () => {
const response = await GET();
expect(response.status).toBe(200);
});
it('returns valid JSON with openapi field = "3.1.0"', async () => {
const response = await GET();
const data = await response.json();
expect(data.openapi).toBe('3.1.0');
});
it('contains all expected paths', async () => {
const response = await GET();
const data = await response.json();
const paths = Object.keys(data.paths);
expect(paths).toContain('/api/v1/tokens');
expect(paths).toContain('/api/v1/proxy-hosts');
expect(paths).toContain('/api/v1/l4-proxy-hosts');
expect(paths).toContain('/api/v1/certificates');
expect(paths).toContain('/api/v1/ca-certificates');
expect(paths).toContain('/api/v1/client-certificates');
expect(paths).toContain('/api/v1/access-lists');
expect(paths).toContain('/api/v1/settings/{group}');
expect(paths).toContain('/api/v1/instances');
expect(paths).toContain('/api/v1/users');
expect(paths).toContain('/api/v1/audit-log');
expect(paths).toContain('/api/v1/caddy/apply');
});
it('has Cache-Control header', async () => {
const response = await GET();
expect(response.headers.get('Cache-Control')).toBe('public, max-age=3600');
});
it('has components.schemas defined', async () => {
const response = await GET();
const data = await response.json();
expect(data.components).toBeDefined();
expect(data.components.schemas).toBeDefined();
expect(Object.keys(data.components.schemas).length).toBeGreaterThan(0);
});
});