import pytest from workflows.engine import execute_flow_dag from workflows.models import FlowDefinition @pytest.mark.django_db def test_vue_flow_initial_graph_executes_successfully(): subflow = FlowDefinition.objects.create( name="Child Sync Subflow", graph={"nodes": [{"id": "sub_start", "type": "trigger", "data": {}}], "edges": []} ) vue_graph = { "nodes": [ { "id": "start-trigger", "type": "input", "label": "⚡ Trigger: Account Created", "position": {"x": 100, "y": 150}, "class": "bg-emerald-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0" }, { "id": "decision-tier", "label": "⚖️ Decision: VIP Tier Check", "position": {"x": 340, "y": 150}, "data": { "type": "decision", "conditions": [ {"field": "amount", "op": "gte", "value": 50000, "target_node": "assign-vip"}, {"field": "amount", "op": "gte", "value": 10000, "target_node": "assign-standard"} ], "default_target": "assign-standard" }, "class": "bg-indigo-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0" }, { "id": "assign-vip", "label": "💎 Assignment: VIP Customer", "position": {"x": 600, "y": 80}, "data": { "type": "assignment", "assignments": [ {"variable": "account_tier", "op": "equals", "value": "VIP"}, {"variable": "priority_score", "op": "add", "value": 100} ] }, "class": "bg-blue-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0" }, { "id": "assign-standard", "label": "📦 Assignment: Standard Customer", "position": {"x": 600, "y": 220}, "data": { "type": "assignment", "assignments": [ {"variable": "account_tier", "op": "equals", "value": "Standard"}, {"variable": "priority_score", "op": "add", "value": 10} ] }, "class": "bg-slate-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0" }, { "id": "subflow-sync", "label": "🔄 Subflow: Sync to Billing", "position": {"x": 860, "y": 150}, "data": { "type": "subflow", "subflow_id": subflow.id, "input_mapping": {"customer_id": "record.id"}, "output_mapping": {"sync_status": "status"} }, "class": "bg-violet-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0" } ], "edges": [ {"id": "e1-2", "source": "start-trigger", "target": "decision-tier"}, {"id": "e2-3", "source": "decision-tier", "target": "assign-vip"}, {"id": "e2-4", "source": "decision-tier", "target": "assign-standard"}, {"id": "e3-5", "source": "assign-vip", "target": "subflow-sync"}, {"id": "e4-5", "source": "assign-standard", "target": "subflow-sync"} ] } res = execute_flow_dag(vue_graph, initial_context={"amount": 75000}) ctx = res if isinstance(res, dict) else res.context assert ctx.get("account_tier") == "VIP", f"Expected VIP, got {ctx.get('account_tier')}" assert ctx.get("priority_score") == 100, f"Expected 100, got {ctx.get('priority_score')}"