From fa02aa9afbf17711f6e8c4f42af50836aae7fcb0 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 30 Oct 2017 14:21:14 -0500 Subject: [PATCH 1/3] Rework results format to match new rapidpro stuff --- .../testdata/flows/all_actions.json | 2 +- .../testdata/flows/all_actions_test.json | 8 +- cmd/flowrunner/testdata/flows/brochure.json | 2 +- .../testdata/flows/brochure_test.json | 10 +- .../testdata/flows/date_parse_test.json | 10 +- .../testdata/flows/default_result_test.json | 10 +- .../testdata/flows/dynamic_groups_test.json | 1 - cmd/flowrunner/testdata/flows/empty_test.json | 1 - .../testdata/flows/node_loop_test.json | 1 - cmd/flowrunner/testdata/flows/subflow.json | 2 +- .../testdata/flows/subflow_loop_test.json | 2 - .../testdata/flows/subflow_other.json | 4 +- .../testdata/flows/subflow_other_test.json | 64 +++--- .../testdata/flows/subflow_test.json | 12 +- .../testdata/flows/triggered_test.json | 4 +- .../testdata/flows/two_questions.json | 4 +- .../testdata/flows/two_questions_test.json | 25 ++- .../testdata/flows/webhook_persists_test.json | 2 - flows/actions/save_flow_result.go | 17 +- flows/engine/session.go | 14 +- flows/events/save_flow_result.go | 27 ++- flows/interfaces.go | 4 +- flows/results.go | 195 ++++++------------ flows/routers/first.go | 6 +- flows/routers/random.go | 6 +- flows/routers/random_once.go | 8 +- flows/routers/switch.go | 16 +- flows/runs/run.go | 6 +- flows/runsummary.go | 6 +- 29 files changed, 212 insertions(+), 257 deletions(-) diff --git a/cmd/flowrunner/testdata/flows/all_actions.json b/cmd/flowrunner/testdata/flows/all_actions.json index 4d9bb2be0..ac2bc2a26 100644 --- a/cmd/flowrunner/testdata/flows/all_actions.json +++ b/cmd/flowrunner/testdata/flows/all_actions.json @@ -123,7 +123,7 @@ { "uuid": "5508e6a7-26ce-4b3b-b32e-bb4e2e614f5d", "type": "save_flow_result", - "result_name": "gender", + "name": "gender", "value": "m", "category": "Male" }, diff --git a/cmd/flowrunner/testdata/flows/all_actions_test.json b/cmd/flowrunner/testdata/flows/all_actions_test.json index 13a6314ac..8865ff720 100644 --- a/cmd/flowrunner/testdata/flows/all_actions_test.json +++ b/cmd/flowrunner/testdata/flows/all_actions_test.json @@ -268,8 +268,8 @@ "event": { "category": "Male", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "name": "gender", "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", - "result_name": "gender", "type": "save_flow_result", "value": "m" }, @@ -586,8 +586,8 @@ { "category": "Male", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "name": "gender", "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", - "result_name": "gender", "type": "save_flow_result", "value": "m" }, @@ -625,8 +625,9 @@ "gender": { "category": "Male", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "", + "name": "gender", "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", - "result_name": "gender", "value": "m" } }, @@ -648,7 +649,6 @@ "flow_uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d", "parent_uuid": "", "path": [], - "results": {}, "status": "completed", "uuid": "" } diff --git a/cmd/flowrunner/testdata/flows/brochure.json b/cmd/flowrunner/testdata/flows/brochure.json index 7b8303687..c45cedbbc 100644 --- a/cmd/flowrunner/testdata/flows/brochure.json +++ b/cmd/flowrunner/testdata/flows/brochure.json @@ -32,7 +32,7 @@ "router": { "type": "switch", "default_exit_uuid": "0680b01f-ba0b-48f4-a688-d2f963130126", - "result_name": "name", + "result_name": "Name", "operand": "@run.input", "cases": [ { diff --git a/cmd/flowrunner/testdata/flows/brochure_test.json b/cmd/flowrunner/testdata/flows/brochure_test.json index c41bc2bbf..e2abe7317 100644 --- a/cmd/flowrunner/testdata/flows/brochure_test.json +++ b/cmd/flowrunner/testdata/flows/brochure_test.json @@ -114,7 +114,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" } @@ -140,8 +139,9 @@ "event": { "category": "", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Name", "node_uuid": "3dcccbb4-d29c-41dd-a01f-16d814c9ab82", - "result_name": "name", "type": "save_flow_result", "value": "Ryan Lewis" }, @@ -279,8 +279,9 @@ { "category": "", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Name", "node_uuid": "3dcccbb4-d29c-41dd-a01f-16d814c9ab82", - "result_name": "name", "type": "save_flow_result", "value": "Ryan Lewis" } @@ -330,8 +331,9 @@ "results": { "name": { "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Name", "node_uuid": "3dcccbb4-d29c-41dd-a01f-16d814c9ab82", - "result_name": "name", "value": "Ryan Lewis" } }, diff --git a/cmd/flowrunner/testdata/flows/date_parse_test.json b/cmd/flowrunner/testdata/flows/date_parse_test.json index e5cca5f69..62b1370b3 100644 --- a/cmd/flowrunner/testdata/flows/date_parse_test.json +++ b/cmd/flowrunner/testdata/flows/date_parse_test.json @@ -105,7 +105,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" } @@ -131,8 +130,9 @@ "event": { "category": "Valid", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "I was born on 1977.06.23 at 3:34 pm", + "name": "Birth Date", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "Birth Date", "type": "save_flow_result", "value": "1977-06-23T15:34:00.000000-05:00" }, @@ -251,8 +251,9 @@ { "category": "Valid", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "I was born on 1977.06.23 at 3:34 pm", + "name": "Birth Date", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "Birth Date", "type": "save_flow_result", "value": "1977-06-23T15:34:00.000000-05:00" } @@ -295,8 +296,9 @@ "birth_date": { "category": "Valid", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "I was born on 1977.06.23 at 3:34 pm", + "name": "Birth Date", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "Birth Date", "value": "1977-06-23T15:34:00.000000-05:00" } }, diff --git a/cmd/flowrunner/testdata/flows/default_result_test.json b/cmd/flowrunner/testdata/flows/default_result_test.json index b6a08d72c..760b7f893 100644 --- a/cmd/flowrunner/testdata/flows/default_result_test.json +++ b/cmd/flowrunner/testdata/flows/default_result_test.json @@ -112,7 +112,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" } @@ -137,8 +136,9 @@ "event": { "category": "All Responses", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Contact Name", "node_uuid": "3a430844-e259-4dcd-9a1d-7bef3168d43f", - "result_name": "Contact Name", "type": "save_flow_result", "value": "Ryan Lewis" }, @@ -271,8 +271,9 @@ { "category": "All Responses", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Contact Name", "node_uuid": "3a430844-e259-4dcd-9a1d-7bef3168d43f", - "result_name": "Contact Name", "type": "save_flow_result", "value": "Ryan Lewis" } @@ -321,8 +322,9 @@ "contact_name": { "category": "All Responses", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Contact Name", "node_uuid": "3a430844-e259-4dcd-9a1d-7bef3168d43f", - "result_name": "Contact Name", "value": "Ryan Lewis" } }, diff --git a/cmd/flowrunner/testdata/flows/dynamic_groups_test.json b/cmd/flowrunner/testdata/flows/dynamic_groups_test.json index f044fea05..dc94a726b 100644 --- a/cmd/flowrunner/testdata/flows/dynamic_groups_test.json +++ b/cmd/flowrunner/testdata/flows/dynamic_groups_test.json @@ -223,7 +223,6 @@ "uuid": "" } ], - "results": {}, "status": "completed", "uuid": "" } diff --git a/cmd/flowrunner/testdata/flows/empty_test.json b/cmd/flowrunner/testdata/flows/empty_test.json index ab383de6e..74bcd6909 100644 --- a/cmd/flowrunner/testdata/flows/empty_test.json +++ b/cmd/flowrunner/testdata/flows/empty_test.json @@ -40,7 +40,6 @@ "expires_on": "2000-01-01T00:00:00.000000000-00:00", "flow_uuid": "76f0a02f-3b75-4b86-9064-e9195e1b3a02", "path": [], - "results": {}, "status": "completed", "uuid": "" } diff --git a/cmd/flowrunner/testdata/flows/node_loop_test.json b/cmd/flowrunner/testdata/flows/node_loop_test.json index 36b995d65..e91567339 100644 --- a/cmd/flowrunner/testdata/flows/node_loop_test.json +++ b/cmd/flowrunner/testdata/flows/node_loop_test.json @@ -92,7 +92,6 @@ "uuid": "" } ], - "results": {}, "status": "errored", "uuid": "" } diff --git a/cmd/flowrunner/testdata/flows/subflow.json b/cmd/flowrunner/testdata/flows/subflow.json index 78b34d9ea..6b5b15597 100644 --- a/cmd/flowrunner/testdata/flows/subflow.json +++ b/cmd/flowrunner/testdata/flows/subflow.json @@ -97,7 +97,7 @@ "type": "msg" }, "router": { - "result_name": "name", + "result_name": "Name", "type": "switch", "default": "910521f5-d709-437e-b7b7-5aab3d83ffb5", "operand": "@run.input.text", diff --git a/cmd/flowrunner/testdata/flows/subflow_loop_test.json b/cmd/flowrunner/testdata/flows/subflow_loop_test.json index 64d22a605..02010daed 100644 --- a/cmd/flowrunner/testdata/flows/subflow_loop_test.json +++ b/cmd/flowrunner/testdata/flows/subflow_loop_test.json @@ -137,7 +137,6 @@ "uuid": "" } ], - "results": {}, "status": "errored", "uuid": "" }, @@ -173,7 +172,6 @@ "uuid": "" } ], - "results": {}, "status": "errored", "uuid": "" } diff --git a/cmd/flowrunner/testdata/flows/subflow_other.json b/cmd/flowrunner/testdata/flows/subflow_other.json index 092760445..8f8e364f7 100644 --- a/cmd/flowrunner/testdata/flows/subflow_other.json +++ b/cmd/flowrunner/testdata/flows/subflow_other.json @@ -112,7 +112,7 @@ ], "router": { "type": "switch", - "result_name": "answer", + "result_name": "Answer", "cases": [ { "type": "has_any_word", @@ -203,7 +203,7 @@ ], "router": { "type": "switch", - "result_name": "answer", + "result_name": "Answer", "cases": [ { "type": "has_any_word", diff --git a/cmd/flowrunner/testdata/flows/subflow_other_test.json b/cmd/flowrunner/testdata/flows/subflow_other_test.json index 784b70d19..14776a608 100644 --- a/cmd/flowrunner/testdata/flows/subflow_other_test.json +++ b/cmd/flowrunner/testdata/flows/subflow_other_test.json @@ -196,7 +196,6 @@ "uuid": "" } ], - "results": {}, "status": "active", "uuid": "" }, @@ -239,7 +238,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" } @@ -264,8 +262,9 @@ "event": { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "neither", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "neither" }, @@ -366,7 +365,6 @@ "uuid": "" } ], - "results": {}, "status": "active", "uuid": "" }, @@ -430,8 +428,9 @@ { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "neither", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "neither" } @@ -477,8 +476,9 @@ "answer": { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "neither", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "value": "neither" } }, @@ -506,8 +506,9 @@ "event": { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "yes" }, @@ -656,7 +657,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" }, @@ -720,8 +720,9 @@ { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "neither", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "neither" } @@ -776,8 +777,9 @@ { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "yes" } @@ -812,8 +814,9 @@ "answer": { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "value": "yes" } }, @@ -841,8 +844,9 @@ "event": { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "never", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "type": "save_flow_result", "value": "never" }, @@ -997,8 +1001,9 @@ { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "never", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "type": "save_flow_result", "value": "never" } @@ -1044,8 +1049,9 @@ "answer": { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "never", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "value": "never" } }, @@ -1112,8 +1118,9 @@ { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "neither", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "neither" } @@ -1168,8 +1175,9 @@ { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "yes" } @@ -1204,8 +1212,9 @@ "answer": { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "value": "yes" } }, @@ -1233,8 +1242,9 @@ "event": { "category": "No", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "no", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "type": "save_flow_result", "value": "no" }, @@ -1382,8 +1392,9 @@ { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "never", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "type": "save_flow_result", "value": "never" } @@ -1438,8 +1449,9 @@ { "category": "No", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "no", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "type": "save_flow_result", "value": "no" } @@ -1474,8 +1486,9 @@ "answer": { "category": "No", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "no", + "name": "Answer", "node_uuid": "6bd3b6ec-050d-41f7-84bf-f4030f2f01f7", - "result_name": "answer", "value": "no" } }, @@ -1542,8 +1555,9 @@ { "category": "Other", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "neither", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "neither" } @@ -1598,8 +1612,9 @@ { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "type": "save_flow_result", "value": "yes" } @@ -1634,8 +1649,9 @@ "answer": { "category": "Yes", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "yes", + "name": "Answer", "node_uuid": "7dbcb3fd-16ee-4ce6-bd56-54b45a647958", - "result_name": "answer", "value": "yes" } }, diff --git a/cmd/flowrunner/testdata/flows/subflow_test.json b/cmd/flowrunner/testdata/flows/subflow_test.json index 172f5229f..1eb934f4c 100644 --- a/cmd/flowrunner/testdata/flows/subflow_test.json +++ b/cmd/flowrunner/testdata/flows/subflow_test.json @@ -136,7 +136,6 @@ "uuid": "" } ], - "results": {}, "status": "active", "uuid": "" }, @@ -170,7 +169,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" } @@ -195,8 +193,9 @@ "event": { "category": "Name", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Name", "node_uuid": "9f7632ee-6e35-4247-9235-c4c7663fd601", - "result_name": "name", "type": "save_flow_result", "value": "Ryan Lewis" }, @@ -317,7 +316,6 @@ "uuid": "" } ], - "results": {}, "status": "completed", "uuid": "" }, @@ -372,8 +370,9 @@ { "category": "Name", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Name", "node_uuid": "9f7632ee-6e35-4247-9235-c4c7663fd601", - "result_name": "name", "type": "save_flow_result", "value": "Ryan Lewis" } @@ -407,8 +406,9 @@ "name": { "category": "Name", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Ryan Lewis", + "name": "Name", "node_uuid": "9f7632ee-6e35-4247-9235-c4c7663fd601", - "result_name": "name", "value": "Ryan Lewis" } }, diff --git a/cmd/flowrunner/testdata/flows/triggered_test.json b/cmd/flowrunner/testdata/flows/triggered_test.json index 9e119973d..647f10202 100644 --- a/cmd/flowrunner/testdata/flows/triggered_test.json +++ b/cmd/flowrunner/testdata/flows/triggered_test.json @@ -76,7 +76,6 @@ "uuid": "" } ], - "results": {}, "status": "completed", "uuid": "" } @@ -105,8 +104,9 @@ "results": { "age": { "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "", + "name": "", "node_uuid": "", - "result_name": "Age", "value": "33" } }, diff --git a/cmd/flowrunner/testdata/flows/two_questions.json b/cmd/flowrunner/testdata/flows/two_questions.json index 0f21e483e..84e2bd365 100644 --- a/cmd/flowrunner/testdata/flows/two_questions.json +++ b/cmd/flowrunner/testdata/flows/two_questions.json @@ -91,7 +91,7 @@ }, "router": { "type": "switch", - "result_name": "favorite_color", + "result_name": "Favorite Color", "default_exit_uuid": "78ae8f05-f92e-43b2-a886-406eaea1b8e0", "operand": "@run.input", "cases": [ @@ -153,7 +153,7 @@ "router": { "type": "switch", "default_exit_uuid": "5ce6c69a-fdfe-4594-ab71-26be534d31c3", - "result_name": "soda", + "result_name": "Soda", "operand": "@run.input", "cases": [ { diff --git a/cmd/flowrunner/testdata/flows/two_questions_test.json b/cmd/flowrunner/testdata/flows/two_questions_test.json index 3d1f3788e..7d9bc47d9 100644 --- a/cmd/flowrunner/testdata/flows/two_questions_test.json +++ b/cmd/flowrunner/testdata/flows/two_questions_test.json @@ -122,7 +122,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "" } @@ -148,8 +147,9 @@ "event": { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Blue", + "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "favorite_color", "type": "save_flow_result", "value": "Blue" }, @@ -269,8 +269,9 @@ { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Blue", + "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "favorite_color", "type": "save_flow_result", "value": "Blue" } @@ -314,8 +315,9 @@ "favorite_color": { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Blue", + "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "favorite_color", "value": "Blue" } }, @@ -344,8 +346,9 @@ "event": { "category": "Coke", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Coke", + "name": "Soda", "node_uuid": "11a772f3-3ca2-4429-8b33-20fdcfc2b69e", - "result_name": "soda", "type": "save_flow_result", "value": "Coke" }, @@ -460,8 +463,9 @@ { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Blue", + "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "favorite_color", "type": "save_flow_result", "value": "Blue" } @@ -514,8 +518,9 @@ { "category": "Coke", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Coke", + "name": "Soda", "node_uuid": "11a772f3-3ca2-4429-8b33-20fdcfc2b69e", - "result_name": "soda", "type": "save_flow_result", "value": "Coke" } @@ -558,15 +563,17 @@ "favorite_color": { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Blue", + "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "result_name": "favorite_color", "value": "Blue" }, "soda": { "category": "Coke", "created_on": "2000-01-01T00:00:00.000000000-00:00", + "input": "Coke", + "name": "Soda", "node_uuid": "11a772f3-3ca2-4429-8b33-20fdcfc2b69e", - "result_name": "soda", "value": "Coke" } }, diff --git a/cmd/flowrunner/testdata/flows/webhook_persists_test.json b/cmd/flowrunner/testdata/flows/webhook_persists_test.json index 914dad7f3..581cef531 100644 --- a/cmd/flowrunner/testdata/flows/webhook_persists_test.json +++ b/cmd/flowrunner/testdata/flows/webhook_persists_test.json @@ -178,7 +178,6 @@ "uuid": "" } ], - "results": {}, "status": "waiting", "uuid": "", "webhook": { @@ -373,7 +372,6 @@ "uuid": "" } ], - "results": {}, "status": "completed", "uuid": "", "webhook": { diff --git a/flows/actions/save_flow_result.go b/flows/actions/save_flow_result.go index d77bb1715..aa0b22650 100644 --- a/flows/actions/save_flow_result.go +++ b/flows/actions/save_flow_result.go @@ -20,7 +20,7 @@ const TypeSaveFlowResult string = "save_flow_result" // { // "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9", // "type": "save_flow_result", -// "result_name": "gender", +// "name": "Gender", // "value": "m", // "category": "Male" // } @@ -29,9 +29,9 @@ const TypeSaveFlowResult string = "save_flow_result" // @action save_flow_result type SaveFlowResultAction struct { BaseAction - ResultName string `json:"result_name" validate:"required"` - Value string `json:"value"` - Category string `json:"category"` + Name string `json:"name" validate:"required"` + Value string `json:"value" validate:"required"` + Category string `json:"category"` } // Type returns the type of this action @@ -53,16 +53,11 @@ func (a *SaveFlowResultAction) Execute(run flows.FlowRun, step flows.Step, log f log.Add(events.NewErrorEvent(err)) } - template = run.GetText(flows.UUID(a.UUID()), "category", a.Category) - categoryLocalized, err := excellent.EvaluateTemplateAsString(run.Environment(), run.Context(), template) - if err != nil { - log.Add(events.NewErrorEvent(err)) - } - + categoryLocalized := run.GetText(flows.UUID(a.UUID()), "category", a.Category) if a.Category == categoryLocalized { categoryLocalized = "" } - log.Add(events.NewSaveFlowResult(step.NodeUUID(), a.ResultName, value, a.Category, categoryLocalized)) + log.Add(events.NewSaveFlowResult(a.Name, value, a.Category, categoryLocalized, step.NodeUUID(), "")) return nil } diff --git a/flows/engine/session.go b/flows/engine/session.go index 02260d6ce..3d61906c6 100644 --- a/flows/engine/session.go +++ b/flows/engine/session.go @@ -368,13 +368,14 @@ func (s *session) visitNode(run flows.FlowRun, node flows.Node, callerEvents []f func (s *session) pickNodeExit(run flows.FlowRun, node flows.Node, step flows.Step) (flows.Step, flows.NodeUUID, error) { var err error + var operand interface{} route := flows.NoRoute router := node.Router() // we have a router, have it determine our exit var exitUUID flows.ExitUUID if router != nil { - if route, err = router.PickRoute(run, node.Exits(), step); err != nil { + if operand, route, err = router.PickRoute(run, node.Exits(), step); err != nil { return nil, noDestination, err } exitUUID = route.Exit() @@ -387,7 +388,7 @@ func (s *session) pickNodeExit(run flows.FlowRun, node flows.Node, step flows.St // look up our actual exit and localized name var exit flows.Exit - var exitName string + var localizedExitName string if exitUUID != "" { // find our exit @@ -395,7 +396,7 @@ func (s *session) pickNodeExit(run flows.FlowRun, node flows.Node, step flows.St if e.UUID() == exitUUID { localizedName := run.GetText(flows.UUID(exitUUID), "name", e.Name()) if localizedName != e.Name() { - exitName = localizedName + localizedExitName = localizedName } exit = e break @@ -413,7 +414,12 @@ func (s *session) pickNodeExit(run flows.FlowRun, node flows.Node, step flows.St // save our results if appropriate if router != nil && router.ResultName() != "" && route.Match() != "" { - event := events.NewSaveFlowResult(node.UUID(), router.ResultName(), route.Match(), exit.Name(), exitName) + resultInput, err := utils.ToString(run.Environment(), operand) + if err != nil { + return nil, noDestination, err + } + + event := events.NewSaveFlowResult(router.ResultName(), route.Match(), exit.Name(), localizedExitName, node.UUID(), resultInput) run.ApplyEvent(step, nil, event) } diff --git a/flows/events/save_flow_result.go b/flows/events/save_flow_result.go index 064b5f2fe..db6fe6393 100644 --- a/flows/events/save_flow_result.go +++ b/flows/events/save_flow_result.go @@ -13,31 +13,36 @@ const TypeSaveFlowResult string = "save_flow_result" // { // "type": "save_flow_result", // "created_on": "2006-01-02T15:04:05Z", -// "node_uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d", -// "result_name": "Gender", +// "name": "Gender", // "value": "m", -// "category": "Make" +// "category": "Male", +// "category_localized": "Homme", +// "node_uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d", +// "input": "M" // } // ``` // // @event save_flow_result type SaveFlowResultEvent struct { BaseEvent - NodeUUID flows.NodeUUID `json:"node_uuid" validate:"required"` - ResultName string `json:"result_name" validate:"required"` + Name string `json:"name" validate:"required"` Value string `json:"value"` Category string `json:"category"` CategoryLocalized string `json:"category_localized,omitempty"` + NodeUUID flows.NodeUUID `json:"node_uuid" validate:"required,uuid4"` + Input string `json:"input,omitempty"` } // NewSaveFlowResult returns a new save result event for the passed in values -func NewSaveFlowResult(node flows.NodeUUID, name string, value string, categoryName string, categoryLocalized string) *SaveFlowResultEvent { +func NewSaveFlowResult(name string, value string, categoryName string, categoryLocalized string, node flows.NodeUUID, input string) *SaveFlowResultEvent { return &SaveFlowResultEvent{ - BaseEvent: NewBaseEvent(), - NodeUUID: node, - ResultName: name, - Value: value, Category: categoryName, + BaseEvent: NewBaseEvent(), + Name: name, + Value: value, + Category: categoryName, CategoryLocalized: categoryLocalized, + NodeUUID: node, + Input: input, } } @@ -46,6 +51,6 @@ func (e *SaveFlowResultEvent) Type() string { return TypeSaveFlowResult } // Apply applies this event to the given run func (e *SaveFlowResultEvent) Apply(run flows.FlowRun) error { - run.Results().Save(e.NodeUUID, e.ResultName, e.Value, e.Category, e.CategoryLocalized, e.BaseEvent.CreatedOn()) + run.Results().Save(e.Name, e.Value, e.Category, e.CategoryLocalized, e.NodeUUID, e.Input, e.BaseEvent.CreatedOn()) return nil } diff --git a/flows/interfaces.go b/flows/interfaces.go index 879f771f9..ebdb36d01 100644 --- a/flows/interfaces.go +++ b/flows/interfaces.go @@ -151,7 +151,7 @@ type Action interface { } type Router interface { - PickRoute(FlowRun, []Exit, Step) (Route, error) + PickRoute(FlowRun, []Exit, Step) (interface{}, Route, error) Validate([]Exit) error ResultName() string utils.Typed @@ -282,7 +282,7 @@ type RunSummary interface { Contact() *Contact Flow() Flow Status() RunStatus - Results() *Results + Results() Results } // FlowRun represents a run in the current session diff --git a/flows/results.go b/flows/results.go index e84f662f1..d4b4e2c0d 100644 --- a/flows/results.go +++ b/flows/results.go @@ -1,7 +1,6 @@ package flows import ( - "encoding/json" "fmt" "strings" "time" @@ -9,174 +8,102 @@ import ( "github.com/nyaruka/goflow/utils" ) -// NewResults returns a new empty Results object -func NewResults() *Results { - return &Results{make(map[string]*Result)} -} - -// Results is our wrapper around a map of snakified result names to result objects -type Results struct { - results map[string]*Result -} - -func (r *Results) Clone() *Results { - clone := make(map[string]*Result, len(r.results)) - for k, v := range r.results { - clone[k] = v - } - return &Results{results: clone} -} - -// Save saves a new result in our map. The key is saved in a snakified format -func (r *Results) Save(node NodeUUID, name string, value string, category string, categoryLocalized string, createdOn time.Time) { - result := Result{node, name, value, category, categoryLocalized, createdOn} - r.results[utils.Snakify(name)] = &result -} - -// Resolve resolves the passed in key, which is snakified before lookup -func (r *Results) Resolve(key string) interface{} { - key = utils.Snakify(key) - result, ok := r.results[key] - if !ok { - return nil - } - - return result -} - -// Default returns the default value for our Results, which is the entire map -func (r *Results) Default() interface{} { - return r -} - -// String returns the string representation of our Results, which is a key/value pairing of our fields -func (r *Results) String() string { - results := make([]string, 0, len(r.results)) - for _, v := range r.results { - results = append(results, fmt.Sprintf("%s: %s", v.name, v.value)) - } - return strings.Join(results, ", ") -} - -var _ utils.VariableResolver = (*Results)(nil) - // Result represents a result value in our flow run. Results have a name for which they are the result for, // the value itself of the result, optional category and the date and node the result was collected on type Result struct { - node NodeUUID - name string - value string - category string - categoryLocalized string - createdOn time.Time + Name string `json:"name"` + Value string `json:"value"` + Category string `json:"category,omitempty"` + CategoryLocalized string `json:"category_localized,omitempty"` + NodeUUID NodeUUID `json:"node_uuid"` + Input string `json:"input"` + CreatedOn time.Time `json:"created_on"` } // Resolve resolves the passed in key to a value. Result values have a name, value, category, node and created_on func (r *Result) Resolve(key string) interface{} { switch key { + case "name": + return r.Name + case "value": + return r.Value case "category": - return r.category - + return r.Category case "category_localized": - if r.categoryLocalized == "" { - return r.category + if r.CategoryLocalized == "" { + return r.Category } - return r.categoryLocalized + return r.CategoryLocalized case "created_on": - return r.createdOn - - case "node_uuid": - return r.node - - case "result_name": - return r.name - - case "value": - return r.value + return r.CreatedOn } - return fmt.Errorf("No field '%s' on result", key) + return fmt.Errorf("no field '%s' on result", key) } // Default returns the default value for a result, which is our value func (r *Result) Default() interface{} { - return r.value + return r.Value } // String returns the string representation of a result, which is our value func (r *Result) String() string { - return r.value + return r.Value } var _ utils.VariableResolver = (*Result)(nil) -//------------------------------------------------------------------------------------------ -// JSON Encoding / Decoding -//------------------------------------------------------------------------------------------ - -// UnmarshalJSON is our custom unmarshalling of a Results object, we build our map only with -// with snakified keys -func (r *Results) UnmarshalJSON(data []byte) error { - r.results = make(map[string]*Result) - incoming := make(map[string]*Result) - err := json.Unmarshal(data, &incoming) - if err != nil { - return err - } - - // populate ourselves with the values, but keyed with snakified values - for k, v := range incoming { - snaked := utils.Snakify(v.name) - if k != snaked { - return fmt.Errorf("invalid results map, key: '%s' does not match snaked result name: '%s'", k, v.name) - } +// Results is our wrapper around a map of snakified result names to result objects +type Results map[string]*Result - r.results[k] = v - } - return nil +func NewResults() Results { + return make(Results, 0) } -// MarshalJSON is our custom marshalling of a Results object, we build a map with -// the full names and then marshal that with snakified keys -func (r *Results) MarshalJSON() ([]byte, error) { - return json.Marshal(r.results) +func (r Results) Clone() Results { + clone := make(Results, len(r)) + for k, v := range r { + clone[k] = v + } + return clone } -type resultEnvelope struct { - Node NodeUUID `json:"node_uuid"` - Name string `json:"result_name"` - Value string `json:"value"` - Category string `json:"category,omitempty"` - CategoryLocalized string `json:"category_localized,omitempty"` - CreatedOn time.Time `json:"created_on"` +// Save saves a new result in our map. The key is saved in a snakified format +func (r Results) Save(name string, value string, category string, categoryLocalized string, nodeUUID NodeUUID, input string, createdOn time.Time) { + r[utils.Snakify(name)] = &Result{ + Name: name, + Value: value, + Category: category, + CategoryLocalized: categoryLocalized, + NodeUUID: nodeUUID, + Input: input, + CreatedOn: createdOn, + } } -// UnmarshalJSON is our custom unmarshalling of a Result object -func (r *Result) UnmarshalJSON(data []byte) error { - var re resultEnvelope - var err error - - err = json.Unmarshal(data, &re) - r.node = re.Node - r.name = re.Name - r.value = re.Value - r.category = re.Category - r.categoryLocalized = re.CategoryLocalized - r.createdOn = re.CreatedOn +// Resolve resolves the passed in key, which is snakified before lookup +func (r Results) Resolve(key string) interface{} { + key = utils.Snakify(key) + result, ok := r[key] + if !ok { + return nil + } - return err + return result } -// MarshalJSON is our custom marshalling of a Result object -func (r *Result) MarshalJSON() ([]byte, error) { - var re resultEnvelope - - re.Node = r.node - re.Name = r.name - re.Value = r.value - re.Category = r.category - re.CategoryLocalized = r.categoryLocalized - re.CreatedOn = r.createdOn +// Default returns the default value for our Results, which is the entire map +func (r Results) Default() interface{} { + return r +} - return json.Marshal(re) +// String returns the string representation of our Results, which is a key/value pairing of our fields +func (r Results) String() string { + results := make([]string, 0, len(r)) + for _, v := range r { + results = append(results, fmt.Sprintf("%s: %s", v.Name, v.Value)) + } + return strings.Join(results, ", ") } + +var _ utils.VariableResolver = (*Results)(nil) diff --git a/flows/routers/first.go b/flows/routers/first.go index 9938ec5de..c32edafd4 100644 --- a/flows/routers/first.go +++ b/flows/routers/first.go @@ -26,10 +26,10 @@ func (r *FirstRouter) Validate(exits []flows.Exit) error { } // PickRoute always picks the first exit if available for this router -func (r *FirstRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (flows.Route, error) { +func (r *FirstRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (interface{}, flows.Route, error) { if len(exits) == 0 { - return flows.NoRoute, nil + return nil, flows.NoRoute, nil } - return flows.NewRoute(exits[0].UUID(), ""), nil + return nil, flows.NewRoute(exits[0].UUID(), ""), nil } diff --git a/flows/routers/random.go b/flows/routers/random.go index ee171cb94..6a8f78745 100644 --- a/flows/routers/random.go +++ b/flows/routers/random.go @@ -30,13 +30,13 @@ func (r *RandomRouter) Validate(exits []flows.Exit) error { } // PickRoute picks a route randomly from our available exits -func (r *RandomRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (flows.Route, error) { +func (r *RandomRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (interface{}, flows.Route, error) { if len(exits) == 0 { - return flows.NoRoute, nil + return nil, flows.NoRoute, nil } // pick a random exit random := rand.New(rand.NewSource(time.Now().UnixNano())) exitN := random.Intn(len(exits)) - return flows.NewRoute(exits[exitN].UUID(), fmt.Sprintf("%d", exitN)), nil + return nil, flows.NewRoute(exits[exitN].UUID(), fmt.Sprintf("%d", exitN)), nil } diff --git a/flows/routers/random_once.go b/flows/routers/random_once.go index 560fd1782..b95577779 100644 --- a/flows/routers/random_once.go +++ b/flows/routers/random_once.go @@ -50,9 +50,9 @@ func (r *RandomOnceRouter) Validate(exits []flows.Exit) error { // PickRoute will attempt to take a random exit it hasn't taken before. If all exits have been taken, then it will // take the exit specified in it's Exit parameter -func (r *RandomOnceRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (flows.Route, error) { +func (r *RandomOnceRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (interface{}, flows.Route, error) { if len(exits) == 0 { - return flows.NoRoute, nil + return nil, flows.NoRoute, nil } // find all the exits we have taken @@ -74,11 +74,11 @@ func (r *RandomOnceRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step // no valid choices? exit! if len(validExits) == 0 { - return flows.NewRoute(r.Exit, "0"), nil + return nil, flows.NewRoute(r.Exit, "0"), nil } // ok, now pick one randomly random := rand.New(rand.NewSource(time.Now().UnixNano())) exitN := random.Intn(len(validExits)) - return flows.NewRoute(validExits[exitN], string(exitN)), nil + return nil, flows.NewRoute(validExits[exitN], string(exitN)), nil } diff --git a/flows/routers/switch.go b/flows/routers/switch.go index da53a73e9..1becd415c 100644 --- a/flows/routers/switch.go +++ b/flows/routers/switch.go @@ -71,7 +71,7 @@ func (r *SwitchRouter) Validate(exits []flows.Exit) error { // PickRoute evaluates each of the tests on our cases in order, returning the exit for the first case which // evaluates to a true. If no cases evaluate to true, then the default exit (if specified) is returned -func (r *SwitchRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (flows.Route, error) { +func (r *SwitchRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flows.Step) (interface{}, flows.Route, error) { env := run.Environment() // first evaluate our operand @@ -87,7 +87,7 @@ func (r *SwitchRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flo // try to look up our function xtest := excellent.XTESTS[test] if xtest == nil { - return flows.NoRoute, fmt.Errorf("Unknown test '%s', taking no exit", c.Type) + return operand, flows.NoRoute, fmt.Errorf("Unknown test '%s', taking no exit", c.Type) } // build our argument list @@ -110,23 +110,23 @@ func (r *SwitchRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flo rawResult := xtest(env, args...) err, isErr := rawResult.(error) if isErr { - return flows.NoRoute, err + return operand, flows.NoRoute, err } // ok, not an error, must be an XTestResult result, isResult := rawResult.(excellent.XTestResult) if !isResult { - return flows.NoRoute, fmt.Errorf("Unexpected result type from test %v: %#v", xtest, result) + return operand, flows.NoRoute, fmt.Errorf("Unexpected result type from test %v: %#v", xtest, result) } // looks truthy, lets return this exit if result.Matched() { asStr, err := utils.ToString(env, result.Match()) if err != nil { - return flows.NoRoute, err + return operand, flows.NoRoute, err } - return flows.NewRoute(c.ExitUUID, asStr), nil + return operand, flows.NewRoute(c.ExitUUID, asStr), nil } } @@ -138,9 +138,9 @@ func (r *SwitchRouter) PickRoute(run flows.FlowRun, exits []flows.Exit, step flo run.AddError(step, nil, err) } - return flows.NewRoute(r.Default, value), nil + return operand, flows.NewRoute(r.Default, value), nil } // no matches, no defaults, no route - return flows.NoRoute, nil + return operand, flows.NoRoute, nil } diff --git a/flows/runs/run.go b/flows/runs/run.go index 1fe397422..6c871d2d9 100644 --- a/flows/runs/run.go +++ b/flows/runs/run.go @@ -88,7 +88,7 @@ type flowRun struct { input flows.Input parent flows.FlowRun - results *flows.Results + results flows.Results path []flows.Step status flows.RunStatus @@ -127,7 +127,7 @@ func (r *flowRun) Contact() *flows.Contact { return r.contact } func (r *flowRun) SetContact(contact *flows.Contact) { r.contact = contact } func (r *flowRun) Context() utils.VariableResolver { return r.context } -func (r *flowRun) Results() *flows.Results { return r.results } +func (r *flowRun) Results() flows.Results { return r.results } func (r *flowRun) Exit(status flows.RunStatus) { r.SetStatus(status) @@ -332,7 +332,7 @@ type runEnvelope struct { Status flows.RunStatus `json:"status"` ParentUUID flows.RunUUID `json:"parent_uuid,omitempty"` - Results *flows.Results `json:"results,omitempty"` + Results flows.Results `json:"results,omitempty"` Input *utils.TypedEnvelope `json:"input,omitempty"` Webhook *utils.RequestResponse `json:"webhook,omitempty"` Extra json.RawMessage `json:"extra,omitempty"` diff --git a/flows/runsummary.go b/flows/runsummary.go index bce38d197..8b43f2931 100644 --- a/flows/runsummary.go +++ b/flows/runsummary.go @@ -11,14 +11,14 @@ type runSummary struct { flow Flow contact *Contact status RunStatus - results *Results + results Results } func (r *runSummary) UUID() RunUUID { return r.uuid } func (r *runSummary) Flow() Flow { return r.flow } func (r *runSummary) Contact() *Contact { return r.contact } func (r *runSummary) Status() RunStatus { return r.status } -func (r *runSummary) Results() *Results { return r.results } +func (r *runSummary) Results() Results { return r.results } func NewRunSummaryFromRun(run FlowRun) RunSummary { return &runSummary{ @@ -41,7 +41,7 @@ type runSummaryEnvelope struct { FlowUUID FlowUUID `json:"flow_uuid" validate:"uuid4"` Contact json.RawMessage `json:"contact" validate:"required"` Status RunStatus `json:"status" validate:"required"` - Results *Results `json:"results"` + Results Results `json:"results"` } func ReadRunSummary(session Session, data json.RawMessage) (RunSummary, error) { From 560a1bb61348933928aedfeae6bc17dd65b36f8a Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 30 Oct 2017 14:25:56 -0500 Subject: [PATCH 2/3] Use title case for result name examples --- cmd/flowrunner/testdata/flows/all_actions.json | 2 +- cmd/flowrunner/testdata/flows/all_actions_test.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/flowrunner/testdata/flows/all_actions.json b/cmd/flowrunner/testdata/flows/all_actions.json index ac2bc2a26..c4fcba353 100644 --- a/cmd/flowrunner/testdata/flows/all_actions.json +++ b/cmd/flowrunner/testdata/flows/all_actions.json @@ -123,7 +123,7 @@ { "uuid": "5508e6a7-26ce-4b3b-b32e-bb4e2e614f5d", "type": "save_flow_result", - "name": "gender", + "name": "Gender", "value": "m", "category": "Male" }, diff --git a/cmd/flowrunner/testdata/flows/all_actions_test.json b/cmd/flowrunner/testdata/flows/all_actions_test.json index 8865ff720..4ffd898a6 100644 --- a/cmd/flowrunner/testdata/flows/all_actions_test.json +++ b/cmd/flowrunner/testdata/flows/all_actions_test.json @@ -268,7 +268,7 @@ "event": { "category": "Male", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "name": "gender", + "name": "Gender", "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", "type": "save_flow_result", "value": "m" @@ -586,7 +586,7 @@ { "category": "Male", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "name": "gender", + "name": "Gender", "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", "type": "save_flow_result", "value": "m" @@ -626,7 +626,7 @@ "category": "Male", "created_on": "2000-01-01T00:00:00.000000000-00:00", "input": "", - "name": "gender", + "name": "Gender", "node_uuid": "a58be63b-907d-4a1a-856b-0bb5579d7507", "value": "m" } From 333ab86276158010dba86216d96767b81f17bbe1 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 31 Oct 2017 11:41:55 -0500 Subject: [PATCH 3/3] Add example where has_any_word test produces different input and value in a result --- .../testdata/flows/two_questions.json | 12 ++++---- .../testdata/flows/two_questions_test.json | 28 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/flowrunner/testdata/flows/two_questions.json b/cmd/flowrunner/testdata/flows/two_questions.json index 84e2bd365..c6e423068 100644 --- a/cmd/flowrunner/testdata/flows/two_questions.json +++ b/cmd/flowrunner/testdata/flows/two_questions.json @@ -14,13 +14,13 @@ ] }, "98503572-25bf-40ce-ad72-8836b6549a38": { - "test": [ + "arguments": [ "rouge" ] }, "a51e5c8c-c891-401d-9c62-15fc37278c94": { - "test": [ - "blue" + "arguments": [ + "bleu" ] }, "598ae7a5-2f81-48f1-afac-595262514aa1": { @@ -30,7 +30,7 @@ }, "c70fe86c-9aac-4cc2-a5cb-d35cbe3fed6e": { "name": [ - "Blue" + "Bleu" ] }, "78ae8f05-f92e-43b2-a886-406eaea1b8e0": { @@ -40,7 +40,7 @@ }, "d2a4052a-3fa9-4608-ab3e-5b9631440447": { "text": [ - "@(TITLE(run.input.text))! Bien sur! Quelle est votes soda preferee? (pepsi/coke)" + "@(TITLE(run.results.favorite_color.category_localized))! Bien sur! Quelle est votes soda preferee? (pepsi/coke)" ] }, "e27c3bce-1095-4d08-9164-dc4530a0688a": { @@ -143,7 +143,7 @@ { "uuid": "d2a4052a-3fa9-4608-ab3e-5b9631440447", "type": "reply", - "text": "@(TITLE(run.input.text)) it is! What is your favorite soda? (pepsi/coke)" + "text": "@(TITLE(run.results.favorite_color.category_localized)) it is! What is your favorite soda? (pepsi/coke)" } ], "wait": { diff --git a/cmd/flowrunner/testdata/flows/two_questions_test.json b/cmd/flowrunner/testdata/flows/two_questions_test.json index 7d9bc47d9..1f023f20b 100644 --- a/cmd/flowrunner/testdata/flows/two_questions_test.json +++ b/cmd/flowrunner/testdata/flows/two_questions_test.json @@ -13,7 +13,7 @@ }, "created_on": "2000-01-01T00:00:00.000000000-00:00", "msg_uuid": "84f8a3cf-0f2c-4881-9502-2d7b114bf01f", - "text": "Blue", + "text": "I like blue!", "type": "msg_received", "urn": "tel:+12065551212" } @@ -147,11 +147,11 @@ "event": { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "input": "Blue", + "input": "I like blue!", "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", "type": "save_flow_result", - "value": "Blue" + "value": "blue" }, "step_uuid": "" }, @@ -226,7 +226,7 @@ "input": { "channel_uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "text": "Blue", + "text": "I like blue!", "type": "msg", "urn": "tel:+12065551212", "uuid": "84f8a3cf-0f2c-4881-9502-2d7b114bf01f" @@ -262,18 +262,18 @@ }, "created_on": "2000-01-01T00:00:00.000000000-00:00", "msg_uuid": "84f8a3cf-0f2c-4881-9502-2d7b114bf01f", - "text": "Blue", + "text": "I like blue!", "type": "msg_received", "urn": "tel:+12065551212" }, { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "input": "Blue", + "input": "I like blue!", "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", "type": "save_flow_result", - "value": "Blue" + "value": "blue" } ], "exit_uuid": "c70fe86c-9aac-4cc2-a5cb-d35cbe3fed6e", @@ -315,10 +315,10 @@ "favorite_color": { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "input": "Blue", + "input": "I like blue!", "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "value": "Blue" + "value": "blue" } }, "status": "waiting", @@ -456,18 +456,18 @@ }, "created_on": "2000-01-01T00:00:00.000000000-00:00", "msg_uuid": "84f8a3cf-0f2c-4881-9502-2d7b114bf01f", - "text": "Blue", + "text": "I like blue!", "type": "msg_received", "urn": "tel:+12065551212" }, { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "input": "Blue", + "input": "I like blue!", "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", "type": "save_flow_result", - "value": "Blue" + "value": "blue" } ], "exit_uuid": "c70fe86c-9aac-4cc2-a5cb-d35cbe3fed6e", @@ -563,10 +563,10 @@ "favorite_color": { "category": "Blue", "created_on": "2000-01-01T00:00:00.000000000-00:00", - "input": "Blue", + "input": "I like blue!", "name": "Favorite Color", "node_uuid": "46d51f50-58de-49da-8d13-dadbf322685d", - "value": "Blue" + "value": "blue" }, "soda": { "category": "Coke",