"""Characterization tests for the employee directory endpoints.

Written before extracting employees into a plugin. The wjf_employees DB is not
available under test, so these assert the DB-independent behaviors: validation
(400) and graceful failure (500 envelope, not an unhandled crash) when the
directory is unreachable. Behavior must be identical as a plugin blueprint.
"""


def test_search_requires_min_query(client, db):
    """A too-short query is rejected before touching the directory DB."""
    resp = client.get('/api/employees/search?q=a')
    assert resp.status_code == 400


def test_lookup_requires_numeric_sso(client, db):
    """Non-numeric SSO is rejected without touching the directory DB."""
    resp = client.get('/api/employees/lookup/abc')
    assert resp.status_code == 400


def test_search_degrades_when_directory_unreachable(client, db):
    """With the directory DB unavailable, search returns a clean 500 envelope."""
    resp = client.get('/api/employees/search?q=smith')
    assert resp.status_code == 500
    assert resp.get_json()['status'] == 'error'
