"""Tests payment hold serialization.""" import datetime from abacus_common_logic.utils.dates import safe_format_date from marshmallow import ValidationError import pytest from abacus_account.constants.constants import DEFAULT_PAGE_LIMIT, DEFAULT_PAGE_OFFSET from abacus_account.schemas import PaymentHoldSchema from abacus_account.schemas.payment_hold import PaymentHoldListInputSchema def test_payment_hold_schema(): """Tests payment hold schema.""" mock_payment_hold_info = { 'payment_hold_id': 1, 'account_id': 1, 'is_on_hold': 1, 'start_date': datetime.date(2020, 4, 24), 'reason': 'Account was rude to me.', 'created_at': datetime.datetime.now(), 'created_by': 'test_user', 'last_modified': datetime.datetime.now(), 'last_modified_by': 'test_user' } result = PaymentHoldSchema().dump(mock_payment_hold_info) assert result['payment_hold_id'] == mock_payment_hold_info['payment_hold_id'] assert result['account_id'] == mock_payment_hold_info['account_id'] assert result['is_on_hold'] == mock_payment_hold_info['is_on_hold'] assert result['start_date'] == safe_format_date( mock_payment_hold_info['start_date']) assert result['reason'] == mock_payment_hold_info['reason'] assert result['created_at'] == mock_payment_hold_info['created_at'].strftime( '%Y-%m-%d') assert result['created_by'] == mock_payment_hold_info['created_by'] assert result['last_modified'] == mock_payment_hold_info['last_modified'].strftime( '%Y-%m-%d') assert result['last_modified_by'] == mock_payment_hold_info['last_modified_by'] def test_payment_hold_list_input_schema_defaults(): """Ensure default pagination values are applied.""" result = PaymentHoldListInputSchema().load({}) assert result['limit'] == DEFAULT_PAGE_LIMIT assert result['offset'] == DEFAULT_PAGE_OFFSET assert result.get('account_ids') is None def test_payment_hold_list_input_schema_validation_error(): """Validate errors when invalid payload is provided.""" with pytest.raises(ValidationError) as err: PaymentHoldListInputSchema().load( { 'limit': 0, 'offset': -1, 'account_ids': ['invalid'], } ) messages = err.value.messages assert 'limit' in messages assert 'offset' in messages assert 'account_ids' in messages