52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class DiscoveryEndpointsTests : IClassFixture<WebFactory>
|
|
{
|
|
private readonly WebFactory _factory;
|
|
public DiscoveryEndpointsTests(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 Node_types_requires_auth()
|
|
{
|
|
var c = _factory.CreateClient();
|
|
var res = await c.GetAsync("/api/node-types");
|
|
Assert.Equal(HttpStatusCode.Unauthorized, res.StatusCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Node_types_returns_five_registered_types()
|
|
{
|
|
var c = await LoggedIn();
|
|
var res = await c.GetFromJsonAsync<List<NodeTypeDto>>("/api/node-types");
|
|
Assert.NotNull(res);
|
|
var ids = res!.Select(n => n.Id).ToHashSet();
|
|
Assert.Subset(new HashSet<string>
|
|
{
|
|
"nats.hook", "nats.publish", "http.webhook", "http.response", "python.transform",
|
|
}, ids);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Connection_providers_returns_nats()
|
|
{
|
|
var c = await LoggedIn();
|
|
var res = await c.GetFromJsonAsync<List<ConnectionProviderDto>>("/api/connection-providers");
|
|
Assert.NotNull(res);
|
|
Assert.Contains(res!, p => p.Id == "nats");
|
|
}
|
|
|
|
private sealed record NodeTypeDto(string Id, string DisplayName, string Category,
|
|
int InputCount, int OutputCount, string? ConnectionProviderId, object ConfigSchema);
|
|
private sealed record ConnectionProviderDto(string Id, string DisplayName, object ConfigSchema);
|
|
}
|