77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
using System.Text.Json;
|
|
using VolcanicCore.Api.Engine;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class WorkflowGraphParseTests
|
|
{
|
|
[Fact]
|
|
public void Nodes_without_pin_fields_get_null_pins()
|
|
{
|
|
var g = WorkflowGraph.Parse("""
|
|
{
|
|
"nodes": [{ "id": "n1", "type_id": "test.a", "config": {} }],
|
|
"edges": []
|
|
}
|
|
""");
|
|
var n = g.Nodes.Single();
|
|
Assert.Null(n.PinnedInputJson);
|
|
Assert.Null(n.PinnedOutputJson);
|
|
}
|
|
|
|
[Fact]
|
|
public void Pinned_input_object_is_stored_as_raw_json_text()
|
|
{
|
|
var g = WorkflowGraph.Parse("""
|
|
{
|
|
"nodes": [{
|
|
"id": "n1", "type_id": "test.a", "config": {},
|
|
"pinned_input": { "a": 1 }
|
|
}],
|
|
"edges": []
|
|
}
|
|
""");
|
|
Assert.Equal("""{"a":1}""",
|
|
Compact(g.Nodes.Single().PinnedInputJson!));
|
|
}
|
|
|
|
[Fact]
|
|
public void Pinned_output_array_is_stored_as_raw_json_text()
|
|
{
|
|
var g = WorkflowGraph.Parse("""
|
|
{
|
|
"nodes": [{
|
|
"id": "t", "type_id": "test.trigger", "config": {},
|
|
"pinned_output": [{ "b": 1 }, { "b": 2 }]
|
|
}],
|
|
"edges": []
|
|
}
|
|
""");
|
|
Assert.Equal("""[{"b":1},{"b":2}]""",
|
|
Compact(g.Nodes.Single().PinnedOutputJson!));
|
|
}
|
|
|
|
[Fact]
|
|
public void Explicit_null_pin_is_stored_as_null()
|
|
{
|
|
var g = WorkflowGraph.Parse("""
|
|
{
|
|
"nodes": [{
|
|
"id": "n1", "type_id": "test.a", "config": {},
|
|
"pinned_input": null, "pinned_output": null
|
|
}],
|
|
"edges": []
|
|
}
|
|
""");
|
|
var n = g.Nodes.Single();
|
|
Assert.Null(n.PinnedInputJson);
|
|
Assert.Null(n.PinnedOutputJson);
|
|
}
|
|
|
|
private static string Compact(string raw)
|
|
{
|
|
using var doc = JsonDocument.Parse(raw);
|
|
return JsonSerializer.Serialize(doc.RootElement);
|
|
}
|
|
}
|