67 lines
2.7 KiB
C#
67 lines
2.7 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class ExecutionsEndpointsTests : IClassFixture<WebFactory>
|
|
{
|
|
private readonly WebFactory _factory;
|
|
public ExecutionsEndpointsTests(WebFactory f) => _factory = f;
|
|
|
|
private async Task<HttpClient> LoggedIn()
|
|
{
|
|
var c = _factory.CreateClient(new() { HandleCookies = true, AllowAutoRedirect = false });
|
|
await c.PostAsJsonAsync("/api/session", new { password = _factory.AdminPassword });
|
|
return c;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Manual_run_of_workflow_with_single_webhook_trigger_produces_completed_execution()
|
|
{
|
|
var c = await LoggedIn();
|
|
var graph = new
|
|
{
|
|
nodes = new object[]
|
|
{
|
|
new { id = "t", type_id = "http.webhook", config = new { path = "manual" } },
|
|
new { id = "r", type_id = "http.response", config = new { status = 204, body = "" } },
|
|
},
|
|
edges = new[] { new { from_node = "t", from_port = 0, to_node = "r", to_port = 0 } },
|
|
};
|
|
var create = await c.PostAsJsonAsync("/api/workflows", new { name = "manual-wf", graph });
|
|
var wf = await create.Content.ReadFromJsonAsync<JsonElement>();
|
|
var wfId = wf.GetProperty("id").GetString()!;
|
|
|
|
var run = await c.PostAsJsonAsync($"/api/workflows/{wfId}/executions",
|
|
new { startFromNodeId = "t", triggerData = new { hello = "world" } });
|
|
Assert.Equal(HttpStatusCode.Accepted, run.StatusCode);
|
|
var runBody = await run.Content.ReadFromJsonAsync<JsonElement>();
|
|
var eid = runBody.GetProperty("executionId").GetString()!;
|
|
|
|
// Poll for completion (executor is in-process; this returns nearly synchronously).
|
|
JsonElement detail = default;
|
|
for (var i = 0; i < 20; i++)
|
|
{
|
|
detail = await c.GetFromJsonAsync<JsonElement>($"/api/executions/{eid}");
|
|
if (detail.GetProperty("status").GetString() != "running") break;
|
|
await Task.Delay(50);
|
|
}
|
|
Assert.Equal("completed", detail.GetProperty("status").GetString());
|
|
var nodes = detail.GetProperty("nodes");
|
|
Assert.Equal(2, nodes.GetArrayLength());
|
|
|
|
var list = await c.GetFromJsonAsync<JsonElement>($"/api/workflows/{wfId}/executions");
|
|
Assert.True(list.GetArrayLength() >= 1);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Manual_run_returns_404_for_unknown_workflow()
|
|
{
|
|
var c = await LoggedIn();
|
|
var res = await c.PostAsJsonAsync("/api/workflows/nope/executions",
|
|
new { startFromNodeId = "t", triggerData = new { } });
|
|
Assert.Equal(HttpStatusCode.NotFound, res.StatusCode);
|
|
}
|
|
}
|