from uuid import UUID
from starlette.testclient import TestClient

from fmatch.saas.main import create_app
from fmatch.saas.auth import get_current_account


def test_ownership_mismatch_returns_404():
    app = create_app()
    client = TestClient(app)

    acct_a = UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
    acct_b = UUID("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")

    # Create job as A
    app.dependency_overrides[get_current_account] = lambda: acct_a
    r1 = client.post(
        "/api/v2/jobs/run",
        json={
            "input": {"uri": "file://dummy.csv"},
            "intelligence": {"profile": "leads_to_accounts", "threshold": 0.75, "options": {}},
        },
    )
    assert r1.status_code in (201, 200), r1.text
    job_id = r1.json()["job_id"]

    # Query as B → 404
    app.dependency_overrides[get_current_account] = lambda: acct_b
    r2 = client.get(f"/api/v2/jobs/{job_id}")
    assert r2.status_code == 404, r2.text

