Output
params_test.ts
/konnectvol/konimage/src/params_test.ts
import { assertEquals } from "jsr:@std/assert"; import { parseParams } from "./params.ts"; // deno-lint-ignore no-explicit-any type ParseResult = any; Deno.test("parseParams - resize mode with valid key", () => { const url = new URL("http://localhost:8000/?mode=resize&imageurl=http://example.com/test.jpg&uniqueid=test123&imagenumber=1&key=99"); const result: ParseResult = parseParams(url); assertEquals(typeof result, "object"); assertEquals(result.mode, "resize"); assertEquals(result.imageurl, "http://example.com/test.jpg"); assertEquals(result.uniqueid, "test123"); assertEquals(result.imagenumber, 1); assertEquals(result.width, 2000); // Always overridden to 2000 }); Deno.test("parseParams - fetch mode (no key required)", () => { const url = new URL("http://localhost:8000/?mode=fetch&imageurl=http://khost/images/test.jpg"); const result: ParseResult = parseParams(url); assertEquals(typeof result, "object"); assertEquals(result.mode, "fetch"); assertEquals(result.imageurl, "http://khost/images/test.jpg"); }); Deno.test("parseParams - invalid key returns error", () => { const url = new URL("http://localhost:8000/?mode=resize&imageurl=http://example.com/test.jpg&key=invalid"); const result: ParseResult = parseParams(url); assertEquals(typeof result, "string"); assertEquals((result as string).startsWith("A12"), true); // Key validation error }); Deno.test("parseParams - daily key validation", () => { // #16 FIX: Use UTC date to match params.ts const today = ("0" + new Date().getUTCDate()).slice(-2); const url = new URL(`http://localhost:8000/?mode=resize&imageurl=http://example.com/test.jpg&uniqueid=test&imagenumber=1&key=${today}`); const result: ParseResult = parseParams(url); assertEquals(typeof result, "object"); assertEquals(result.mode, "resize"); }); Deno.test("parseParams - ping mode", () => { const url = new URL("http://localhost:8000/?mode=ping&key=99"); const result: ParseResult = parseParams(url); assertEquals(typeof result, "object"); assertEquals(result.mode, "ping"); }); Deno.test("parseParams - arrayresize mode", () => { const imageArray = JSON.stringify([{data: "http://example.com/1.jpg"}, {data: "http://example.com/2.jpg"}]); const url = new URL(`http://localhost:8000/?mode=arrayresize&imagearray=${encodeURIComponent(imageArray)}&uniqueid=batch&imagenumber=1&key=99`); const result: ParseResult = parseParams(url); assertEquals(typeof result, "object"); assertEquals(result.mode, "arrayresize"); assertEquals(result.imagearray, imageArray); });
6 tests · Tests URL parameter parsing for resize, fetch, ping, arrayresize modes plus authentication key validation
Quick Actions
Original Request
No layout configured
Details
Type
General
Status
Completed
Created
1 Jan 2026, 10:50 pm
Updated
2 Jan 2026, 3:10 pm
Created By
claude
Raw Data
{
"id": "31d52592-cd92-4fb6-82a6-3a35b0b9cd90",
"type": "general",
"status": "completed",
"title": "params_test.ts Source Code",
"description": "Konimage URL parameter parsing tests",
"context": {
"output": "<div style=\"background:#1e1e1e;color:#e0e0e0;padding:20px;border-radius:8px;font-family:'Consolas','Monaco',monospace;\">\n<h2 style=\"font-family:sans-serif;color:#fff;margin:0 0 4px 0;\">params_test.ts</h2>\n<p style=\"font-family:sans-serif;color:#7f848e;margin:0 0 16px 0;\">/konnectvol/konimage/src/params_test.ts</p>\n\n<pre style=\"background:#2d2d2d;padding:16px;border-radius:6px;overflow-x:auto;line-height:1.6;font-size:0.85rem;\"><span style=\"color:#c678dd;\">import</span> <span style=\"color:#e5c07b;\">{ assertEquals }</span> <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"jsr:@std/assert\"</span>;\n<span style=\"color:#c678dd;\">import</span> <span style=\"color:#e5c07b;\">{ parseParams }</span> <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./params.ts\"</span>;\n\n<span style=\"color:#7f848e;\">// deno-lint-ignore no-explicit-any</span>\n<span style=\"color:#c678dd;\">type</span> <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#c678dd;\">any</span>;\n\n<span style=\"color:#61afef;\">Deno.test</span>(<span style=\"color:#98c379;\">\"parseParams - resize mode with valid key\"</span>, () => {\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">url</span> = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">URL</span>(<span style=\"color:#98c379;\">\"http://localhost:8000/?mode=resize&imageurl=http://example.com/test.jpg&uniqueid=test123&imagenumber=1&key=99\"</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">result</span>: <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#61afef;\">parseParams</span>(<span style=\"color:#e06c75;\">url</span>);\n\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#c678dd;\">typeof</span> <span style=\"color:#e06c75;\">result</span>, <span style=\"color:#98c379;\">\"object\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">mode</span>, <span style=\"color:#98c379;\">\"resize\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">imageurl</span>, <span style=\"color:#98c379;\">\"http://example.com/test.jpg\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">uniqueid</span>, <span style=\"color:#98c379;\">\"test123\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">imagenumber</span>, <span style=\"color:#d19a66;\">1</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">width</span>, <span style=\"color:#d19a66;\">2000</span>); <span style=\"color:#7f848e;\">// Always overridden to 2000</span>\n});\n\n<span style=\"color:#61afef;\">Deno.test</span>(<span style=\"color:#98c379;\">\"parseParams - fetch mode (no key required)\"</span>, () => {\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">url</span> = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">URL</span>(<span style=\"color:#98c379;\">\"http://localhost:8000/?mode=fetch&imageurl=http://khost/images/test.jpg\"</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">result</span>: <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#61afef;\">parseParams</span>(<span style=\"color:#e06c75;\">url</span>);\n\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#c678dd;\">typeof</span> <span style=\"color:#e06c75;\">result</span>, <span style=\"color:#98c379;\">\"object\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">mode</span>, <span style=\"color:#98c379;\">\"fetch\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">imageurl</span>, <span style=\"color:#98c379;\">\"http://khost/images/test.jpg\"</span>);\n});\n\n<span style=\"color:#61afef;\">Deno.test</span>(<span style=\"color:#98c379;\">\"parseParams - invalid key returns error\"</span>, () => {\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">url</span> = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">URL</span>(<span style=\"color:#98c379;\">\"http://localhost:8000/?mode=resize&imageurl=http://example.com/test.jpg&key=invalid\"</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">result</span>: <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#61afef;\">parseParams</span>(<span style=\"color:#e06c75;\">url</span>);\n\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#c678dd;\">typeof</span> <span style=\"color:#e06c75;\">result</span>, <span style=\"color:#98c379;\">\"string\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>((<span style=\"color:#e06c75;\">result</span> <span style=\"color:#c678dd;\">as</span> <span style=\"color:#e5c07b;\">string</span>).<span style=\"color:#61afef;\">startsWith</span>(<span style=\"color:#98c379;\">\"A12\"</span>), <span style=\"color:#d19a66;\">true</span>); <span style=\"color:#7f848e;\">// Key validation error</span>\n});\n\n<span style=\"color:#61afef;\">Deno.test</span>(<span style=\"color:#98c379;\">\"parseParams - daily key validation\"</span>, () => {\n <span style=\"color:#7f848e;\">// #16 FIX: Use UTC date to match params.ts</span>\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">today</span> = (<span style=\"color:#98c379;\">\"0\"</span> + <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">Date</span>().<span style=\"color:#61afef;\">getUTCDate</span>()).<span style=\"color:#61afef;\">slice</span>(-<span style=\"color:#d19a66;\">2</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">url</span> = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">URL</span>(<span style=\"color:#98c379;\">`http://localhost:8000/?mode=resize&imageurl=http://example.com/test.jpg&uniqueid=test&imagenumber=1&key=${today}`</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">result</span>: <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#61afef;\">parseParams</span>(<span style=\"color:#e06c75;\">url</span>);\n\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#c678dd;\">typeof</span> <span style=\"color:#e06c75;\">result</span>, <span style=\"color:#98c379;\">\"object\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">mode</span>, <span style=\"color:#98c379;\">\"resize\"</span>);\n});\n\n<span style=\"color:#61afef;\">Deno.test</span>(<span style=\"color:#98c379;\">\"parseParams - ping mode\"</span>, () => {\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">url</span> = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">URL</span>(<span style=\"color:#98c379;\">\"http://localhost:8000/?mode=ping&key=99\"</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">result</span>: <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#61afef;\">parseParams</span>(<span style=\"color:#e06c75;\">url</span>);\n\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#c678dd;\">typeof</span> <span style=\"color:#e06c75;\">result</span>, <span style=\"color:#98c379;\">\"object\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">mode</span>, <span style=\"color:#98c379;\">\"ping\"</span>);\n});\n\n<span style=\"color:#61afef;\">Deno.test</span>(<span style=\"color:#98c379;\">\"parseParams - arrayresize mode\"</span>, () => {\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">imageArray</span> = <span style=\"color:#e5c07b;\">JSON</span>.<span style=\"color:#61afef;\">stringify</span>([{<span style=\"color:#e06c75;\">data</span>: <span style=\"color:#98c379;\">\"http://example.com/1.jpg\"</span>}, {<span style=\"color:#e06c75;\">data</span>: <span style=\"color:#98c379;\">\"http://example.com/2.jpg\"</span>}]);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">url</span> = <span style=\"color:#c678dd;\">new</span> <span style=\"color:#e5c07b;\">URL</span>(<span style=\"color:#98c379;\">`http://localhost:8000/?mode=arrayresize&imagearray=${encodeURIComponent(imageArray)}&uniqueid=batch&imagenumber=1&key=99`</span>);\n <span style=\"color:#c678dd;\">const</span> <span style=\"color:#e06c75;\">result</span>: <span style=\"color:#e5c07b;\">ParseResult</span> = <span style=\"color:#61afef;\">parseParams</span>(<span style=\"color:#e06c75;\">url</span>);\n\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#c678dd;\">typeof</span> <span style=\"color:#e06c75;\">result</span>, <span style=\"color:#98c379;\">\"object\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">mode</span>, <span style=\"color:#98c379;\">\"arrayresize\"</span>);\n <span style=\"color:#61afef;\">assertEquals</span>(<span style=\"color:#e06c75;\">result</span>.<span style=\"color:#e06c75;\">imagearray</span>, <span style=\"color:#e06c75;\">imageArray</span>);\n});</pre>\n\n<div style=\"background:#2d2d2d;padding:12px;border-radius:6px;margin-top:16px;font-family:sans-serif;\">\n<p style=\"margin:0;color:#7f848e;font-size:0.85rem;\"><strong style=\"color:#fff;\">6 tests</strong> · Tests URL parameter parsing for resize, fetch, ping, arrayresize modes plus authentication key validation</p>\n</div>\n</div>",
"requestedAt": "2026-01-01T12:43:00.000Z",
"requestId": "59d47e6f-6f76-48ab-aff3-ddb91a2efc2b"
},
"createdBy": "claude",
"createdAt": "2026-01-01T12:50:36.066Z",
"updatedAt": "2026-01-02T05:10:54.070Z",
"requestId": "59d47e6f-6f76-48ab-aff3-ddb91a2efc2b"
}