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

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

  describe('getSessions', () => {
    it('should return list of sessions', async () => {
      const result = await sessionService.getSessions();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('sessions');
      expect(Array.isArray(result.sessions)).toBe(true);
      expect(result.sessions.length).toBeGreaterThan(0);
      expect(result.sessions[0]).toHaveProperty('id');
      expect(result.sessions[0]).toHaveProperty('ip_address');
      expect(result.sessions[0]).toHaveProperty('user_agent');
    });
  });

  describe('logoutSession', () => {
    it('should logout current session', async () => {
      const result = await sessionService.logoutSession();

      expect(result).toBeDefined();
    });
  });

  describe('logoutAll', () => {
    it('should logout all sessions', async () => {
      const result = await sessionService.logoutAll();

      expect(result).toBeDefined();
    });
  });

  describe('revokeSession', () => {
    it('should revoke a specific session', async () => {
      const result = await sessionService.revokeSession('s1');

      expect(result).toBeDefined();
    });
  });

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

      expect(stats).toBeDefined();
      expect(stats).toHaveProperty('total_sessions');
      expect(stats).toHaveProperty('active_sessions');
    });
  });
});
