Download packages/cli/src/commands/handlers/api.test.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/cli/src/commands/handlers/api.test.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/cli/src/commands/handlers/api.test.ts
-
curl -L -o api.test.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/cli/src/commands/handlers/api.test.ts
1.1 kB
| import { describe, expect, test } from "bun:test" | |
| import { rawRequest, resolveOperation } from "./api" | |
| describe("api request resolution", () => { | |
| test("resolves an operation ID with path and query parameters", () => { | |
| expect( | |
| resolveOperation( | |
| { | |
| paths: { | |
| "/api/session/{sessionID}": { | |
| get: { operationId: "v2.session.get" }, | |
| }, | |
| }, | |
| }, | |
| "v2.session.get", | |
| { sessionID: "ses/a", workspace: "work" }, | |
| ), | |
| ).toEqual({ method: "GET", path: "/api/session/ses%2Fa?workspace=work" }) | |
| }) | |
| test("rejects a missing path parameter", () => { | |
| expect(() => | |
| resolveOperation( | |
| { paths: { "/api/session/{sessionID}": { get: { operationId: "v2.session.get" } } } }, | |
| "v2.session.get", | |
| {}, | |
| ), | |
| ).toThrow("Missing path parameter: sessionID") | |
| }) | |
| test("resolves curl-like method and path input", () => { | |
| expect(rawRequest(["post", "/api/foo"])).toEqual({ method: "POST", path: "/api/foo" }) | |
| expect(rawRequest(["v2.session.list"])).toBeUndefined() | |
| }) | |
| }) | |