// deno-lint-ignore-file require-await import { ltProxyHandler } from '../ltProxyHandler.ts'; import { assertEquals } from 'https://deno.land/std@0.204.0/assert/mod.ts'; import type { IContext } from 'http-kernel/Interfaces/mod.ts'; Deno.test('ltProxyHandler: proxies request and returns response', async () => { const expectedResponse = new Response('Mocked LT Response', { status: 200, headers: { 'content-type': 'text/plain', 'x-mocked': 'true', }, }); // Backup and mock global fetch const originalFetch = globalThis.fetch; globalThis.fetch = async () => expectedResponse; const req = new Request('http://localhost/v2/check?language=de-DE', { method: 'POST', body: new TextEncoder().encode('text=Hallo+Welt'), headers: { 'content-type': 'application/x-www-form-urlencoded', }, }); const ctx: IContext = { req, params: {}, query: { language: 'de-DE', }, state: {}, }; const response = await ltProxyHandler(ctx); assertEquals(response.status, 200); assertEquals(await response.text(), 'Mocked LT Response'); assertEquals(response.headers.get('x-mocked'), 'true'); // Restore fetch globalThis.fetch = originalFetch; });