| 1 | import { |
| 2 | getApiKeyValidationError, |
| 3 | isValidAnthropicApiKey, |
| 4 | } from "./util/apiKeyValidation.js"; |
| 5 | |
| 6 | describe("Free Trial Transition API Key Validation", () => { |
| 7 | it("should validate API keys properly for free trial transition", () => { |
| 8 | // Valid API keys |
| 9 | expect(isValidAnthropicApiKey("sk-ant-1234567890")).toBe(true); |
| 10 | expect( |
| 11 | isValidAnthropicApiKey("sk-ant-api03_T3BlbkFJ1234567890abcdef"), |
| 12 | ).toBe(true); |
| 13 | |
| 14 | // Invalid API keys |
| 15 | expect(isValidAnthropicApiKey("TEST-")).toBe(false); |
| 16 | expect(isValidAnthropicApiKey("sk-ant-")).toBe(false); |
| 17 | expect(isValidAnthropicApiKey("TEST-openai-1234")).toBe(false); |
| 18 | expect(isValidAnthropicApiKey("")).toBe(false); |
| 19 | expect(isValidAnthropicApiKey(null)).toBe(false); |
| 20 | expect(isValidAnthropicApiKey(undefined)).toBe(false); |
| 21 | }); |
| 22 | |
| 23 | it("should provide helpful error messages for invalid API keys", () => { |
| 24 | expect(getApiKeyValidationError("")).toBe("API key is required"); |
| 25 | expect(getApiKeyValidationError(null)).toBe("API key is required"); |
| 26 | expect(getApiKeyValidationError(undefined)).toBe("API key is required"); |
| 27 | expect(getApiKeyValidationError("TEST-")).toBe( |
| 28 | 'API key must start with "sk-ant-"', |
| 29 | ); |
| 30 | expect(getApiKeyValidationError("TEST-openai-1234")).toBe( |
| 31 | 'API key must start with "sk-ant-"', |
| 32 | ); |
| 33 | expect(getApiKeyValidationError("sk-ant-")).toBe("API key is too short"); |
| 34 | expect(getApiKeyValidationError("invalid")).toBe( |
| 35 | 'API key must start with "sk-ant-"', |
| 36 | ); |
| 37 | }); |
| 38 | }); |