mirror of https://github.com/openclaw/openclaw.git
test: tighten shared fetch helper coverage
This commit is contained in:
parent
3e9243817e
commit
e895d4d1a8
|
|
@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||||
import {
|
import {
|
||||||
buildUsageErrorSnapshot,
|
buildUsageErrorSnapshot,
|
||||||
buildUsageHttpErrorSnapshot,
|
buildUsageHttpErrorSnapshot,
|
||||||
|
parseFiniteNumber,
|
||||||
} from "./provider-usage.fetch.shared.js";
|
} from "./provider-usage.fetch.shared.js";
|
||||||
|
|
||||||
describe("provider usage fetch shared helpers", () => {
|
describe("provider usage fetch shared helpers", () => {
|
||||||
|
|
@ -14,6 +15,14 @@ describe("provider usage fetch shared helpers", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ value: 12, expected: 12 },
|
||||||
|
{ value: "12.5", expected: 12.5 },
|
||||||
|
{ value: "not-a-number", expected: undefined },
|
||||||
|
])("parses finite numbers for %j", ({ value, expected }) => {
|
||||||
|
expect(parseFiniteNumber(value)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it("maps configured status codes to token expired", () => {
|
it("maps configured status codes to token expired", () => {
|
||||||
const snapshot = buildUsageHttpErrorSnapshot({
|
const snapshot = buildUsageHttpErrorSnapshot({
|
||||||
provider: "openai-codex",
|
provider: "openai-codex",
|
||||||
|
|
@ -35,4 +44,14 @@ describe("provider usage fetch shared helpers", () => {
|
||||||
|
|
||||||
expect(snapshot.error).toBe("HTTP 403: missing scope");
|
expect(snapshot.error).toBe("HTTP 403: missing scope");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("omits empty HTTP error message suffixes", () => {
|
||||||
|
const snapshot = buildUsageHttpErrorSnapshot({
|
||||||
|
provider: "anthropic",
|
||||||
|
status: 429,
|
||||||
|
message: " ",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(snapshot.error).toBe("HTTP 429");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue