// Risk Rules Engine Tests

import { riskRulesEngine } from '../rules-engine.service';

describe('RiskRulesEngine', () => {
  describe('assessRisk', () => {
    it('should assess risk for a transaction', async () => {
      const request = {
        userId: 'user-123',
        amount: '1000.00',
        currencyCode: 'USD',
        deviceFingerprint: 'abc123',
        velocityData: {
          count24h: 5,
        },
      };

      const result = await riskRulesEngine.assessRisk(request);

      expect(result).toBeDefined();
      expect(result.riskScore).toBeGreaterThanOrEqual(0);
      expect(result.riskScore).toBeLessThanOrEqual(100);
      expect(['allow', 'block', 'flag', 'require_verification']).toContain(result.decision);
      expect(result.matchedRules).toBeDefined();
      expect(result.signals).toBeDefined();
    });

    it('should detect high velocity', async () => {
      const request = {
        userId: 'user-123',
        amount: '1000.00',
        currencyCode: 'USD',
        velocityData: {
          count24h: 25, // Above threshold
        },
      };

      const result = await riskRulesEngine.assessRisk(request);

      expect(result.riskScore).toBeGreaterThan(50);
      expect(result.signals.some(s => s.type === 'velocity')).toBe(true);
    });

    it('should detect high amount transactions', async () => {
      const request = {
        userId: 'user-123',
        amount: '15000.00', // Above threshold
        currencyCode: 'USD',
      };

      const result = await riskRulesEngine.assessRisk(request);

      expect(result.signals.length).toBeGreaterThan(0);
    });
  });
});
