@@ -547,6 +547,40 @@ def test_batch_update_merchant_target_exists(self, backend, mock_ynab_api):
547547 )
548548 mock_transactions_api .update_transactions .assert_called_once ()
549549
550+ def test_batch_update_merchant_same_payee_id (self , backend , mock_ynab_api ):
551+ """Test that reassigning to the same payee ID is rejected."""
552+ backend .client .budget_id = "test-budget-id"
553+ backend .client .api_client = MagicMock ()
554+
555+ # Mock two payees with different names but same ID (edge case - shouldn't happen but guard against it)
556+ mock_old_payee = MagicMock ()
557+ mock_old_payee .id = "payee-same"
558+ mock_old_payee .name = "Amazon.com"
559+
560+ mock_target_payee = MagicMock ()
561+ mock_target_payee .id = "payee-same" # Same ID!
562+ mock_target_payee .name = "Amazon"
563+
564+ mock_payees_response = MagicMock ()
565+ mock_payees_response .data .payees = [mock_old_payee , mock_target_payee ]
566+
567+ mock_payees_api = MagicMock ()
568+ mock_payees_api .get_payees .return_value = mock_payees_response
569+
570+ mock_ynab_api .PayeesApi .return_value = mock_payees_api
571+
572+ # Attempt to rename payee to itself (simulating a bug where names differ but ID is same)
573+ result = backend .batch_update_merchant ("Amazon.com" , "Amazon" )
574+
575+ # Should fail with same_payee_error
576+ assert result ["success" ] is False
577+ assert result ["method" ] == "same_payee_error"
578+ assert "same payee" in result ["message" ]
579+ assert result ["payee_id" ] == "payee-same"
580+
581+ # Verify no API calls were made to update transactions
582+ mock_payees_api .update_payee .assert_not_called ()
583+
550584 def test_batch_update_merchant_integration (self , backend , mock_ynab_api ):
551585 """
552586 Integration test: Verify that batch_update_merchant cascades to transactions.
0 commit comments