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

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

  describe('getUserXP', () => {
    it('should return user XP data', async () => {
      const xp = await gamificationService.getUserXP('user-1');

      expect(xp).toBeDefined();
      expect(xp).toHaveProperty('current');
      expect(xp).toHaveProperty('next');
      expect(xp).toHaveProperty('level');
      expect(xp).toHaveProperty('rank');
      expect(xp).toHaveProperty('totalEarned');
    });
  });

  describe('getAchievements', () => {
    it('should return user achievements', async () => {
      const achievements = await gamificationService.getAchievements('user-1');

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

  describe('getLeaderboard', () => {
    it('should return weekly leaderboard', async () => {
      const leaderboard = await gamificationService.getLeaderboard('weekly');

      expect(leaderboard).toBeDefined();
      expect(Array.isArray(leaderboard)).toBe(true);
      expect(leaderboard.length).toBeGreaterThan(0);
      expect(leaderboard[0]).toHaveProperty('rank');
      expect(leaderboard[0]).toHaveProperty('username');
      expect(leaderboard[0]).toHaveProperty('xp');
    });

    it('should return monthly leaderboard', async () => {
      const leaderboard = await gamificationService.getLeaderboard('monthly');

      expect(leaderboard).toBeDefined();
      expect(Array.isArray(leaderboard)).toBe(true);
    });

    it('should return all-time leaderboard', async () => {
      const leaderboard = await gamificationService.getLeaderboard('all');

      expect(leaderboard).toBeDefined();
      expect(Array.isArray(leaderboard)).toBe(true);
    });
  });

  describe('claimReward', () => {
    it('should claim an achievement reward', async () => {
      const result = await gamificationService.claimReward('achievement-1');

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