UNPKG

@elevenlabs/convai-cli

Version:

CLI tool to manage ElevenLabs conversational AI agents

164 lines 7.69 kB
"use strict"; /** * Tests for config management */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const os = __importStar(require("os")); const config_1 = require("../config"); const globals_1 = require("@jest/globals"); // Mock os module globals_1.jest.mock('os', () => ({ ...globals_1.jest.requireActual('os'), homedir: globals_1.jest.fn() })); const mockedOs = os; (0, globals_1.describe)('Config Management', () => { let tempDir; (0, globals_1.beforeEach)(async () => { // Create a temporary directory for config tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'convai-test-')); // Mock os.homedir to return our temp directory mockedOs.homedir.mockReturnValue(tempDir); }); (0, globals_1.afterEach)(async () => { // Clean up temp directory await fs.remove(tempDir); globals_1.jest.clearAllMocks(); }); (0, globals_1.describe)('loadConfig and saveConfig', () => { (0, globals_1.it)('should save and load config correctly', async () => { const config = { apiKey: 'test-key', defaultEnvironment: 'dev' }; await (0, config_1.saveConfig)(config); const loaded = await (0, config_1.loadConfig)(); // API key is not saved to config file for security (0, globals_1.expect)(loaded).toEqual({ defaultEnvironment: 'dev' }); }); (0, globals_1.it)('should return empty config if file does not exist', async () => { const config = await (0, config_1.loadConfig)(); (0, globals_1.expect)(config).toEqual({}); }); (0, globals_1.it)('should create config directory if it does not exist', async () => { const config = { apiKey: 'test' }; await (0, config_1.saveConfig)(config); const configPath = path.join(tempDir, '.convai', 'config.json'); const exists = await fs.pathExists(configPath); (0, globals_1.expect)(exists).toBe(true); }); }); (0, globals_1.describe)('API key management', () => { (0, globals_1.beforeEach)(() => { // Clear environment variable delete process.env.ELEVENLABS_API_KEY; }); (0, globals_1.it)('should set and get API key', async () => { await (0, config_1.setApiKey)('test-api-key'); const apiKey = await (0, config_1.getApiKey)(); (0, globals_1.expect)(apiKey).toBe('test-api-key'); }); (0, globals_1.it)('should remove API key', async () => { await (0, config_1.setApiKey)('test-api-key'); await (0, config_1.removeApiKey)(); const apiKey = await (0, config_1.getApiKey)(); (0, globals_1.expect)(apiKey).toBeUndefined(); }); (0, globals_1.it)('should prioritize environment variable over config file', async () => { await (0, config_1.setApiKey)('config-key'); process.env.ELEVENLABS_API_KEY = 'env-key'; const apiKey = await (0, config_1.getApiKey)(); (0, globals_1.expect)(apiKey).toBe('env-key'); }); (0, globals_1.it)('should check login status correctly', async () => { (0, globals_1.expect)(await (0, config_1.isLoggedIn)()).toBe(false); await (0, config_1.setApiKey)('test-key'); (0, globals_1.expect)(await (0, config_1.isLoggedIn)()).toBe(true); await (0, config_1.removeApiKey)(); (0, globals_1.expect)(await (0, config_1.isLoggedIn)()).toBe(false); }); }); (0, globals_1.describe)('Default environment management', () => { (0, globals_1.it)('should return prod as default environment', async () => { const env = await (0, config_1.getDefaultEnvironment)(); (0, globals_1.expect)(env).toBe('prod'); }); (0, globals_1.it)('should set and get default environment', async () => { await (0, config_1.setDefaultEnvironment)('dev'); const env = await (0, config_1.getDefaultEnvironment)(); (0, globals_1.expect)(env).toBe('dev'); }); }); (0, globals_1.describe)('Residency management', () => { (0, globals_1.it)('should return global as default residency', async () => { const residency = await (0, config_1.getResidency)(); (0, globals_1.expect)(residency).toBe('global'); }); (0, globals_1.it)('should set and get residency', async () => { await (0, config_1.setResidency)('eu-residency'); const residency = await (0, config_1.getResidency)(); (0, globals_1.expect)(residency).toBe('eu-residency'); }); (0, globals_1.it)('should handle all valid residency values', async () => { const validResidencies = ['us', 'eu-residency', 'in-residency', 'global']; for (const residencyValue of validResidencies) { await (0, config_1.setResidency)(residencyValue); const residency = await (0, config_1.getResidency)(); (0, globals_1.expect)(residency).toBe(residencyValue); } }); (0, globals_1.it)('should persist residency across config loads', async () => { await (0, config_1.setResidency)('in-residency'); // Load config again to ensure persistence const config = await (0, config_1.loadConfig)(); (0, globals_1.expect)(config.residency).toBe('in-residency'); const residency = await (0, config_1.getResidency)(); (0, globals_1.expect)(residency).toBe('in-residency'); }); (0, globals_1.it)('should save residency along with other config', async () => { await (0, config_1.setDefaultEnvironment)('staging'); await (0, config_1.setResidency)('eu-residency'); const config = await (0, config_1.loadConfig)(); (0, globals_1.expect)(config.defaultEnvironment).toBe('staging'); (0, globals_1.expect)(config.residency).toBe('eu-residency'); }); }); }); //# sourceMappingURL=config.test.js.map