let alerts = require('./alerts')

describe('alerts', () => {
  test('creates and lists alerts correctly', () => {
    const c1 = {
      type: 'test_alert',
      reference_type: 'asset',
      reference_id: 1,
      severity: 'warning',
      title: 'Test Alert 1',
      message: 'This is a test alert for asset 1'
    };
    const c2 = {
      type: 'test_alert',
      reference_type: 'asset',
      reference_id: 2,
      severity: 'critical',
      title: 'Test Alert 2',
      message: 'This is a test alert for asset 2'
    };
    const result = alerts.scan([c1, c2], 1);
    expect(result.created.length).toBe(2);
    expect(result.openCount).toBeGreaterThanOrEqual(2);

    const list = alerts.listAlerts({ status: 'open', type: 'test_alert' });
    expect(list.length).toBeGreaterThanOrEqual(2);
    expect(list.some(a => a.reference_id === 1 && a.severity === 'warning')).toBe(true);
    expect(list.some(a => a.reference_id === 2 && a.severity === 'critical')).toBe(true);
  });
});
