mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 17:51:24 +00:00
test: add fetch mock helper and reaction coverage
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user