feat: Ipad app production readiness, Colony orchestration, Social posting (#44)

#38 Ipad app production readiness, Colony orchestration, Social posting

Co-authored-by: Sayan Datta <sayan@Sayans-MacBook-Air.local>
Reviewed-on: sagnik/Project_Velocity#44
This commit is contained in:
2026-05-03 18:30:38 +05:30
parent 59d398abc3
commit eeb684b46c
86 changed files with 20349 additions and 1655 deletions

View File

@@ -1,9 +1,14 @@
from __future__ import annotations
import os
os.environ.setdefault("VELOCITY_JWT_SECRET", "test-secret")
from fastapi import FastAPI
from fastapi.testclient import TestClient
from backend.api.routes_catalyst import router
from backend.auth.dependencies import UserPrincipal, get_current_user
from backend.services.ad_network_service import BidAction, Platform
@@ -18,6 +23,18 @@ def _build_client() -> TestClient:
return TestClient(app)
def _build_authed_client() -> TestClient:
app = FastAPI()
app.state.db_pool = object()
app.dependency_overrides[get_current_user] = lambda: UserPrincipal(
user_id="sayan",
role="ADMIN",
tenant_id="tenant-root",
)
app.include_router(router, prefix="/api/catalyst")
return TestClient(app)
def test_catalyst_campaigns_and_google_budget_routes(monkeypatch) -> None:
client = _build_client()
@@ -92,3 +109,51 @@ def test_catalyst_campaigns_and_google_budget_routes(monkeypatch) -> None:
)
assert bid.status_code == 200
assert bid.json()["data"]["new_strategy"] == "TARGET_ROAS"
def test_catalyst_social_publish_route_is_tenant_scoped(monkeypatch) -> None:
async def fake_publish_content(*, pool, tenant_id, actor_id, payload):
assert pool is not None
assert tenant_id == "tenant-root"
assert actor_id == "sayan"
assert payload.platforms[0].value == "facebook"
return {
"request_id": "req-1",
"total": 1,
"published": 1,
"scheduled": 0,
"failed": 0,
"posts": [{"post_id": "post-1", "platform": "facebook", "status": "published"}],
}
monkeypatch.setattr("backend.api.routes_catalyst.publish_content", fake_publish_content)
response = _build_authed_client().post(
"/api/catalyst/publish",
json={
"platforms": ["facebook"],
"post_type": "image",
"caption": "New waterfront inventory is ready.",
"media_url": "https://assets.example.com/post.jpg",
},
)
assert response.status_code == 201
assert response.json()["data"]["published"] == 1
def test_catalyst_scheduled_posts_route_filters_scheduled_status(monkeypatch) -> None:
async def fake_list_posts(*, pool, tenant_id, platform=None, status=None, limit=50):
assert pool is not None
assert tenant_id == "tenant-root"
assert platform is None
assert status.value == "scheduled"
assert limit == 25
return [{"post_id": "post-2", "platform": "linkedin", "status": "scheduled"}]
monkeypatch.setattr("backend.api.routes_catalyst.list_posts", fake_list_posts)
response = _build_authed_client().get("/api/catalyst/scheduled?limit=25")
assert response.status_code == 200
assert response.json()["meta"]["count"] == 1