diff --git a/crates/core/src/runtime/functions/control.rs b/crates/core/src/runtime/functions/control.rs index a601cf7..6be61e7 100644 --- a/crates/core/src/runtime/functions/control.rs +++ b/crates/core/src/runtime/functions/control.rs @@ -62,7 +62,8 @@ fn r#if( ctx.push_runtime_trace_label("branch=if".to_string()); run(*if_pointer, ctx) } else { - Signal::Return(Value { + ctx.push_runtime_trace_label("branch=else".to_string()); + Signal::Success(Value { kind: Some(Kind::NullValue(0)), }) } diff --git a/crates/tests/src/main.rs b/crates/tests/src/main.rs index 29ae8c3..61561cf 100644 --- a/crates/tests/src/main.rs +++ b/crates/tests/src/main.rs @@ -51,29 +51,25 @@ impl Testable for Case { "name": err.name, "message": err.message, }); - return CaseResult::Failure(input, json); + if json != input.clone().expected_result { + return CaseResult::Failure(input, json); + } } taurus_core::context::signal::Signal::Success(value) => { let json = to_json_value(value); - if json == input.clone().expected_result { - return CaseResult::Success; - } else { + if json != input.clone().expected_result { return CaseResult::Failure(input, json); } } taurus_core::context::signal::Signal::Return(value) => { let json = to_json_value(value); - if json == input.clone().expected_result { - return CaseResult::Success; - } else { + if json != input.clone().expected_result { return CaseResult::Failure(input, json); } } taurus_core::context::signal::Signal::Respond(value) => { let json = to_json_value(value); - if json == input.clone().expected_result { - return CaseResult::Success; - } else { + if json != input.clone().expected_result { return CaseResult::Failure(input, json); } } diff --git a/flows/01_return_object.json b/flows/01_return_object.json index 80105fd..c6e8290 100644 --- a/flows/01_return_object.json +++ b/flows/01_return_object.json @@ -5,7 +5,7 @@ { "input": null, "expected_result": { - "status_code": 200, + "http_status_code": 200, "headers": { "Header": "X" }, diff --git a/flows/02_return_flow_input.json b/flows/02_return_flow_input.json index 3074d27..227f692 100644 --- a/flows/02_return_flow_input.json +++ b/flows/02_return_flow_input.json @@ -5,7 +5,7 @@ { "input": null, "expected_result": { - "status_code": 200, + "http_status_code": 200, "headers": { "Authentication": "X" }, @@ -23,7 +23,7 @@ ] }, "expected_result": { - "status_code": 200, + "http_status_code": 200, "headers": { "Authentication": "X" }, diff --git a/flows/04_example_action.json b/flows/04_example_action.json index c0b5c96..07256e8 100644 --- a/flows/04_example_action.json +++ b/flows/04_example_action.json @@ -5,11 +5,8 @@ { "input": null, "expected_result": { - "status_code": 200, - "headers": { - "Header": "X" - }, - "payload": "Hello World" + "message": "Remote runtime not configured", + "name": "RemoteRuntimeNotConfigured" } } ], diff --git a/flows/05_if_control.json b/flows/05_if_control.json new file mode 100644 index 0000000..5d26fac --- /dev/null +++ b/flows/05_if_control.json @@ -0,0 +1,220 @@ +{ + "name": "05_if_control", + "description": "This flow expects an object as input (from http request) structured payload.test = bool which the flow will return", + "inputs": [ + { + "input": { + "http_method": "GET", + "headers": { + "Content-Type": "text/plain" + }, + "payload": { + "test": 1 + } + }, + "expected_result": { + "message": "Expected a bool value but received [Eval(Value { kind: Some(NumberValue(NumberValue { number: Some(Integer(1)) })) }), Thunk(12)]", + "name": "InvalidArgumentRuntimeError" + } + }, + { + "input": { + "http_method": "GET", + "headers": { + "Content-Type": "text/plain" + }, + "payload": { + "test": false + } + }, + "expected_result": { + "http_status_code": 200, + "headers": {}, + "payload": "Blub" + } + }, + { + "input": { + "http_method": "GET", + "headers": { + "Content-Type": "text/plain" + }, + "payload": { + "test": true + } + }, + "expected_result": { + "http_status_code": 200, + "headers": {}, + "payload": true + } + } + ], + "flow": { + "flowId": "2", + "projectId": "1", + "type": "REST", + "settings": [ + { + "databaseId": "3", + "flowSettingId": "httpURL", + "value": { + "stringValue": "/test2" + } + }, + { + "databaseId": "4", + "flowSettingId": "httpMethod", + "value": { + "stringValue": "GET" + } + } + ], + "startingNodeId": "11", + "nodeFunctions": [ + { + "databaseId": "13", + "runtimeFunctionId": "rest::control::respond", + "parameters": [ + { + "databaseId": "57", + "runtimeParameterId": "http_response", + "value": { + "referenceValue": { + "nodeId": "14" + } + } + } + ] + }, + { + "databaseId": "14", + "runtimeFunctionId": "http::response::create", + "parameters": [ + { + "databaseId": "54", + "runtimeParameterId": "http_status_code", + "value": { + "literalValue": { + "numberValue": { + "integer": "200" + } + } + } + }, + { + "databaseId": "55", + "runtimeParameterId": "headers", + "value": { + "literalValue": { + "structValue": {} + } + } + }, + { + "databaseId": "56", + "runtimeParameterId": "payload", + "value": { + "literalValue": { + "stringValue": "Blub" + } + } + } + ], + "nextNodeId": "13" + }, + { + "databaseId": "11", + "runtimeFunctionId": "std::control::if", + "parameters": [ + { + "databaseId": "49", + "runtimeParameterId": "condition", + "value": { + "referenceValue": { + "paths": [ + { + "path": "payload" + }, + { + "path": "test" + } + ], + "flowInput": {} + } + } + }, + { + "databaseId": "50", + "runtimeParameterId": "runnable", + "value": { + "nodeFunctionId": "12" + } + } + ], + "nextNodeId": "14" + }, + { + "databaseId": "15", + "runtimeFunctionId": "rest::control::respond", + "parameters": [ + { + "databaseId": "58", + "runtimeParameterId": "http_response", + "value": { + "referenceValue": { + "nodeId": "12" + } + } + } + ] + }, + { + "databaseId": "12", + "runtimeFunctionId": "http::response::create", + "parameters": [ + { + "databaseId": "51", + "runtimeParameterId": "http_status_code", + "value": { + "literalValue": { + "numberValue": { + "integer": "200" + } + } + } + }, + { + "databaseId": "52", + "runtimeParameterId": "headers", + "value": { + "literalValue": { + "structValue": {} + } + } + }, + { + "databaseId": "53", + "runtimeParameterId": "payload", + "value": { + "referenceValue": { + "paths": [ + { + "path": "payload" + }, + { + "path": "test" + } + ], + "flowInput": {} + } + } + } + ], + "nextNodeId": "15" + } + ], + "projectSlug": "codezero-project", + "signature": "(httpURL: HTTP_URL, httpMethod: HTTP_METHOD): { payload: { test: BOOLEAN }, headers: { test: TEXT } }" + } +} diff --git a/flows/06_if_else_control.json b/flows/06_if_else_control.json new file mode 100644 index 0000000..04e9d12 --- /dev/null +++ b/flows/06_if_else_control.json @@ -0,0 +1,218 @@ +{ + "name": "06_if_else_control", + "description": "This flow expects an object as input (from http request) structured payload.test = bool which the flow will return", + "inputs": [ + { + "input": { + "http_method": "GET", + "headers": { + "Content-Type": "text/plain" + }, + "payload": { + "test": 1 + } + }, + "expected_result": { + "message": "Expected a bool value but received [Eval(Value { kind: Some(NumberValue(NumberValue { number: Some(Integer(1)) })) }), Thunk(19), Thunk(17)]", + "name": "InvalidArgumentRuntimeError" + } + }, + { + "input": { + "http_method": "GET", + "headers": { + "Content-Type": "text/plain" + }, + "payload": { + "test": true + } + }, + "expected_result": { + "http_status_code": 200, + "headers": {}, + "payload": "Blub" + } + }, + { + "input": { + "http_method": "GET", + "headers": { + "Content-Type": "text/plain" + }, + "payload": { + "test": false + } + }, + "expected_result": { + "http_status_code": 200, + "headers": {}, + "payload": "Blob" + } + } + ], + "flow": { + "flowId": "3", + "projectId": "1", + "type": "REST", + "settings": [ + { + "databaseId": "5", + "flowSettingId": "httpURL", + "value": { + "stringValue": "/test3" + } + }, + { + "databaseId": "6", + "flowSettingId": "httpMethod", + "value": { + "stringValue": "GET" + } + } + ], + "startingNodeId": "16", + "nodeFunctions": [ + { + "databaseId": "19", + "runtimeFunctionId": "http::response::create", + "parameters": [ + { + "databaseId": "51", + "runtimeParameterId": "http_status_code", + "value": { + "literalValue": { + "numberValue": { + "integer": "200" + } + } + } + }, + { + "databaseId": "78", + "runtimeParameterId": "headers", + "value": { + "literalValue": { + "structValue": {} + } + } + }, + { + "databaseId": "79", + "runtimeParameterId": "payload", + "value": { + "literalValue": { + "stringValue": "Blub" + } + } + } + ], + "nextNodeId": "20" + }, + { + "databaseId": "20", + "runtimeFunctionId": "rest::control::respond", + "parameters": [ + { + "databaseId": "76", + "runtimeParameterId": "http_response", + "value": { + "referenceValue": { + "nodeId": "19" + } + } + } + ] + }, + { + "databaseId": "16", + "runtimeFunctionId": "std::control::if_else", + "parameters": [ + { + "databaseId": "62", + "runtimeParameterId": "condition", + "value": { + "referenceValue": { + "paths": [ + { + "path": "payload" + }, + { + "path": "test" + } + ], + "flowInput": {} + } + } + }, + { + "databaseId": "63", + "runtimeParameterId": "runnable", + "value": { + "nodeFunctionId": "19" + } + }, + { + "databaseId": "68", + "runtimeParameterId": "else_runnable", + "value": { + "nodeFunctionId": "17" + } + } + ] + }, + { + "databaseId": "17", + "runtimeFunctionId": "http::response::create", + "parameters": [ + { + "databaseId": "72", + "runtimeParameterId": "http_status_code", + "value": { + "literalValue": { + "numberValue": { + "integer": "200" + } + } + } + }, + { + "databaseId": "73", + "runtimeParameterId": "headers", + "value": { + "literalValue": { + "structValue": {} + } + } + }, + { + "databaseId": "75", + "runtimeParameterId": "payload", + "value": { + "literalValue": { + "stringValue": "Blob" + } + } + } + ], + "nextNodeId": "18" + }, + { + "databaseId": "18", + "runtimeFunctionId": "rest::control::respond", + "parameters": [ + { + "databaseId": "64", + "runtimeParameterId": "http_response", + "value": { + "referenceValue": { + "nodeId": "17" + } + } + } + ] + } + ], + "projectSlug": "codezero-project", + "signature": "(httpURL: HTTP_URL, httpMethod: HTTP_METHOD): { payload: { test: BOOLEAN }, headers: { test: TEXT } }" + } +}