import { describe, it, expect } from 'vitest'
import { roleLabel, ROLE_LABELS } from '../role-labels'

// KAR-787 / R53: curated German labels for role codes, replacing the
// duplicated hardcoded ALL_ROLES maps in the create/edit user modals.

describe('roleLabel (R53)', () => {
  it('returns the curated German label for a known code', () => {
    expect(roleLabel('consultant')).toBe('Berater')
    expect(roleLabel('readonly')).toBe('Nur Lesen')
    expect(roleLabel('masteradmin')).toBe('Masteradmin')
  })

  it('falls back to the DB-provided label for an unknown code', () => {
    expect(roleLabel('newrole', 'Neue Rolle')).toBe('Neue Rolle')
  })

  it('falls back to the raw code when nothing else is available', () => {
    expect(roleLabel('newrole')).toBe('newrole')
    expect(roleLabel('newrole', null)).toBe('newrole')
  })

  it('covers every code in the roles_code_check constraint', () => {
    for (const code of ['masteradmin', 'admin', 'consultant', 'readonly', 'extern']) {
      expect(ROLE_LABELS[code as keyof typeof ROLE_LABELS]).toBeTruthy()
    }
  })
})
