// author: simon-pierre boucher import { describe, expect, it } from "vitest"; import { buildHeaders, BOT_SUFFIX } from "./headers.js"; describe("buildHeaders", () => { it("emits headers in Safari order", () => { const keys = Object.keys(buildHeaders("example.com")); expect(keys).toEqual([ "Host", "Accept", "Accept-Language", "Accept-Encoding", "User-Agent", "Connection", "Sec-Fetch-Dest", "Sec-Fetch-Mode", "Sec-Fetch-Site", "Sec-Fetch-User", "Upgrade-Insecure-Requests", ]); }); it("always appends the bot suffix to the UA (ยง26)", () => { expect(buildHeaders("example.com")["User-Agent"]).toContain(BOT_SUFFIX); expect(buildHeaders("example.com", {}, "Custom/9")["User-Agent"]).toBe("Custom/9" + BOT_SUFFIX); }); it("sets the Host header from the argument", () => { expect(buildHeaders("shop.example")["Host"]).toBe("shop.example"); }); it("merges overrides over defaults without reordering base keys", () => { const h = buildHeaders("example.com", { "Accept-Language": "fr-CA,fr;q=0.9", "X-Extra": "1" }); expect(h["Accept-Language"]).toBe("fr-CA,fr;q=0.9"); expect(h["X-Extra"]).toBe("1"); }); });