import os
os.environ['DB_ENV'] = 'test'
os.environ['USE_MONGODB'] = 'true'
os.environ['MONGO_URI'] = 'mongomock'
os.environ.setdefault('SECRET_KEY', 'test-secret-key')
os.environ.setdefault('REFRESH_TOKEN_EXPIRY_DAYS', '90')
os.environ.setdefault('DIGEST_TOKEN_SECRET', 'test-digest-secret')
os.environ.setdefault('VAPID_PUBLIC_KEY', 'test-vapid-public-key')
os.environ.setdefault('VAPID_PRIVATE_KEY', 'test-vapid-private-key')
import sys
import pytest

# Ensure backend root is in sys.path for imports like 'config.paths'
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# Shared test constants — import these in test files instead of hardcoding
TEST_SECRET_KEY = 'test-secret-key'
TEST_REFRESH_TOKEN_EXPIRY_DAYS = 90

@pytest.fixture(scope="session", autouse=True)
def set_test_db_env():
    os.environ['DB_ENV'] = 'test'
    os.environ['USE_MONGODB'] = 'true'
    os.environ['MONGO_URI'] = 'mongomock'
    os.environ['SECRET_KEY'] = TEST_SECRET_KEY
    os.environ['REFRESH_TOKEN_EXPIRY_DAYS'] = str(TEST_REFRESH_TOKEN_EXPIRY_DAYS)
    # Ensure indexes are created once for the test session.  This is safe to
    # call repeatedly because MongoDB treats index creation as idempotent.
    from db.db import ensure_mongodb_indexes
    ensure_mongodb_indexes()
