test: add fetch mock helper and reaction coverage

This commit is contained in:
Sebastian
2026-02-17 09:01:30 -05:00
parent 0e023e300e
commit cc359d338e
28 changed files with 193 additions and 106 deletions

View File

@@ -1,6 +1,7 @@
import net from "node:net";
import { describe, expect, it, vi } from "vitest";
import { CHUTES_TOKEN_ENDPOINT, CHUTES_USERINFO_ENDPOINT } from "../agents/chutes-oauth.js";
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
import { loginChutes } from "./chutes-oauth.js";
async function getFreePort(): Promise<number> {
@@ -32,7 +33,7 @@ function createOAuthFetchFn(params: {
username: string;
passthrough?: boolean;
}): typeof fetch {
return async (input, init) => {
return withFetchPreconnect(async (input, init) => {
const url = urlToString(input);
if (url === CHUTES_TOKEN_ENDPOINT) {
return new Response(
@@ -54,7 +55,7 @@ function createOAuthFetchFn(params: {
return fetch(input, init);
}
return new Response("not found", { status: 404 });
};
});
}
describe("loginChutes", () => {
@@ -157,7 +158,7 @@ describe("loginChutes", () => {
});
it("rejects pasted redirect URLs missing state", async () => {
const fetchFn: typeof fetch = async () => new Response("not found", { status: 404 });
const fetchFn = withFetchPreconnect(async () => new Response("not found", { status: 404 }));
await expect(
loginChutes({