feat: add HTTP server adapter and request-mapping tests

This commit is contained in:
Codex
2026-02-18 12:37:46 +00:00
parent fedab9f7bd
commit 78d72cc4a9
2 changed files with 110 additions and 0 deletions

31
test/server.test.js Normal file
View File

@@ -0,0 +1,31 @@
"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const { mapToAppRequest, normalizeHeaders } = require("../src/server");
test("normalizeHeaders lowercases and joins array values", () => {
const headers = normalizeHeaders({
"X-User-Id": "u1",
"X-Forwarded-For": ["a", "b"],
});
assert.equal(headers["x-user-id"], "u1");
assert.equal(headers["x-forwarded-for"], "a,b");
});
test("mapToAppRequest extracts method/path/headers/body correctly", () => {
const request = mapToAppRequest({
req: {
method: "POST",
url: "/api/webhooks/x?debug=1",
headers: { "X-Signature": "sha256=abc" },
},
rawBody: "{\"ok\":true}",
});
assert.equal(request.method, "POST");
assert.equal(request.path, "/api/webhooks/x");
assert.equal(request.headers["x-signature"], "sha256=abc");
assert.equal(request.rawBody, "{\"ok\":true}");
});