openpondai/agents/news-bot
OpenTool app
typescript
import { afterEach, describe, expect, mock, test } from "bun:test";
import { resolveRuntimeConfig } from "./config";
import { resolveExecutableMarketSymbol } from "./market-symbol";
const originalFetch = globalThis.fetch;
afterEach(() => {
globalThis.fetch = originalFetch;
});
describe("resolveExecutableMarketSymbol", () => {
test("returns explicit marketSymbol without gateway lookup", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
asset: "OIL",
marketSymbol: "flx:OIL",
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("flx:OIL");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("returns explicit spot pair symbols without gateway lookup", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
mode: "event",
query: "alt season",
asset: "HYPE",
marketSymbol: "HYPE-USDC",
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("HYPE-USDC");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("falls back to execution symbol before asset", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
mode: "event",
query: "alt season",
asset: "HYPE",
execution: {
enabled: false,
symbol: "HYPE/USDC",
},
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("HYPE/USDC");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("falls back to the bare asset as a perp symbol", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
mode: "event",
query: "btc breakout",
asset: "btc",
});
await expect(resolveExecutableMarketSymbol(config)).resolves.toBe("BTC");
expect(fetchSpy).not.toHaveBeenCalled();
});
test("rejects raw Hyperliquid spot ids", async () => {
const fetchSpy = mock(() => {
throw new Error("fetch should not be called");
}) as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
const config = resolveRuntimeConfig({
mode: "event",
query: "alt season",
asset: "HYPE",
execution: {
enabled: false,
symbol: "@107",
},
});
await expect(resolveExecutableMarketSymbol(config)).rejects.toThrow(
"Do not use @index spot ids",
);
expect(fetchSpy).not.toHaveBeenCalled();
});
});