/** * Unit Tests for General Utilities * * NOTE: Per constitution requirement, proxy.js has ZERO exports. * Internal functions (generateRequestId, validateDocumentId, etc.) cannot be unit tested directly. * These functions are tested indirectly through integration tests of the main handleRequest function. * * This test file verifies constitution compliance only. */ import { test, describe } from 'node:test'; import assert from 'node:assert'; // Set up globals that server.js would provide // Note: crypto is already available on globalThis (Web Crypto API) globalThis.config = { google: {}, server: {}, sitemap: {} }; describe('Unit: Constitution Compliance', () => { test('T046: proxy.js has ZERO exports and exposes handleRequest via globalThis', async () => { // Verify proxy.js can be loaded and exposes handleRequest via globalThis await import('../../src/proxy.js'); assert.ok(globalThis.handleRequest, 'handleRequest should be available on globalThis'); assert.strictEqual(typeof globalThis.handleRequest, 'function', 'handleRequest should be a function'); }); test('T046: crypto is available on globalThis (Web Crypto API)', () => { assert.ok(globalThis.crypto, 'crypto should be available'); assert.ok(globalThis.crypto.randomUUID, 'crypto.randomUUID should be available'); // Test that it works const uuid = globalThis.crypto.randomUUID(); assert.ok(uuid, 'Should generate UUID'); assert.match(uuid, /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, 'Should be valid UUID format'); }); }); // Note: Previous unit tests for internal functions (generateRequestId, validateDocumentId, etc.) // have been moved to integration tests where they are tested through handleRequest. // This maintains test coverage while respecting the constitution's ZERO exports requirement.