"""Main processor unit tests.""" from unittest.mock import patch from commit_ledger_account_contract.constants.constants import ( CONTRACT_ADVANCE_EVENT_MAP, CUSTOM_PAYMENT_EVENT_MAP, PAYMENT_GROUP_EVENT_MAP, ) from commit_ledger_account_contract.constants.errors import INVALID_EVENT_NAME from commit_ledger_account_contract.processor import CommitLedgerProcessor @patch('commit_ledger_account_contract.processor.app_logger') def test_process_invalid_event(mock_logger): """Test main process method when passed an invalid event.""" invalid_event = { 'event_name': 'invalid_event_name', 'event_id': 1, 'target_type': 'target_type', 'target_id': 123, } processor = CommitLedgerProcessor(invalid_event) res = processor.process() assert not res mock_logger.error.assert_called_once_with(INVALID_EVENT_NAME) @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitAdvancePayment') def test_process_commit_advance_payment( mock_commit_advance_payment, mock_logger, mock_commit_contract_advance_event ): """Test main process method when committing a contract_advance_payment.""" event_name = mock_commit_contract_advance_event['event_name'] processor = CommitLedgerProcessor(mock_commit_contract_advance_event) processor.process() mock_commit_advance_payment.assert_called_once_with( mock_commit_contract_advance_event['abacus_event_id'], CONTRACT_ADVANCE_EVENT_MAP[event_name], mock_commit_contract_advance_event['target_id'], ) mock_commit_advance_payment.return_value.commit_applied_contract_advance.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_contract_advance_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitVatSummary') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') def test_process_commit_vat_summary( mock_commit_payment_group, mock_commit_vat_summary, mock_logger, mock_commit_vat_summary_event, ): """Test main process method when committing a VAT summary.""" mock_commit_vat_summary.return_value.commit_vat_summary.return_value = None processor = CommitLedgerProcessor(mock_commit_vat_summary_event) processor.process() mock_commit_vat_summary.assert_called_once_with( mock_commit_vat_summary_event['abacus_event_id'], mock_commit_vat_summary_event['target_id'], ) mock_commit_vat_summary.return_value.commit_vat_summary.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_vat_summary_event}' ) mock_logger.error.assert_not_called() mock_commit_payment_group.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitAdvancePayment') def test_process_return_advance_payment( mock_commit_advance_payment, mock_logger, mock_return_advance_payment_event ): """Test main process method when returning a contract advance payment.""" event_name = mock_return_advance_payment_event['event_name'] processor = CommitLedgerProcessor(mock_return_advance_payment_event) processor.process() mock_commit_advance_payment.assert_called_once_with( mock_return_advance_payment_event['abacus_event_id'], CONTRACT_ADVANCE_EVENT_MAP[event_name], mock_return_advance_payment_event['target_id'], ) mock_commit_advance_payment.return_value.commit_applied_contract_advance.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_return_advance_payment_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') def test_process_commit_batch_payment( mock_commit_payment_group, mock_logger, mock_commit_batch_payment_event ): """Test main process method when committing a batch payment.""" event_name = mock_commit_batch_payment_event['event_name'] processor = CommitLedgerProcessor(mock_commit_batch_payment_event) processor.process() mock_commit_payment_group.assert_called_once_with( mock_commit_batch_payment_event['abacus_event_id'], PAYMENT_GROUP_EVENT_MAP[event_name]['ledger_event_type'], PAYMENT_GROUP_EVENT_MAP[event_name]['payment_group_type'], mock_commit_batch_payment_event['target_id'], ) mock_commit_payment_group.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_batch_payment_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') @patch('commit_ledger_account_contract.processor.CommitVatSummary') def test_process_commit_vat_summary_payment_group( mock_commit_vat_summary, mock_commit_payment_group, mock_logger, mock_commit_vat_summary_payment_group_event, ): """Test main process method when committing a VAT summary payment.""" event_name = mock_commit_vat_summary_payment_group_event['event_name'] processor = CommitLedgerProcessor(mock_commit_vat_summary_payment_group_event) processor.process() mock_commit_payment_group.assert_called_once_with( mock_commit_vat_summary_payment_group_event['abacus_event_id'], PAYMENT_GROUP_EVENT_MAP[event_name]['ledger_event_type'], PAYMENT_GROUP_EVENT_MAP[event_name]['payment_group_type'], mock_commit_vat_summary_payment_group_event['target_id'], ) mock_commit_payment_group.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_vat_summary_payment_group_event}' ) mock_logger.error.assert_not_called() mock_commit_vat_summary.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') def test_process_commit_wht_tax( mock_commit_payment_group, mock_logger, mock_commit_wht_tax_event ): """Test main process method when committing a withholding tax payment.""" event_name = mock_commit_wht_tax_event['event_name'] processor = CommitLedgerProcessor(mock_commit_wht_tax_event) processor.process() mock_commit_payment_group.assert_called_once_with( mock_commit_wht_tax_event['abacus_event_id'], PAYMENT_GROUP_EVENT_MAP[event_name]['ledger_event_type'], PAYMENT_GROUP_EVENT_MAP[event_name]['payment_group_type'], mock_commit_wht_tax_event['target_id'], ) mock_commit_payment_group.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with(f'Processing {mock_commit_wht_tax_event}') mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') def test_process_return_batch_payment( mock_commit_payment_group, mock_logger, mock_return_batch_payment_event ): """Test main process method when returning a batch payment.""" event_name = mock_return_batch_payment_event['event_name'] processor = CommitLedgerProcessor(mock_return_batch_payment_event) processor.process() mock_commit_payment_group.assert_called_once_with( mock_return_batch_payment_event['abacus_event_id'], PAYMENT_GROUP_EVENT_MAP[event_name]['ledger_event_type'], PAYMENT_GROUP_EVENT_MAP[event_name]['payment_group_type'], mock_return_batch_payment_event['target_id'], ) mock_commit_payment_group.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_return_batch_payment_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') def test_process_return_vat_summary( mock_commit_payment_group, mock_logger, mock_return_vat_summary_event ): """Test main process method when returning a VAT summary payment.""" event_name = mock_return_vat_summary_event['event_name'] processor = CommitLedgerProcessor(mock_return_vat_summary_event) processor.process() mock_commit_payment_group.assert_called_once_with( mock_return_vat_summary_event['abacus_event_id'], PAYMENT_GROUP_EVENT_MAP[event_name]['ledger_event_type'], PAYMENT_GROUP_EVENT_MAP[event_name]['payment_group_type'], mock_return_vat_summary_event['target_id'], ) mock_commit_payment_group.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_return_vat_summary_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitPaymentGroup') def test_process_return_wht_tax( mock_commit_payment_group, mock_logger, mock_return_wht_tax_event ): """Test main process method when returning a withholding tax payment.""" event_name = mock_return_wht_tax_event['event_name'] processor = CommitLedgerProcessor(mock_return_wht_tax_event) processor.process() mock_commit_payment_group.assert_called_once_with( mock_return_wht_tax_event['abacus_event_id'], PAYMENT_GROUP_EVENT_MAP[event_name]['ledger_event_type'], PAYMENT_GROUP_EVENT_MAP[event_name]['payment_group_type'], mock_return_wht_tax_event['target_id'], ) mock_commit_payment_group.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with(f'Processing {mock_return_wht_tax_event}') mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitCustomPayment') def test_process_commit_custom_payment( mock_commit_custom_payment, mock_logger, mock_commit_custom_payment_event ): """Test commit_custom_payment event processing.""" event_name = mock_commit_custom_payment_event['event_name'] processor = CommitLedgerProcessor(mock_commit_custom_payment_event) processor.process() mock_commit_custom_payment.assert_called_once_with( mock_commit_custom_payment_event['abacus_event_id'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['ledger_event_type'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['amount_type'], mock_commit_custom_payment_event['target_id'], ) mock_commit_custom_payment.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_custom_payment_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitCustomPayment') def test_process_return_custom_payment( mock_commit_custom_payment, mock_logger, mock_return_custom_payment_event ): """Test return_custom_payment event processing.""" event_name = mock_return_custom_payment_event['event_name'] processor = CommitLedgerProcessor(mock_return_custom_payment_event) processor.process() mock_commit_custom_payment.assert_called_once_with( mock_return_custom_payment_event['abacus_event_id'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['ledger_event_type'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['amount_type'], mock_return_custom_payment_event['target_id'], ) mock_commit_custom_payment.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_return_custom_payment_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitVatSummary') @patch('commit_ledger_account_contract.processor.CommitCustomPayment') def test_process_commit_vat_summary_custom_payment( mock_commit_custom_payment, mock_commit_vat_summary, mock_logger, mock_commit_vat_summary_custom_payment_event, ): """Test commit_vat_summary event processing.""" event_name = mock_commit_vat_summary_custom_payment_event['event_name'] processor = CommitLedgerProcessor(mock_commit_vat_summary_custom_payment_event) processor.process() mock_commit_custom_payment.assert_called_once_with( mock_commit_vat_summary_custom_payment_event['abacus_event_id'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['ledger_event_type'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['amount_type'], mock_commit_vat_summary_custom_payment_event['target_id'], ) mock_commit_custom_payment.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_vat_summary_custom_payment_event}' ) mock_logger.error.assert_not_called() mock_commit_vat_summary.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitVatSummary') @patch('commit_ledger_account_contract.processor.CommitCustomPayment') def test_process_return_vat_summary_custom_payment( mock_commit_custom_payment, mock_commit_vat_summary, mock_logger, mock_return_vat_summary_custom_payment_event, ): """Test return_vat_summary event processing.""" event_name = mock_return_vat_summary_custom_payment_event['event_name'] processor = CommitLedgerProcessor(mock_return_vat_summary_custom_payment_event) processor.process() mock_commit_custom_payment.assert_called_once_with( mock_return_vat_summary_custom_payment_event['abacus_event_id'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['ledger_event_type'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['amount_type'], mock_return_vat_summary_custom_payment_event['target_id'], ) mock_commit_custom_payment.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_return_vat_summary_custom_payment_event}' ) mock_logger.error.assert_not_called() mock_commit_vat_summary.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitCustomPayment') def test_process_commit_wht_custom_payment( mock_commit_custom_payment, mock_logger, mock_commit_wht_custom_payment_event ): """Test commit_withholding_tax event processing.""" event_name = mock_commit_wht_custom_payment_event['event_name'] processor = CommitLedgerProcessor(mock_commit_wht_custom_payment_event) processor.process() mock_commit_custom_payment.assert_called_once_with( mock_commit_wht_custom_payment_event['abacus_event_id'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['ledger_event_type'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['amount_type'], mock_commit_wht_custom_payment_event['target_id'], ) mock_commit_custom_payment.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_commit_wht_custom_payment_event}' ) mock_logger.error.assert_not_called() @patch('commit_ledger_account_contract.processor.app_logger') @patch('commit_ledger_account_contract.processor.CommitCustomPayment') def test_process_return_wht_custom_payment( mock_commit_custom_payment, mock_logger, mock_return_wht_custom_payment_event ): """Test return_withholding_tax event processing.""" event_name = mock_return_wht_custom_payment_event['event_name'] processor = CommitLedgerProcessor(mock_return_wht_custom_payment_event) processor.process() mock_commit_custom_payment.assert_called_once_with( mock_return_wht_custom_payment_event['abacus_event_id'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['ledger_event_type'], CUSTOM_PAYMENT_EVENT_MAP[event_name]['amount_type'], mock_return_wht_custom_payment_event['target_id'], ) mock_commit_custom_payment.return_value.commit.assert_called_once() mock_logger.info.assert_called_once_with( f'Processing {mock_return_wht_custom_payment_event}' ) mock_logger.error.assert_not_called()