import { expect, test } from "vitest" import { formatBearerCredential, isBearerCredential, parseBearerCredential, } from "#Source/credential/index.ts" test("isBearerCredential recognizes bearer credential strings", () => { expect(isBearerCredential("Bearer token-value")).toBe(true) expect(isBearerCredential("bearer token-value")).toBe(true) expect(isBearerCredential("Basic token-value")).toBe(false) expect(isBearerCredential("token-value")).toBe(false) }) test("formatBearerCredential prefixes a raw token with the Bearer scheme", () => { expect(formatBearerCredential("token-value")).toBe("Bearer token-value") expect(formatBearerCredential(" token-value ")).toBe("Bearer token-value") expect(() => formatBearerCredential(" ")).toThrow( "Expected token to contain at least one non-whitespace character", ) }) test("parseBearerCredential extracts the raw token only from bearer credentials", () => { expect(parseBearerCredential("Bearer token-value")).toBe("token-value") expect(parseBearerCredential("bearer token-value")).toBe("token-value") expect(parseBearerCredential("Basic token-value")).toBeUndefined() expect(parseBearerCredential(undefined)).toBeUndefined() })