"""Test helpers for the prepaid credit ledger. Prepaid billing means an organization needs credit before engine work runs, so tests that exercise that work fund the organization first. ``fund_org`` writes the credit through the same repository the platform owner's endpoints use, so the wallet and its history are written the real way. """ from __future__ import annotations from sqlalchemy.ext.asyncio import async_sessionmaker from app.domain.billing.models import CreditKind, CreditTransaction from app.infrastructure.repositories.credit import CreditLedgerRepository async def fund_org( session_factory: async_sessionmaker, organization_id: str, amount: float = 100.0 ) -> CreditTransaction: """Credit an organization's wallet by ``amount`` as a labelled adjustment.""" async with session_factory() as session: transaction = await CreditLedgerRepository(session).apply( organization_id=organization_id, amount=amount, kind=CreditKind.ADJUSTMENT, reason="test funding", ) await session.commit() return transaction