import { describe, expect, it } from 'vitest'

import { canEditContent } from '@/lib/users'

import type { UserRole } from '@/types'

const userWithRole = (role: UserRole) => ({ role })

describe ('user permission helpers', () => {
  it ('allows admins and members to edit content', () => {
    expect (canEditContent (userWithRole ('admin'))).toBe (true)
    expect (canEditContent (userWithRole ('member'))).toBe (true)
  })

  it ('does not allow guests or missing users to edit content', () => {
    expect (canEditContent (userWithRole ('guest'))).toBe (false)
    expect (canEditContent (null)).toBe (false)
    expect (canEditContent (undefined)).toBe (false)
  })
})
