|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { resolveUpstreamUrl } from "../url.js"; |
| 3 | + |
| 4 | +describe("resolveUpstreamUrl", () => { |
| 5 | + it("preserves base path prefix", () => { |
| 6 | + expect(resolveUpstreamUrl("https://openrouter.ai/api", "/v1/chat/completions").href).toBe( |
| 7 | + "https://openrouter.ai/api/v1/chat/completions", |
| 8 | + ); |
| 9 | + }); |
| 10 | + |
| 11 | + it("works with root-path providers", () => { |
| 12 | + expect(resolveUpstreamUrl("https://api.openai.com", "/v1/chat/completions").href).toBe( |
| 13 | + "https://api.openai.com/v1/chat/completions", |
| 14 | + ); |
| 15 | + }); |
| 16 | + |
| 17 | + it("handles trailing slash on base", () => { |
| 18 | + expect(resolveUpstreamUrl("https://openrouter.ai/api/", "/v1/messages").href).toBe( |
| 19 | + "https://openrouter.ai/api/v1/messages", |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + it("handles no leading slash on pathname", () => { |
| 24 | + expect(resolveUpstreamUrl("https://api.anthropic.com", "v1/messages").href).toBe( |
| 25 | + "https://api.anthropic.com/v1/messages", |
| 26 | + ); |
| 27 | + }); |
| 28 | + |
| 29 | + it("handles both trailing and no leading slash", () => { |
| 30 | + expect(resolveUpstreamUrl("https://openrouter.ai/api/", "v1/embeddings").href).toBe( |
| 31 | + "https://openrouter.ai/api/v1/embeddings", |
| 32 | + ); |
| 33 | + }); |
| 34 | +}); |
0 commit comments