using System.Net; using System.Net.Http.Json; using FluentAssertions; using Microsoft.AspNetCore.Mvc.Testing; using StellaOps.SbomService.Models; namespace StellaOps.SbomService.Tests; public class EntrypointEndpointsTests : IClassFixture> { private readonly WebApplicationFactory _factory; public EntrypointEndpointsTests(WebApplicationFactory factory) { _factory = factory; } [Fact] public async Task Get_entrypoints_requires_tenant() { var client = _factory.CreateClient(); var response = await client.GetAsync("/entrypoints"); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); } [Fact] public async Task Get_entrypoints_returns_seeded_list() { var client = _factory.CreateClient(); var response = await client.GetAsync("/entrypoints?tenant=tenant-a"); response.EnsureSuccessStatusCode(); var payload = await response.Content.ReadFromJsonAsync(); payload.Should().NotBeNull(); payload!.Tenant.Should().Be("tenant-a"); payload.Items.Should().NotBeEmpty(); payload.Items.Select(e => e.Artifact).Should().Contain("ghcr.io/stellaops/sample-api"); } [Fact] public async Task Post_entrypoints_upserts_and_returns_ordered_list() { var client = _factory.CreateClient(); var upsert = new EntrypointUpsertRequest( Tenant: "tenant-a", Artifact: "ghcr.io/stellaops/sample-api", Service: "web", Path: "/api/v2", Scope: "runtime", RuntimeFlag: true); var post = await client.PostAsJsonAsync("/entrypoints", upsert); post.EnsureSuccessStatusCode(); var payload = await post.Content.ReadFromJsonAsync(); payload.Should().NotBeNull(); payload!.Items.First(e => e.Service == "web").Path.Should().Be("/api/v2"); payload.Items.Should().BeInAscendingOrder(e => e.Artifact); } }