"""Tests for WorksheetAccountContractTaxableRevenue repository.""" from payment.repository import worksheet_account_contract_taxable_revenue as repository from tests.utils.factories import ( PaymentGroupPaymentAccountFactory, PaymentGroupPaymentBatchAccountFactory, PaymentGroupPaymentBatchFactory, WorksheetAccountContractTaxableRevenueFactory, ) def test_catchup_taxable_revenue_no_payments( mock_abacus_event, mock_statement_periods, mock_accounts, mock_contracts, mock_worksheet_account_contract_closing_balance, create_mock_payment_state, ): """Test catchup_taxable_revenue function.""" payment_group_payment_account = PaymentGroupPaymentAccountFactory.create( account_id=1, current_statement_period_id=1, payment_group_payment_account_id=3, # rejected in mocked state ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=1 # error in mocked state ) PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_batch=payment_group_payment_batch, payment_group_payment_account=payment_group_payment_account, ) worksheet1 = WorksheetAccountContractTaxableRevenueFactory.create( account_id=1, statement_period_id=2 ) worksheet2 = WorksheetAccountContractTaxableRevenueFactory.create( account_id=2, statement_period_id=2 ) items, total_count = repository.catchup_taxable_revenue(100, 0) assert items == [worksheet1, worksheet2] assert total_count == 2 items, total_count = repository.catchup_taxable_revenue(100, 0, [1]) assert items == [worksheet1] assert total_count == 1 items, total_count = repository.catchup_taxable_revenue(100, 0, [2]) assert items == [worksheet2] assert total_count == 1 items, total_count = repository.catchup_taxable_revenue(1, 1) assert items == [worksheet2] assert total_count == 2 def test_catchup_taxable_revenue_payment_before_statement_period( mock_abacus_event, mock_statement_periods, mock_accounts, mock_contracts, mock_worksheet_account_contract_closing_balance, create_mock_payment_state, ): """Test catchup_taxable_revenue function.""" payment_group_payment_account = PaymentGroupPaymentAccountFactory.create( account_id=1, current_statement_period_id=1, payment_group_payment_account_id=7, # complete in mocked state ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=3 # complete in mocked state ) PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_batch=payment_group_payment_batch, payment_group_payment_account=payment_group_payment_account, ) worksheet = WorksheetAccountContractTaxableRevenueFactory.create( account_id=1, statement_period_id=2 ) items, total_count = repository.catchup_taxable_revenue(100, 0) assert items == [worksheet] assert total_count == 1 items, total_count = repository.catchup_taxable_revenue(100, 0, [1]) assert items == [worksheet] assert total_count == 1 items, total_count = repository.catchup_taxable_revenue(100, 0, [2]) assert items == [] assert total_count == 0 def test_catchup_taxable_revenue_deleted_payment( mock_abacus_event, mock_statement_periods, mock_accounts, mock_contracts, mock_worksheet_account_contract_closing_balance, create_mock_payment_state, faker, ): """Test catchup_taxable_revenue function.""" payment_group_payment_account = PaymentGroupPaymentAccountFactory.create( deleted_at=faker.past_datetime(), account_id=1, current_statement_period_id=1, payment_group_payment_account_id=7, # complete in mocked state ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=3 # complete in mocked state ) PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_batch=payment_group_payment_batch, payment_group_payment_account=payment_group_payment_account, ) worksheet = WorksheetAccountContractTaxableRevenueFactory.create( account_id=1, statement_period_id=2 ) items, total_count = repository.catchup_taxable_revenue(100, 0, [1]) assert items == [worksheet] assert total_count == 1 def test_catchup_taxable_revenue_payment_in_statement_period( mock_abacus_event, mock_statement_periods, mock_accounts, mock_contracts, mock_worksheet_account_contract_closing_balance, create_mock_payment_state, ): """Test catchup_taxable_revenue function.""" payment_group_payment_account = PaymentGroupPaymentAccountFactory.create( account_id=1, current_statement_period_id=3, payment_group_payment_account_id=7, # complete in mocked state ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=3 # complete in mocked state ) PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_batch=payment_group_payment_batch, payment_group_payment_account=payment_group_payment_account, ) WorksheetAccountContractTaxableRevenueFactory.create( account_id=1, statement_period_id=3 ) items, total_count = repository.catchup_taxable_revenue(100, 0, [1]) assert items == [] assert total_count == 0 def test_catchup_taxable_revenue_payment_after_statement_period( mock_abacus_event, mock_statement_periods, mock_accounts, mock_contracts, mock_worksheet_account_contract_closing_balance, create_mock_payment_state, ): """Test catchup_taxable_revenue function.""" payment_group_payment_account = PaymentGroupPaymentAccountFactory.create( account_id=1, current_statement_period_id=3, payment_group_payment_account_id=7, # complete in mocked state ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=3 # complete in mocked state ) PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_batch=payment_group_payment_batch, payment_group_payment_account=payment_group_payment_account, ) WorksheetAccountContractTaxableRevenueFactory.create( account_id=1, statement_period_id=2 ) items, total_count = repository.catchup_taxable_revenue(100, 0) assert items == [] assert total_count == 0