/** * Tests for the AI Intent Router */ const { routeIntent } = require('../../routes/ai-intent'); describe('AI Intent Router', () => { describe('deploy intents', () => { test('detects "deploy plex"', () => { const result = routeIntent('Deploy Plex'); expect(result.intent).toBe('deploy'); expect(result.appId).toBe('plex'); }); test('detects "set up nextcloud"', () => { const result = routeIntent('Set up Nextcloud'); expect(result.intent).toBe('deploy'); expect(result.appId).toBe('nextcloud'); }); test('detects "install gitea"', () => { const result = routeIntent('Can you install Gitea for me?'); expect(result.intent).toBe('deploy'); expect(result.appId).toBe('gitea'); }); test('includes deploy info', () => { const result = routeIntent('Deploy Plex'); expect(result.appId).toBe('plex'); expect(result.action).toBe('dashcaddy_deploy_app'); }); }); describe('recommend intents', () => { test('media streaming → recommends Plex', () => { const result = routeIntent('I want to stream movies'); expect(result.intent).toBe('recommend'); expect(result.categories).toContain('media-streaming'); }); test('password manager → recommends Vaultwarden', () => { const result = routeIntent('I need a password manager'); expect(result.intent).toBe('recommend'); expect(result.response.recommendations[0].app).toBe('vaultwarden'); }); test('ad blocking → recommends AdGuard', () => { const result = routeIntent('Block ads on my network'); expect(result.intent).toBe('recommend'); expect(result.response.recommendations[0].app).toBe('adguard'); }); test('includes categories for wizard', () => { const result = routeIntent('I want to stream movies'); expect(result.categories).toContain('media-streaming'); expect(result.action).toBe('dashcaddy_wizard_recommend'); }); }); describe('diagnose intents', () => { test('detects "why is plex down"', () => { const result = routeIntent('Why is Plex down?'); expect(result.intent).toBe('diagnose'); expect(result.serviceId).toBe('plex'); }); test('detects "something is broken"', () => { const result = routeIntent('Something is broken with my services'); expect(result.intent).toBe('diagnose'); }); }); describe('backup intents', () => { test('detects "back up everything"', () => { const result = routeIntent('Back up everything'); expect(result.intent).toBe('backup'); }); test('detects "create a snapshot"', () => { const result = routeIntent('Create a snapshot'); expect(result.intent).toBe('backup'); }); }); describe('health intents', () => { test('detects "is everything ok?"', () => { const result = routeIntent('Is everything OK?'); expect(result.intent).toBe('health'); }); test('detects "system check"', () => { const result = routeIntent('Run a system check'); expect(result.intent).toBe('health'); }); }); describe('list intents', () => { test('detects "what services am I running?"', () => { const result = routeIntent('What services am I running?'); expect(result.intent).toBe('list'); }); test('detects "show me everything"', () => { const result = routeIntent('Show me everything that\'s deployed'); expect(result.intent).toBe('list'); }); }); describe('unknown intents', () => { test('returns fallback for unrecognized input', () => { const result = routeIntent('xyz random gibberish 123'); expect(result.intent).toBe('unknown'); expect(result.response.suggestions).toBeTruthy(); expect(result.response.suggestions.length).toBeGreaterThan(0); }); test('fallback includes example queries', () => { const result = routeIntent('hello world'); expect(result.response.suggestions.some(s => s.includes('Deploy'))).toBe(true); }); }); });