import { describe, it, expect, beforeEach, vi } from 'vitest'
import * as forumService from '../../services/forum'
import { Context } from '../../types/context'

describe('Forum Service', () => {
  const mockContext: Context = {
    user: {
      id: 'user-1',
      email: 'test@example.com',
      name: 'Test User',
      role: 'USER',
    },
  } as Context

  beforeEach(() => {
    vi.clearAllMocks()
  })

  describe('getForumCategories', () => {
    it('should return list of forum categories', async () => {
      const categories = await forumService.getForumCategories()
      expect(Array.isArray(categories)).toBe(true)
    })
  })

  describe('createForumPost', () => {
    it('should create a new forum post', async () => {
      const input = {
        categoryId: 'cat-1',
        title: 'Test Post',
        content: 'Test content',
      }

      const post = await forumService.createForumPost(mockContext, input)
      expect(post).toBeDefined()
      expect(post.title).toBe(input.title)
      expect(post.content).toBe(input.content)
    })

    it('should throw error if user is not authenticated', async () => {
      const unauthenticatedContext = {} as Context
      const input = {
        categoryId: 'cat-1',
        title: 'Test Post',
        content: 'Test content',
      }

      await expect(
        forumService.createForumPost(unauthenticatedContext, input)
      ).rejects.toThrow('Authentication required')
    })
  })
})

