import logging
from flask_pii_logger import logger, PIIRedactor, REDACTED

def test_init(app):
    with app.app_context():
        logger.init(app, level=logging.INFO)  # no log_file in tests
        assert logger._logger is not None

def test_sensitive_key_redacted():
    assert PIIRedactor.redact("abc123", key="password") == REDACTED

def test_iban_redacted():
    result = PIIRedactor.redact_text("My IBAN is GB29NWBK60161331926819")
    assert REDACTED in result

def test_card_redacted():
    result = PIIRedactor.redact_text("Card: 4111 1111 1111 1111")
    assert REDACTED in result

def test_nested_dict_redacted():
    data = {"user": {"password": "secret", "name": "Alice"}}
    result = PIIRedactor.redact(data)
    assert result["user"]["password"] == REDACTED
    assert result["user"]["name"] == "Alice"