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

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

  describe('getFeed', () => {
    it('should return social feed', async () => {
      const result = await socialService.getFeed();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('posts');
      expect(Array.isArray(result.posts)).toBe(true);
      if (result.posts.length > 0) {
        expect(result.posts[0]).toHaveProperty('id');
        expect(result.posts[0]).toHaveProperty('author');
        expect(result.posts[0]).toHaveProperty('content');
      }
    });

    it('should handle pagination', async () => {
      const result = await socialService.getFeed({ page: 2, limit: 10 });

      expect(result).toBeDefined();
      expect(result).toHaveProperty('posts');
    });
  });

  describe('createPost', () => {
    it('should create a new post', async () => {
      const result = await socialService.createPost({
        content: 'Test post',
      });

      expect(result).toBeDefined();
      expect(result).toHaveProperty('post');
      expect(result.post).toHaveProperty('id');
      expect(result.post.content).toBe('Test post');
    });
  });

  describe('getComments', () => {
    it('should return comments for a track', async () => {
      const result = await socialService.getComments('track-1');

      expect(result).toBeDefined();
      expect(result).toHaveProperty('comments');
      expect(Array.isArray(result.comments)).toBe(true);
    });
  });

  describe('postComment', () => {
    it('should post a comment', async () => {
      const result = await socialService.postComment('track-1', 'Great track!');

      expect(result).toBeDefined();
      expect(result).toHaveProperty('id');
      expect(result).toHaveProperty('content');
      expect(result.content).toBe('Great track!');
    });
  });

  describe('deleteComment', () => {
    it('should delete a comment', async () => {
      const result = await socialService.deleteComment('comment-1');

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

  describe('getNotifications', () => {
    it('should return notifications', async () => {
      const result = await socialService.getNotifications();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('notifications');
      expect(Array.isArray(result.notifications)).toBe(true);
      if (result.notifications.length > 0) {
        expect(result.notifications[0]).toHaveProperty('id');
        expect(result.notifications[0]).toHaveProperty('type');
        expect(result.notifications[0]).toHaveProperty('text');
      }
    });
  });

  describe('markRead', () => {
    it('should mark notification as read', async () => {
      const result = await socialService.markRead();

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

  describe('markAllRead', () => {
    it('should mark all notifications as read', async () => {
      const result = await socialService.markAllRead();

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

  describe('getChatToken', () => {
    it('should return chat token', async () => {
      const result = await socialService.getChatToken();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('token');
    });
  });
});
