import { describe, expect, it } from 'bun:test';
import { generateCachePrefix, normalizeServiceName } from '../src/service-utils';

describe('ServiceCache Integration', () => {
  // Since ServiceCache depends on external createCache, we'll test the utility functions it uses

  describe('generateCachePrefix usage', () => {
    it('should generate correct cache prefix for service', () => {
      const prefix = generateCachePrefix('userService');
      expect(prefix).toBe('cache:user-service');
    });

    it('should handle global cache prefix', () => {
      // This simulates what ServiceCache does for global cache
      const globalPrefix = 'stock-bot:shared';
      expect(globalPrefix).toBe('stock-bot:shared');
    });
  });

  describe('cache key patterns', () => {
    it('should follow correct key pattern for job results', () => {
      const jobId = 'job-123';
      const expectedKey = `job:result:${jobId}`;
      expect(expectedKey).toBe('job:result:job-123');
    });

    it('should follow correct key pattern for operation metrics', () => {
      const handler = 'test-handler';
      const operation = 'test-op';
      const expectedKey = `metrics:${handler}:${operation}`;
      expect(expectedKey).toBe('metrics:test-handler:test-op');
    });

    it('should follow correct key pattern for service health', () => {
      const serviceName = 'test-service';
      const expectedKey = `health:${serviceName}`;
      expect(expectedKey).toBe('health:test-service');
    });

    it('should follow correct key pattern for queue stats', () => {
      const queueName = 'test-queue';
      const expectedKey = `queue:stats:${queueName}`;
      expect(expectedKey).toBe('queue:stats:test-queue');
    });
  });

  describe('service name normalization', () => {
    it('should normalize service names in cache prefix', () => {
      const serviceName = 'UserService';
      const normalized = normalizeServiceName(serviceName);
      expect(normalized).toBe('user-service');

      const prefix = generateCachePrefix(normalized);
      expect(prefix).toBe('cache:user-service');
    });
  });
});
