33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("@/server/lib/runtime-env", () => ({
|
|
getRequiredEnvValue: vi.fn(async () => "encoded-credentials"),
|
|
}));
|
|
|
|
import { dataforseoPost } from "@/server/lib/dataforseo/core";
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("DataForSEO transport", () => {
|
|
it("retries a transient 5xx on idempotent reads and returns the parsed envelope", async () => {
|
|
const fetchMock = vi
|
|
.fn<typeof fetch>()
|
|
.mockResolvedValueOnce(new Response("upstream failure", { status: 503 }))
|
|
.mockResolvedValueOnce(Response.json({ status_code: 20000, tasks: [] }));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
await expect(
|
|
dataforseoPost("/v3/backlinks/summary/live", []),
|
|
).resolves.toEqual({ status_code: 20000, tasks: [] });
|
|
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
|
|
const [url, init] = fetchMock.mock.calls[0];
|
|
expect(url).toBe("https://api.dataforseo.com/v3/backlinks/summary/live");
|
|
expect(new Headers(init?.headers).get("Authorization")).toBe(
|
|
"Basic encoded-credentials",
|
|
);
|
|
});
|
|
});
|