|
| 1 | +// npx vitest run src/api/providers/__tests__/constants.spec.ts |
| 2 | + |
| 3 | +import { describe, it, expect } from "vitest" |
| 4 | +import { DEFAULT_HEADERS } from "../constants" |
| 5 | +import { Package } from "../../../shared/package" |
| 6 | + |
| 7 | +describe("DEFAULT_HEADERS", () => { |
| 8 | + it("should contain all required headers", () => { |
| 9 | + expect(DEFAULT_HEADERS).toHaveProperty("HTTP-Referer") |
| 10 | + expect(DEFAULT_HEADERS).toHaveProperty("X-Title") |
| 11 | + expect(DEFAULT_HEADERS).toHaveProperty("User-Agent") |
| 12 | + }) |
| 13 | + |
| 14 | + it("should have correct HTTP-Referer value", () => { |
| 15 | + expect(DEFAULT_HEADERS["HTTP-Referer"]).toBe("https://github.com/RooVetGit/Roo-Cline") |
| 16 | + }) |
| 17 | + |
| 18 | + it("should have correct X-Title value", () => { |
| 19 | + expect(DEFAULT_HEADERS["X-Title"]).toBe("Roo Code") |
| 20 | + }) |
| 21 | + |
| 22 | + it("should have correct User-Agent format", () => { |
| 23 | + const userAgent = DEFAULT_HEADERS["User-Agent"] |
| 24 | + expect(userAgent).toBe(`RooCode/${Package.version}`) |
| 25 | + |
| 26 | + // Verify it follows the tool_name/version pattern |
| 27 | + expect(userAgent).toMatch(/^[a-zA-Z-]+\/\d+\.\d+\.\d+$/) |
| 28 | + }) |
| 29 | + |
| 30 | + it("should have User-Agent with correct tool name", () => { |
| 31 | + const userAgent = DEFAULT_HEADERS["User-Agent"] |
| 32 | + expect(userAgent.startsWith("RooCode/")).toBe(true) |
| 33 | + }) |
| 34 | + |
| 35 | + it("should have User-Agent with semantic version format", () => { |
| 36 | + const userAgent = DEFAULT_HEADERS["User-Agent"] |
| 37 | + const version = userAgent.split("/")[1] |
| 38 | + |
| 39 | + // Check semantic version format (major.minor.patch) |
| 40 | + expect(version).toMatch(/^\d+\.\d+\.\d+$/) |
| 41 | + |
| 42 | + // Verify current version matches package version |
| 43 | + expect(version).toBe(Package.version) |
| 44 | + }) |
| 45 | + |
| 46 | + it("should be an object with string values", () => { |
| 47 | + expect(typeof DEFAULT_HEADERS).toBe("object") |
| 48 | + expect(DEFAULT_HEADERS).not.toBeNull() |
| 49 | + |
| 50 | + Object.values(DEFAULT_HEADERS).forEach((value) => { |
| 51 | + expect(typeof value).toBe("string") |
| 52 | + expect(value.length).toBeGreaterThan(0) |
| 53 | + }) |
| 54 | + }) |
| 55 | + |
| 56 | + it("should have exactly 3 headers", () => { |
| 57 | + const headerKeys = Object.keys(DEFAULT_HEADERS) |
| 58 | + expect(headerKeys).toHaveLength(3) |
| 59 | + expect(headerKeys).toEqual(["HTTP-Referer", "X-Title", "User-Agent"]) |
| 60 | + }) |
| 61 | +}) |
0 commit comments