// Expression Evaluator Tests

import { expressionEvaluator } from '../policy/expression-evaluator';

describe('ExpressionEvaluator', () => {
  describe('evaluate', () => {
    it('should evaluate simple equality', () => {
      const condition = {
        eq: { status: 'active' },
      };
      const context = { status: 'active' };

      const result = expressionEvaluator.evaluate(condition, context);
      expect(result).toBe(true);
    });

    it('should evaluate greater than', () => {
      const condition = {
        gt: { amount: 1000 },
      };
      const context = { amount: 1500 };

      const result = expressionEvaluator.evaluate(condition, context);
      expect(result).toBe(true);
    });

    it('should evaluate AND conditions', () => {
      const condition = {
        and: [
          { eq: { status: 'active' } },
          { gt: { amount: 1000 } },
        ],
      };
      const context = { status: 'active', amount: 1500 };

      const result = expressionEvaluator.evaluate(condition, context);
      expect(result).toBe(true);
    });

    it('should evaluate OR conditions', () => {
      const condition = {
        or: [
          { eq: { status: 'inactive' } },
          { gt: { amount: 1000 } },
        ],
      };
      const context = { status: 'active', amount: 1500 };

      const result = expressionEvaluator.evaluate(condition, context);
      expect(result).toBe(true);
    });

    it('should evaluate IN operator', () => {
      const condition = {
        in: { region: ['US', 'EU', 'APAC'] },
      };
      const context = { region: 'US' };

      const result = expressionEvaluator.evaluate(condition, context);
      expect(result).toBe(true);
    });

    it('should return false for non-matching conditions', () => {
      const condition = {
        eq: { status: 'active' },
      };
      const context = { status: 'inactive' };

      const result = expressionEvaluator.evaluate(condition, context);
      expect(result).toBe(false);
    });
  });
});
