82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using w4c_workflows.Controllers;
|
|
using w4c_workflows.Models.Nodes;
|
|
using w4c_workflows.Services.Nodes;
|
|
using Xunit;
|
|
|
|
namespace w4c_workflows.Tests;
|
|
|
|
public class NodesControllerTests
|
|
{
|
|
private static NodesController Create() => new(
|
|
new NodeBlueprintCatalog(NodeBlueprintCatalog.LoadEmbedded()),
|
|
new NodeExecutorRegistry(Array.Empty<INodeExecutor>()));
|
|
|
|
[Fact]
|
|
public void List_returns_core_nodes_with_port_shape()
|
|
{
|
|
var result = Create().List(search: null, kind: null, category: null);
|
|
|
|
var ok = Assert.IsType<OkObjectResult>(result);
|
|
var items = Assert.IsAssignableFrom<IEnumerable<NodeSummary>>(ok.Value).ToList();
|
|
|
|
var branch = items.Single(n => n.Type == "core.if");
|
|
Assert.Equal(2, branch.Outputs);
|
|
Assert.False(branch.HasErrorBranch);
|
|
|
|
var request = items.Single(n => n.Type == "core.httpRequest");
|
|
Assert.True(request.HasErrorBranch);
|
|
}
|
|
|
|
[Fact]
|
|
public void List_filters_by_kind()
|
|
{
|
|
var ok = (OkObjectResult)Create().List(search: null, kind: NodeKind.Control, category: null);
|
|
var items = ((IEnumerable<NodeSummary>)ok.Value!).ToList();
|
|
|
|
Assert.Contains(items, n => n.Type == "core.if");
|
|
Assert.DoesNotContain(items, n => n.Type == "core.httpRequest");
|
|
}
|
|
|
|
[Fact]
|
|
public void Get_returns_blueprint_detail()
|
|
{
|
|
var ok = Assert.IsType<OkObjectResult>(Create().Get("core.set", null));
|
|
var detail = Assert.IsType<NodeDetail>(ok.Value);
|
|
|
|
Assert.Equal("core.set", detail.Blueprint.Type);
|
|
Assert.False(detail.Runnable); // no executors installed yet
|
|
}
|
|
|
|
[Fact]
|
|
public void Get_unknown_type_returns_404()
|
|
{
|
|
Assert.IsType<NotFoundObjectResult>(Create().Get("does.not.exist", null));
|
|
}
|
|
|
|
[Fact]
|
|
public void Categories_are_exposed()
|
|
{
|
|
var ok = (OkObjectResult)Create().Categories();
|
|
var categories = Assert.IsAssignableFrom<IReadOnlyList<string>>(ok.Value);
|
|
|
|
Assert.Contains("Core", categories);
|
|
}
|
|
|
|
[Fact]
|
|
public void List_hides_nodes_barred_by_the_permission_policy()
|
|
{
|
|
var permissions = EgressTestData.Permissions(o => o.DenyTypes.Add("core.code"));
|
|
var controller = new NodesController(
|
|
new NodeBlueprintCatalog(NodeBlueprintCatalog.LoadEmbedded()),
|
|
new NodeExecutorRegistry(Array.Empty<INodeExecutor>()),
|
|
permissions);
|
|
|
|
var ok = (OkObjectResult)controller.List(search: null, kind: null, category: null);
|
|
var items = ((IEnumerable<NodeSummary>)ok.Value!).ToList();
|
|
|
|
Assert.DoesNotContain(items, n => n.Type == "core.code");
|
|
Assert.Contains(items, n => n.Type == "core.noop");
|
|
}
|
|
}
|