"""Functional tests for fetching transactions.""" from oto import status from tests.testutils import db, mock_auth from tests.testutils import transaction_fixtures as fixtures @db.test_schema_default_seed def test_get_transactions(auth_client): """Test get transactions handler.""" result = auth_client.get("/collaborators/1/transactions") assert result.json == { "items": fixtures.SORTED_TRANSACTIONS, "pagination": {"total_records": 4, "type": "standard"}, } assert result.status_code == 200 @db.test_schema_default_seed def test_get_transactions_moneyhub(auth_client, mocker): """Test get transactions handler.""" collab_id = 1 mock_auth(mocker, collab_id) result = auth_client.get( f"/collaborators/{collab_id}/transactions", headers=[ ("orchard-identity-id", "7ec441df-7b21-4a71-a9da"), ("orchard-profile-id", "90003"), ("orchard-profile-type", "MoneyhubProfile"), ], ) assert result.json == { "items": fixtures.SORTED_TRANSACTIONS, "pagination": {"total_records": 4, "type": "standard"}, } assert result.status_code == 200 @db.test_schema_default_seed def test_get_transactions_not_found(auth_client): """Test get transactions handler with not found response.""" result = auth_client.get("/collaborators/2/transactions") assert result.status_code == 200 assert result.json == { "items": [], "pagination": {"total_records": 0, "type": "standard"}, } @db.test_schema_default_seed def test_get_transactions_account_no_access(auth_client, mocker): """Test get transactions handler with no access.""" mock_auth(mocker, 123) result = auth_client.get("/collaborators/2/transactions") assert result.status_code == status.FORBIDDEN def test_get_transactions_with_profile_auth_error(auth_client): """Test get transactions handler with bad params response.""" result = auth_client.get( "/collaborators/1/transactions", headers=[ ("orchard-identity-id", "7ec441df-7b21-4a71-a9da"), ("orchard-profile-id", "90003"), ("orchard-profile-type", "BogusProfile"), ], ) assert result.status_code == status.FORBIDDEN