import { describe, it, expect } from 'vitest'
import { getDomain, BACKEND_URL, EMPTY_CONTROL, DOMAIN_OPTIONS, COLLECTION_OPTIONS } from '../components/helpers'

describe('getDomain', () => {
  it('extracts domain from control_id', () => {
    expect(getDomain('AUTH-001')).toBe('AUTH')
    expect(getDomain('NET-042')).toBe('NET')
    expect(getDomain('CRYPT-003')).toBe('CRYPT')
  })

  it('returns empty string for invalid control_id', () => {
    expect(getDomain('')).toBe('')
    expect(getDomain('NODASH')).toBe('NODASH')
  })
})

describe('BACKEND_URL', () => {
  it('points to canonical API proxy', () => {
    expect(BACKEND_URL).toBe('/api/sdk/v1/canonical')
  })
})

describe('EMPTY_CONTROL', () => {
  it('has required fields with default values', () => {
    expect(EMPTY_CONTROL.framework_id).toBe('bp_security_v1')
    expect(EMPTY_CONTROL.severity).toBe('medium')
    expect(EMPTY_CONTROL.release_state).toBe('draft')
    expect(EMPTY_CONTROL.tags).toEqual([])
    expect(EMPTY_CONTROL.requirements).toEqual([''])
    expect(EMPTY_CONTROL.test_procedure).toEqual([''])
    expect(EMPTY_CONTROL.evidence).toEqual([{ type: '', description: '' }])
    expect(EMPTY_CONTROL.open_anchors).toEqual([{ framework: '', ref: '', url: '' }])
  })
})

describe('DOMAIN_OPTIONS', () => {
  it('contains expected domains', () => {
    const values = DOMAIN_OPTIONS.map(d => d.value)
    expect(values).toContain('AUTH')
    expect(values).toContain('NET')
    expect(values).toContain('CRYPT')
    expect(values).toContain('AI')
    expect(values).toContain('COMP')
    expect(values.length).toBe(10)
  })
})

describe('COLLECTION_OPTIONS', () => {
  it('contains expected collections', () => {
    const values = COLLECTION_OPTIONS.map(c => c.value)
    expect(values).toContain('bp_compliance_ce')
    expect(values).toContain('bp_compliance_gesetze')
    expect(values).toContain('bp_compliance_datenschutz')
    expect(values.length).toBe(6)
  })
})
