// Policy Engine Service Tests

import { policyEngineService } from '../policy/policy-engine.service';
import { CapabilityState } from '@/shared/solacenet/types';

describe('PolicyEngineService', () => {
  describe('decide', () => {
    it('should deny if capability is disabled', async () => {
      const decision = await policyEngineService.decide({
        tenantId: 'test-tenant',
        capabilityId: 'disabled-capability',
        region: 'US',
        channel: 'API',
      });

      expect(decision.allowed).toBe(false);
      expect(decision.mode).toBe(CapabilityState.DISABLED);
    });

    it('should allow if capability is enabled and no rules block', async () => {
      // This test requires a capability to be created and enabled first
      // In a real test, you'd set up the test data
      const decision = await policyEngineService.decide({
        tenantId: 'test-tenant',
        capabilityId: 'enabled-capability',
        region: 'US',
        channel: 'API',
      });

      // Result depends on actual capability state
      expect(decision).toBeDefined();
      expect(decision.decisionId).toBeDefined();
    });
  });

  describe('activateKillSwitch', () => {
    it('should activate kill switch and invalidate cache', async () => {
      await expect(
        policyEngineService.activateKillSwitch('test-capability', 'Test reason')
      ).resolves.not.toThrow();
    });
  });
});
