2025-12-30 15:06:41 +09:00
|
|
|
import { describe, it, expect, spyOn, afterEach } from "bun:test"
|
|
|
|
|
import * as auth from "./auth"
|
|
|
|
|
|
|
|
|
|
describe("auth check", () => {
|
|
|
|
|
describe("getAuthProviderInfo", () => {
|
|
|
|
|
it("returns anthropic as always available", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given anthropic provider
|
|
|
|
|
// when getting info
|
2025-12-30 15:06:41 +09:00
|
|
|
const info = auth.getAuthProviderInfo("anthropic")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should show plugin installed (builtin)
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(info.id).toBe("anthropic")
|
|
|
|
|
expect(info.pluginInstalled).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns correct name for each provider", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given each provider
|
|
|
|
|
// when getting info
|
|
|
|
|
// then should have correct names
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(auth.getAuthProviderInfo("anthropic").name).toContain("Claude")
|
|
|
|
|
expect(auth.getAuthProviderInfo("openai").name).toContain("ChatGPT")
|
|
|
|
|
expect(auth.getAuthProviderInfo("google").name).toContain("Gemini")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("checkAuthProvider", () => {
|
|
|
|
|
let getInfoSpy: ReturnType<typeof spyOn>
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
getInfoSpy?.mockRestore()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns pass when plugin installed", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given plugin installed
|
2025-12-30 15:06:41 +09:00
|
|
|
getInfoSpy = spyOn(auth, "getAuthProviderInfo").mockReturnValue({
|
|
|
|
|
id: "anthropic",
|
|
|
|
|
name: "Anthropic (Claude)",
|
|
|
|
|
pluginInstalled: true,
|
|
|
|
|
configured: true,
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when checking
|
2025-12-30 15:06:41 +09:00
|
|
|
const result = await auth.checkAuthProvider("anthropic")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should pass
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(result.status).toBe("pass")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("returns skip when plugin not installed", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given plugin not installed
|
2025-12-30 15:06:41 +09:00
|
|
|
getInfoSpy = spyOn(auth, "getAuthProviderInfo").mockReturnValue({
|
|
|
|
|
id: "openai",
|
|
|
|
|
name: "OpenAI (ChatGPT)",
|
|
|
|
|
pluginInstalled: false,
|
|
|
|
|
configured: false,
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when checking
|
2025-12-30 15:06:41 +09:00
|
|
|
const result = await auth.checkAuthProvider("openai")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should skip
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(result.status).toBe("skip")
|
|
|
|
|
expect(result.message).toContain("not installed")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("checkAnthropicAuth", () => {
|
|
|
|
|
it("returns a check result", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
|
|
|
|
// when checking anthropic
|
2025-12-30 15:06:41 +09:00
|
|
|
const result = await auth.checkAnthropicAuth()
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should return valid result
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(result.name).toBeDefined()
|
|
|
|
|
expect(["pass", "fail", "warn", "skip"]).toContain(result.status)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("checkOpenAIAuth", () => {
|
|
|
|
|
it("returns a check result", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
|
|
|
|
// when checking openai
|
2025-12-30 15:06:41 +09:00
|
|
|
const result = await auth.checkOpenAIAuth()
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should return valid result
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(result.name).toBeDefined()
|
|
|
|
|
expect(["pass", "fail", "warn", "skip"]).toContain(result.status)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("checkGoogleAuth", () => {
|
|
|
|
|
it("returns a check result", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
|
|
|
|
// when checking google
|
2025-12-30 15:06:41 +09:00
|
|
|
const result = await auth.checkGoogleAuth()
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should return valid result
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(result.name).toBeDefined()
|
|
|
|
|
expect(["pass", "fail", "warn", "skip"]).toContain(result.status)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("getAuthCheckDefinitions", () => {
|
|
|
|
|
it("returns definitions for all three providers", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
|
|
|
|
// when getting definitions
|
2025-12-30 15:06:41 +09:00
|
|
|
const defs = auth.getAuthCheckDefinitions()
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should have 3 definitions
|
2025-12-30 15:06:41 +09:00
|
|
|
expect(defs.length).toBe(3)
|
|
|
|
|
expect(defs.every((d) => d.category === "authentication")).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|