import { describe, expect, it } from 'vitest'; import { loadConfig } from '../src/config.js'; const base = { MONGO_URL: 'mongodb://localhost/fuegos', CONFIG_FILE: '/nonexistent.json' }; describe('loadConfig', () => { it('defaults to the safest mode (dry-run) with no channels owned', () => { const cfg = loadConfig({ ...base } as NodeJS.ProcessEnv); expect(cfg.mode).toBe('dry-run'); expect(cfg.ownedChannels).toEqual([]); expect(cfg.killSwitch).toBe(false); }); it('requires MONGO_URL', () => { expect(() => loadConfig({ CONFIG_FILE: '/nonexistent.json' } as NodeJS.ProcessEnv)).toThrow(/MONGO_URL/); }); it('rejects an invalid mode', () => { expect(() => loadConfig({ ...base, MODE: 'nuke' } as NodeJS.ProcessEnv)).toThrow(/Invalid MODE/); }); it('parses OWNED_CHANNELS and rejects unknown channels', () => { expect(loadConfig({ ...base, OWNED_CHANNELS: 'fcm,email' } as NodeJS.ProcessEnv).ownedChannels).toEqual(['fcm', 'email']); expect(() => loadConfig({ ...base, OWNED_CHANNELS: 'fcm,telegram' } as NodeJS.ProcessEnv)).toThrow(/Invalid channel/); }); it('parses KILL_SWITCH and canary lists', () => { const cfg = loadConfig({ ...base, KILL_SWITCH: '1', CANARY_USER_IDS: 'a, b ,c', MODE: 'canary' } as NodeJS.ProcessEnv); expect(cfg.killSwitch).toBe(true); expect(cfg.canary.userIds).toEqual(['a', 'b', 'c']); }); });