import { describe, it, expect } from 'vitest'
import { canAccessOps, filterNavLinks, isDashboardRole, roleCanAccessRoute, MAIN_NAV_LINKS } from '@/composables/roleAccess'

describe('roleAccess', () => {
  it('filtersNavLinksByRole', () => {
    const nurseLinks = filterNavLinks(MAIN_NAV_LINKS, 'NURSE')
    expect(nurseLinks.some((l) => l.to === '/analytics/alerts')).toBe(true)
    expect(nurseLinks.some((l) => l.to === '/alerts')).toBe(true)

    const physicianLinks = filterNavLinks(MAIN_NAV_LINKS, 'PHYSICIAN')
    expect(physicianLinks.some((l) => l.to === '/analytics/alerts')).toBe(true)
  })

  it('rejectsIntegrationDashboardRole', () => {
    expect(isDashboardRole('INTEGRATION')).toBe(false)
    expect(isDashboardRole('NURSE')).toBe(true)
  })

  it('guardsRoutesByAllowedRoles', () => {
    expect(roleCanAccessRoute('NURSE', { allowedRoles: ['PHYSICIAN', 'ADMIN'] })).toBe(false)
    expect(roleCanAccessRoute('ADMIN', { allowedRoles: ['ADMIN'] })).toBe(true)
    expect(roleCanAccessRoute('INTEGRATION', { allowedRoles: ['NURSE'] })).toBe(false)
  })

  it('restrictsOpsAccessToAdminByDefault', () => {
    expect(canAccessOps('ADMIN')).toBe(true)
    expect(canAccessOps('NURSE')).toBe(false)
    expect(canAccessOps('PHYSICIAN')).toBe(false)
    expect(canAccessOps('INTEGRATION')).toBe(false)
  })
})
