UNPKG

tprompter

Version:
50 lines (49 loc) 2.38 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Container } from 'typedi'; import { AppConfig, DEFAULT_APP_CONFIG } from './AppConfig.js'; import { PersistentConfigRepository } from './PersistentConfigRepository.js'; describe(AppConfig.name, () => { let config; let repoMock = { getRawConfig: jest.fn(), saveRawConfig: jest.fn(), }; beforeEach(() => { Container.set(PersistentConfigRepository, repoMock); config = Container.get(AppConfig); config.resetConfig(); }); describe('setPersistentValue', () => { it('should save persistant value data', () => __awaiter(void 0, void 0, void 0, function* () { yield config.setPersistentValue('openAIApiKey', 'oai'); expect(repoMock.saveRawConfig).toHaveBeenCalledWith(expect.stringContaining('"openAIApiKey": "oai"')); })); }); describe('getConfig', () => { it('should return merged data (with default)', () => __awaiter(void 0, void 0, void 0, function* () { repoMock.getRawConfig.mockResolvedValue(JSON.stringify({ openAIApiKey: '123' })); yield config.loadPersistent(); yield config.applyCLIArguments({ quiet: true }); expect(config.getConfig()).toEqual({ openAIApiKey: '123', quiet: true, verbose: false, agentMaxTokens: DEFAULT_APP_CONFIG.agentMaxTokens, agentDefaultModel: DEFAULT_APP_CONFIG.agentDefaultModel, }); })); }); describe('getAvailableConfigKeys', () => { it('should return all keys', () => { expect(config.getAvailableConfigKeys().length).toBeGreaterThan(0); }); }); });