62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using System.Net;
|
|
using System.Net.Http.Headers;
|
|
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using StellaOps.Concelier.WebService.Tests.Fixtures;
|
|
using Xunit;
|
|
|
|
|
|
using StellaOps.TestKit;
|
|
namespace StellaOps.Concelier.WebService.Tests;
|
|
|
|
public class ConcelierTimelineEndpointTests : IClassFixture<ConcelierApplicationFactory>
|
|
{
|
|
private readonly WebApplicationFactory<Program> _factory;
|
|
|
|
public ConcelierTimelineEndpointTests(ConcelierApplicationFactory factory)
|
|
{
|
|
_factory = factory.WithWebHostBuilder(_ => { });
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public async Task Timeline_requires_tenant_header()
|
|
{
|
|
var client = _factory.CreateClient();
|
|
|
|
var response = await client.GetAsync("/obs/concelier/timeline");
|
|
|
|
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public async Task Timeline_returns_sse_event()
|
|
{
|
|
var client = _factory.CreateClient();
|
|
client.DefaultRequestHeaders.Add("X-Stella-Tenant", "tenant-a");
|
|
|
|
using var request = new HttpRequestMessage(HttpMethod.Get, "/obs/concelier/timeline");
|
|
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/event-stream"));
|
|
|
|
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
var stream = await response.Content.ReadAsStreamAsync();
|
|
using var reader = new StreamReader(stream);
|
|
// The SSE stream may start with a retry directive; skip non-event lines.
|
|
string? line;
|
|
string? eventLine = null;
|
|
while ((line = await reader.ReadLineAsync()) is not null)
|
|
{
|
|
if (line.StartsWith("event:", StringComparison.Ordinal))
|
|
{
|
|
eventLine = line;
|
|
break;
|
|
}
|
|
}
|
|
eventLine.Should().NotBeNull();
|
|
eventLine!.Should().StartWith("event: ingest.update");
|
|
}
|
|
}
|