feat: Phase 1 Group 5 — add account_id to PSA and notification tables
psa_post_log: backfill via psa_connection, fallback to posted_by user psa_member_mappings: backfill via psa_connection notification_logs: backfill via notification_config Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -343,3 +343,41 @@ async def test_user_pinned_tree_account_id_matches_user(test_db: AsyncSession):
|
||||
result = await test_db.execute(select(UserPinnedTree).where(UserPinnedTree.id == pin.id))
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
|
||||
# ── Group 5: PSA & notifications ─────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_psa_member_mapping_account_id_matches_connection(test_db: AsyncSession):
|
||||
"""psa_member_mappings.account_id must match psa_connection's account_id."""
|
||||
from app.models.psa_connection import PsaConnection
|
||||
from app.models.psa_member_mapping import PsaMemberMapping
|
||||
|
||||
account, user = await _make_account_and_user(test_db, "psa1")
|
||||
conn = PsaConnection(
|
||||
account_id=account.id,
|
||||
provider="connectwise",
|
||||
display_name="Test CW",
|
||||
site_url="https://cw.example.com",
|
||||
company_id="TEST",
|
||||
credentials_encrypted="placeholder",
|
||||
)
|
||||
test_db.add(conn)
|
||||
await test_db.flush()
|
||||
|
||||
mapping = PsaMemberMapping(
|
||||
psa_connection_id=conn.id,
|
||||
user_id=user.id,
|
||||
account_id=account.id,
|
||||
external_member_id="cw-123",
|
||||
external_member_name="Test User",
|
||||
matched_by="manual_admin",
|
||||
)
|
||||
test_db.add(mapping)
|
||||
await test_db.commit()
|
||||
|
||||
result = await test_db.execute(
|
||||
select(PsaMemberMapping).where(PsaMemberMapping.id == mapping.id)
|
||||
)
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
Reference in New Issue
Block a user