"""Tests for payment_hold model.""" from abacus_account.models.payment_hold import PaymentHold from tests.utils.factories import PaymentHoldFactory def test_get_payment_hold_by_id(fresh_db): """Test to get a payment hold by id.""" object_id = 11 assert len(PaymentHold.query.all()) == 0 payment_hold = PaymentHoldFactory.create(payment_hold_id=object_id) assert len(PaymentHold.query.all()) == 1 result = PaymentHold.get_by_id(object_id) assert result.payment_hold_id == payment_hold.payment_hold_id assert result.account_id == payment_hold.account_id def test_get_filtered_items_pagination(fresh_db): """Test retrieving payment holds with pagination.""" holds = [PaymentHoldFactory.create() for _ in range(5)] items, total_count = PaymentHold.get_filtered_items(2, 1) expected_ids = sorted([hold.payment_hold_id for hold in holds])[1:3] result_ids = sorted(item.payment_hold_id for item in items) assert len(items) == 2 assert total_count == len(holds) assert result_ids == expected_ids def test_get_filtered_items_account_filter(fresh_db): """Test filtering payment holds by account ids.""" PaymentHoldFactory.create(account__account_id=1) PaymentHoldFactory.create(account__account_id=2) PaymentHoldFactory.create(account__account_id=3) items, total_count = PaymentHold.get_filtered_items(10, 0, [1, 3]) result_account_ids = sorted(item.account_id for item in items) assert len(items) == 2 assert total_count == 2 assert result_account_ids == [1, 3]