Files
VolcanicCore/tests/VolcanicCore.Tests/WebResponseNodeTests.cs

57 lines
2.1 KiB
C#

using System.Text.Json;
using Microsoft.Extensions.Logging.Abstractions;
using VolcanicCore.Api.Engine;
using VolcanicCore.Core;
using VolcanicCore.Nodes;
// ImplicitUsings pulls System.Threading → collision with our ExecutionContext.
using ExecutionContext = VolcanicCore.Api.Engine.ExecutionContext;
namespace VolcanicCore.Tests;
public class WebResponseNodeTests
{
private sealed class NullReg : IConnectionInstanceRegistry
{
public Task<object> GetAsync(string id, CancellationToken ct) => throw new InvalidOperationException();
}
[Fact]
public async Task Resolves_router_with_configured_status_and_body_and_returns_no_outputs()
{
var router = new WebhookRouter();
var channel = Guid.NewGuid();
var wait = router.Register(channel, TimeSpan.FromSeconds(5));
var node = new WebResponseNode(router);
var ctx = new ExecutionContext("e", "wf", "n",
JsonDocument.Parse("""{"status":201,"body":"created","contentType":"text/plain"}""").RootElement,
channel, NullLogger.Instance, null, new NullReg());
var outputs = await node.ExecuteAsync(ctx,
new IReadOnlyList<Item>[] { new [] { new Item(JsonDocument.Parse("{}").RootElement) } },
CancellationToken.None);
Assert.Empty(outputs);
var payload = await wait;
Assert.NotNull(payload);
Assert.Equal(201, payload!.StatusCode);
Assert.Equal("created", payload.Body);
Assert.Equal("text/plain", payload.ContentType);
}
[Fact]
public async Task Missing_answer_channel_is_a_noop_but_does_not_throw()
{
var router = new WebhookRouter();
var node = new WebResponseNode(router);
var ctx = new ExecutionContext("e", "wf", "n",
JsonDocument.Parse("""{"status":200,"body":""}""").RootElement,
answerChannelId: null, NullLogger.Instance, null, new NullReg());
var outputs = await node.ExecuteAsync(ctx,
new IReadOnlyList<Item>[] { Array.Empty<Item>() }, CancellationToken.None);
Assert.Empty(outputs);
}
}