73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using StellaOps.Notifier.Tests.Support;
|
|
using StellaOps.Notifier.WebService.Contracts;
|
|
using StellaOps.Notify.Queue;
|
|
using Xunit;
|
|
|
|
#if false
|
|
namespace StellaOps.Notifier.Tests;
|
|
|
|
public sealed class RiskEventEndpointTests : IClassFixture<NotifierApplicationFactory>
|
|
{
|
|
private readonly NotifierApplicationFactory _factory;
|
|
|
|
public RiskEventEndpointTests(NotifierApplicationFactory factory)
|
|
{
|
|
_factory = factory;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Risk_event_is_published_to_queue()
|
|
{
|
|
var recordingQueue = new RecordingNotifyEventQueue();
|
|
|
|
var client = _factory.WithWebHostBuilder(builder =>
|
|
{
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
services.RemoveAll<INotifyEventQueue>();
|
|
services.AddSingleton<INotifyEventQueue>(recordingQueue);
|
|
});
|
|
}).CreateClient();
|
|
|
|
var request = new RiskEventRequest
|
|
{
|
|
EventId = Guid.NewGuid(),
|
|
Kind = "risk.profile.severity.changed",
|
|
Actor = "risk-engine",
|
|
Timestamp = DateTimeOffset.Parse("2025-11-24T00:00:00Z"),
|
|
Payload = new System.Text.Json.Nodes.JsonObject
|
|
{
|
|
["profile"] = new System.Text.Json.Nodes.JsonObject
|
|
{
|
|
["id"] = "stellaops://risk/profile/example@2025.11",
|
|
["version"] = "2025.11"
|
|
},
|
|
["previous"] = new System.Text.Json.Nodes.JsonObject { ["severity"] = "medium" },
|
|
["current"] = new System.Text.Json.Nodes.JsonObject { ["severity"] = "high" }
|
|
}
|
|
};
|
|
|
|
var message = new HttpRequestMessage(HttpMethod.Post, "/api/v1/notify/risk-events")
|
|
{
|
|
Content = JsonContent.Create(request)
|
|
};
|
|
message.Headers.Add("X-StellaOps-Tenant", "tenant-sample");
|
|
|
|
var response = await client.SendAsync(message, TestContext.Current.CancellationToken);
|
|
|
|
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
|
|
Assert.Single(recordingQueue.Published);
|
|
|
|
var published = recordingQueue.Published.Single();
|
|
Assert.Equal("risk.profile.severity.changed", published.Event.Kind);
|
|
Assert.Equal("tenant-sample", published.Event.Tenant);
|
|
Assert.Equal("notify:events", published.Stream);
|
|
}
|
|
}
|
|
#endif
|