chore: Fix types in tests 29/N.

This commit is contained in:
cpojer
2026-02-17 14:32:43 +09:00
parent 03e6acd051
commit ecf1c955a1
12 changed files with 67 additions and 35 deletions

View File

@@ -49,7 +49,7 @@ describe("fetchBrowserJson loopback auth", () => {
});
it("adds bearer auth for loopback absolute HTTP URLs", async () => {
const fetchMock = vi.fn(
const fetchMock = vi.fn<(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>>(
async () =>
new Response(JSON.stringify({ ok: true }), {
status: 200,
@@ -61,13 +61,13 @@ describe("fetchBrowserJson loopback auth", () => {
const res = await fetchBrowserJson<{ ok: boolean }>("http://127.0.0.1:18888/");
expect(res.ok).toBe(true);
const init = fetchMock.mock.calls[0]?.[1] as RequestInit;
const init = fetchMock.mock.calls[0]?.[1];
const headers = new Headers(init?.headers);
expect(headers.get("authorization")).toBe("Bearer loopback-token");
});
it("does not inject auth for non-loopback absolute URLs", async () => {
const fetchMock = vi.fn(
const fetchMock = vi.fn<(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>>(
async () =>
new Response(JSON.stringify({ ok: true }), {
status: 200,
@@ -78,13 +78,13 @@ describe("fetchBrowserJson loopback auth", () => {
await fetchBrowserJson<{ ok: boolean }>("http://example.com/");
const init = fetchMock.mock.calls[0]?.[1] as RequestInit;
const init = fetchMock.mock.calls[0]?.[1];
const headers = new Headers(init?.headers);
expect(headers.get("authorization")).toBeNull();
});
it("keeps caller-supplied auth header", async () => {
const fetchMock = vi.fn(
const fetchMock = vi.fn<(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>>(
async () =>
new Response(JSON.stringify({ ok: true }), {
status: 200,
@@ -99,7 +99,7 @@ describe("fetchBrowserJson loopback auth", () => {
},
});
const init = fetchMock.mock.calls[0]?.[1] as RequestInit;
const init = fetchMock.mock.calls[0]?.[1];
const headers = new Headers(init?.headers);
expect(headers.get("authorization")).toBe("Bearer caller-token");
});