"""worksheet_payment_custom repository tests.""" from datetime import datetime from payment.repository import worksheet_payment_custom as repository from tests.utils.factories import WorksheetPaymentCustomFactory def test_get_filtered_worksheet_payment_customs_no_filters( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with no filters.""" # Create test data custom1 = WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs() assert total_count == 2 assert len(items) == 2 assert custom1 in items assert custom2 in items def test_get_filtered_worksheet_payment_customs_with_ids_filter( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with worksheet_payment_custom_ids filter.""" # Create test data custom1 = WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create() custom3 = WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs( worksheet_payment_custom_ids=[ custom1.worksheet_payment_custom_id, custom2.worksheet_payment_custom_id, ] ) assert total_count == 2 assert len(items) == 2 assert custom1 in items assert custom2 in items assert custom3 not in items def test_get_filtered_worksheet_payment_customs_with_single_id( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with single ID.""" # Create test data custom1 = WorksheetPaymentCustomFactory.create() WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs( worksheet_payment_custom_ids=[custom1.worksheet_payment_custom_id] ) assert total_count == 1 assert len(items) == 1 assert items[0] == custom1 def test_get_filtered_worksheet_payment_customs_excludes_deleted( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs excludes soft-deleted records.""" # Create test data custom1 = WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create(deleted_at=datetime.now()) items, total_count = repository.get_filtered_worksheet_payment_customs() assert total_count == 1 assert len(items) == 1 assert items[0] == custom1 def test_get_filtered_worksheet_payment_customs_pagination_limit( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with limit.""" # Create test data WorksheetPaymentCustomFactory.create() WorksheetPaymentCustomFactory.create() WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs(limit=2) assert total_count == 3 assert len(items) == 2 def test_get_filtered_worksheet_payment_customs_pagination_offset( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with offset.""" # Create test data in specific order custom1 = WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create() custom3 = WorksheetPaymentCustomFactory.create() # Get first page items_page1, total_count = repository.get_filtered_worksheet_payment_customs( limit=2, offset=0 ) assert total_count == 3 assert len(items_page1) == 2 # Get second page items_page2, total_count = repository.get_filtered_worksheet_payment_customs( limit=2, offset=2 ) assert total_count == 3 assert len(items_page2) == 1 def test_get_filtered_worksheet_payment_customs_limit_and_offset( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with both limit and offset.""" # Create test data WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create() custom3 = WorksheetPaymentCustomFactory.create() WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs( limit=2, offset=1 ) assert total_count == 4 assert len(items) == 2 # Results should be ordered by created_at desc, so we get the 2nd and 3rd newest assert custom2 in items assert custom3 in items def test_get_filtered_worksheet_payment_customs_empty_result( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with no matching records.""" items, total_count = repository.get_filtered_worksheet_payment_customs( worksheet_payment_custom_ids=[999999] ) assert total_count == 0 assert len(items) == 0 def test_get_filtered_worksheet_payment_customs_combined_filters( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs with multiple filters combined.""" # Create test data custom1 = WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create() custom3 = WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs( worksheet_payment_custom_ids=[ custom1.worksheet_payment_custom_id, custom2.worksheet_payment_custom_id, custom3.worksheet_payment_custom_id, ], limit=2, offset=0, ) assert total_count == 3 assert len(items) == 2 def test_get_filtered_worksheet_payment_customs_ordering( fresh_db, mock_accounts, mock_contracts ): """Test get_filtered_worksheet_payment_customs returns results ordered by created_at desc.""" # Create test data with known order custom1 = WorksheetPaymentCustomFactory.create() custom2 = WorksheetPaymentCustomFactory.create() custom3 = WorksheetPaymentCustomFactory.create() items, total_count = repository.get_filtered_worksheet_payment_customs() assert total_count == 3 assert len(items) == 3 # Should be ordered by created_at desc (newest first) assert items[0].created_at >= items[1].created_at assert items[1].created_at >= items[2].created_at