import { assertEquals } from 'test-deps'; import Controller from 'if/controllers/controller.class.ts'; Deno.test('Controller class', async () => { const mockHandler = (req: Request) => new Response('Hello, world!'); const controller = new Controller({ '/_GET': mockHandler, }); // Test that the handler was stored correctly assertEquals(controller.handlers['/_GET'], mockHandler); // Test the response method const req = new Request('http://localhost/'); const res = Controller.response(req, 'Hello, world!'); assertEquals(res.status, 200); assertEquals( new TextDecoder().decode(new Uint8Array(await res.arrayBuffer())), 'Hello, world!', ); // Test the responseJSON method const jsonRes = Controller.responseJSON(req, { message: 'Hello, world!' }); assertEquals(jsonRes.status, 200); assertEquals(await jsonRes.json(), { message: 'Hello, world!' }); });