using System.Net; using System.Net.Http.Headers; using FluentAssertions; using Microsoft.AspNetCore.Mvc.Testing; using Xunit; using StellaOps.TestKit; namespace StellaOps.Concelier.WebService.Tests; public class ConcelierTimelineEndpointTests : IClassFixture> { private readonly WebApplicationFactory _factory; public ConcelierTimelineEndpointTests(WebApplicationFactory 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); var firstLine = await reader.ReadLineAsync(); firstLine.Should().NotBeNull(); firstLine!.Should().StartWith("event: ingest.update"); } }