"""Functional tests for statement reserves.""" from moneyhub.constants.constants import StatementPeriodStatus from tests.functional.conftest import insert_mock_data def test_get_statement_reserves_by_account_id(fixture_client): """Test getting statement reserves by an account.""" account_id = 24601 statement_period_id = 124 insert_mock_data({ 'account': {'account_id': account_id}, 'statement_period': [ { 'statement_period_id': statement_period_id - 1, 'statement_period_name': 'Taken', 'statement_period_status': StatementPeriodStatus.CLOSED, }, { 'statement_period_id': statement_period_id, 'statement_period_name': 'Middle', 'statement_period_status': StatementPeriodStatus.CLOSED, }, { 'statement_period_id': statement_period_id + 1, 'statement_period_name': 'Released', 'statement_period_status': StatementPeriodStatus.CLOSED, }, ], 'abacus_event': [ {'abacus_event_id': 1}, {'abacus_event_id': 2}, { 'abacus_event_id': 3, 'statement_period_id': statement_period_id, 'target_type': 'statement_period', 'event_name': 'release_reserves', }, { 'abacus_event_id': 4, 'statement_period_id': statement_period_id, 'target_type': 'accounting_run', 'event_name': 'take_reserves', }, ], 'run_controller': {'run_controller_id': 1}, 'accounting_period': { 'accounting_period_id': 1, 'statement_period_id': statement_period_id - 1, }, 'accounting_run': { 'accounting_run_id': 1, 'accounting_period_id': 1, 'run_controller_id': 1, }, 'reference_payment_entity': {'reference_payment_entity_id': 1}, 'reference_sap_profit_center': { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC' }, 'reference_signing_entity': { 'reference_signing_entity_id': 1, 'reference_payment_entity_id': 1, 'reference_sap_profit_center_id': 1, 'company_code': '1234', 'tax_entity_company_code': '1234', 'legal_name': 'Company', 'vat_number': '12341234', 'company_registration_number': '12341234', 'address': None, }, 'contract': { 'contract_id': 1001, 'reference_signing_entity_id': 1, }, 'contract_reserve': { 'contract_reserve_id': 1, 'contract_id': 1001, }, 'ledger_account_contract': [ { 'ledger_account_contract_id': 1, 'abacus_event_id': 3, 'account_id': account_id, 'contract_id': 1001, 'currency_code': 'GBP', 'currency_amount': 1000.0, 'previous_balance': 0, 'current_balance': 1000.0, }, { 'ledger_account_contract_id': 2, 'abacus_event_id': 4, 'account_id': account_id, 'contract_id': 1001, 'currency_code': 'GBP', 'currency_amount': 100.0, 'previous_balance': 1000.0, 'current_balance': 900.0, } ], 'ledger_reserve_taken': { 'ledger_reserve_taken_id': 1, 'statement_period_id': statement_period_id - 1, 'abacus_event_id': 3, 'contract_reserve_id': 1, 'accounting_run_id': 1, }, 'ledger_reserve_release_schedule': [ { 'ledger_reserve_release_schedule_id': 1, 'abacus_event_id': 1, 'account_id': account_id, 'taken_statement_period_id': statement_period_id - 1, 'release_statement_period_id': statement_period_id, 'ledger_reserve_taken_id': 1, 'currency_code': 'USD', 'installment_amount': -100, 'outstanding_amount_after_installment': 100, }, { 'ledger_reserve_release_schedule_id': 2, 'abacus_event_id': 2, 'account_id': account_id, 'taken_statement_period_id': statement_period_id - 1, 'release_statement_period_id': statement_period_id + 1, 'ledger_reserve_taken_id': 1, 'currency_code': 'USD', 'installment_amount': -200, 'outstanding_amount_after_installment': 0, }, ], 'ledger_reserve_release': { 'ledger_reserve_release_id': 1, 'ledger_reserve_release_schedule_id': 1, 'abacus_event_id': 1, 'statement_period_id': statement_period_id, 'installment_amount': 100, } }) result = fixture_client.get( f'/statement-reserves/account/{account_id}/statement-period/{statement_period_id}') assert result.status_code == 200 assert result.json() == { 'ledger_reserve_release_total': 1000.00, 'ledger_reserve_taken_total': 100.00, 'ledger_reserve_total': 1100.00, } def test_get_statement_reserves_by_account_id_no_data(fixture_client): """Test getting statement reserves by an account when there is no data.""" account_id = 24601 statement_period_id = 123 result = fixture_client.get( f'/statement-reserves/account/{account_id}/statement-period/{statement_period_id}') assert result.status_code == 200 assert result.json() is None