feat: add HTTP server adapter and request-mapping tests
This commit is contained in:
31
test/server.test.js
Normal file
31
test/server.test.js
Normal 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}");
|
||||
});
|
||||
Reference in New Issue
Block a user