import { describe, it, expect, vi, beforeEach } from 'vitest';
import { developerService } from './developerService';

describe('developerService', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  describe('listKeys', () => {
    it('should return list of API keys', async () => {
      const keys = await developerService.listKeys();

      expect(keys).toBeDefined();
      expect(Array.isArray(keys)).toBe(true);
      expect(keys.length).toBeGreaterThan(0);
      expect(keys[0]).toHaveProperty('id');
      expect(keys[0]).toHaveProperty('name');
      expect(keys[0]).toHaveProperty('prefix');
    });
  });

  describe('createKey', () => {
    it('should create a new API key', async () => {
      const newKey = await developerService.createKey({
        name: 'Test Key',
        scopes: ['read', 'write'],
      });

      expect(newKey).toBeDefined();
      expect(newKey.name).toBe('Test Key');
      expect(newKey.scopes).toEqual(['read', 'write']);
      expect(newKey.status).toBe('active');
      expect(newKey).toHaveProperty('id');
      expect(newKey).toHaveProperty('prefix');
    });
  });

  describe('revokeKey', () => {
    it('should revoke an API key', async () => {
      const result = await developerService.revokeKey('key-1');

      expect(result).toBeDefined();
      expect(result.success).toBe(true);
    });
  });

  describe('getStats', () => {
    it('should return developer statistics', async () => {
      const stats = await developerService.getStats();

      expect(stats).toBeDefined();
      expect(stats).toHaveProperty('requests_24h');
      expect(stats).toHaveProperty('avg_latency');
      expect(stats).toHaveProperty('active_keys');
    });
  });
});
