70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
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",
|
|
"data": {"type": "trigger"}
|
|
},
|
|
{
|
|
"id": "decision-tier",
|
|
"type": "decision",
|
|
"data": {
|
|
"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"
|
|
}
|
|
},
|
|
{
|
|
"id": "assign-vip",
|
|
"type": "assignment",
|
|
"data": {
|
|
"assignments": [
|
|
{"variable": "account_tier", "op": "equals", "value": "VIP"},
|
|
{"variable": "priority_score", "op": "add", "value": 100}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"id": "assign-standard",
|
|
"type": "assignment",
|
|
"data": {
|
|
"assignments": [
|
|
{"variable": "account_tier", "op": "equals", "value": "Standard"},
|
|
{"variable": "priority_score", "op": "add", "value": 10}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"id": "subflow-sync",
|
|
"type": "subflow",
|
|
"data": {
|
|
"subflow_id": subflow.id
|
|
}
|
|
}
|
|
],
|
|
"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')}"
|