test(oauth): restoring mocked global

This commit is contained in:
Elliott de Launay 2026-04-24 09:52:50 -04:00
parent 4f62b4043f
commit dab4e2cece
No known key found for this signature in database
GPG key ID: BB899BED766D1806

View file

@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from "vitest" import { describe, it, expect, vi, beforeEach, afterAll } from "vitest"
// Mock the SDK's discoverOAuthProtectedResourceMetadata // Mock the SDK's discoverOAuthProtectedResourceMetadata
vi.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({ vi.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
@ -9,6 +9,7 @@ import { discoverOAuthProtectedResourceMetadata } from "@modelcontextprotocol/sd
import { fetchOAuthAuthServerMetadata } from "../oauth" import { fetchOAuthAuthServerMetadata } from "../oauth"
const mockFetch = vi.fn() const mockFetch = vi.fn()
const originalFetch = global.fetch
global.fetch = mockFetch global.fetch = mockFetch
describe("fetchOAuthAuthServerMetadata", () => { describe("fetchOAuthAuthServerMetadata", () => {
@ -16,6 +17,10 @@ describe("fetchOAuthAuthServerMetadata", () => {
vi.clearAllMocks() vi.clearAllMocks()
}) })
afterAll(() => {
global.fetch = originalFetch
})
it("returns null when resource metadata has no authorization_servers", async () => { it("returns null when resource metadata has no authorization_servers", async () => {
;(discoverOAuthProtectedResourceMetadata as any).mockResolvedValue({ ;(discoverOAuthProtectedResourceMetadata as any).mockResolvedValue({
resource: "https://example.com/", resource: "https://example.com/",