diff --git a/tests/AHKFlowApp.API.Tests/Health/HealthControllerTests.cs b/tests/AHKFlowApp.API.Tests/Health/HealthControllerTests.cs index a1958d9..0f75e6a 100644 --- a/tests/AHKFlowApp.API.Tests/Health/HealthControllerTests.cs +++ b/tests/AHKFlowApp.API.Tests/Health/HealthControllerTests.cs @@ -3,6 +3,8 @@ using AHKFlowApp.API.Models; using AHKFlowApp.TestUtilities.Fixtures; using FluentAssertions; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Configuration; using Xunit; namespace AHKFlowApp.API.Tests.Health; @@ -62,5 +64,38 @@ public async Task GetHealth_InfrastructureEndpoint_ReturnsHealthyText() body.Should().Be("Healthy"); } + [Fact] + public async Task GetHealth_WhenResourceTierSet_ReturnsTierInResponse() + { + // Arrange + using WebApplicationFactory factory = _factory.WithWebHostBuilder(builder => + builder.ConfigureAppConfiguration((_, config) => + config.AddInMemoryCollection(new Dictionary { ["RESOURCE_TIER"] = "free" }))); + using HttpClient client = factory.CreateClient(); + + // Act + HttpResponseMessage response = await client.GetAsync("/api/v1/health"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.OK); + HealthResponse? body = await response.Content.ReadFromJsonAsync(); + body!.Tier.Should().Be("free"); + } + + [Fact] + public async Task GetHealth_WhenResourceTierAbsent_ReturnsTierNull() + { + // Arrange + using HttpClient client = _factory.CreateClient(); + + // Act + HttpResponseMessage response = await client.GetAsync("/api/v1/health"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.OK); + HealthResponse? body = await response.Content.ReadFromJsonAsync(); + body!.Tier.Should().BeNull(); + } + public void Dispose() => _factory.Dispose(); } diff --git a/tests/AHKFlowApp.TestUtilities/Builders/HealthResponseBuilder.cs b/tests/AHKFlowApp.TestUtilities/Builders/HealthResponseBuilder.cs index d6a6370..fb08c9e 100644 --- a/tests/AHKFlowApp.TestUtilities/Builders/HealthResponseBuilder.cs +++ b/tests/AHKFlowApp.TestUtilities/Builders/HealthResponseBuilder.cs @@ -54,6 +54,6 @@ public HealthResponseBuilder WithTier(string? tier) } #pragma warning disable IDE0028 // Simplify collection initialization - public HealthResponse Build() => new(_status, _version, _environment, _timestamp, new(_checks), _tier); + public HealthResponse Build() => new(_status, _version, _environment, _timestamp, new(_checks), Tier: _tier); #pragma warning restore IDE0028 // Simplify collection initialization } diff --git a/tests/AHKFlowApp.UI.Blazor.Tests/Pages/HealthPageTests.cs b/tests/AHKFlowApp.UI.Blazor.Tests/Pages/HealthPageTests.cs index d9dbb11..5e5fe41 100644 --- a/tests/AHKFlowApp.UI.Blazor.Tests/Pages/HealthPageTests.cs +++ b/tests/AHKFlowApp.UI.Blazor.Tests/Pages/HealthPageTests.cs @@ -109,4 +109,40 @@ public void Health_WhenApiReturnsUnhealthy_DisplaysUnhealthyStatusAndCheckDetail cut.Markup.Should().Contain("database"); cut.Markup.Should().Contain("Login failed for user"); } + + [Fact] + public void Health_WhenTierIsNull_DoesNotRenderTierRow() + { + // Arrange + var response = new HealthResponse("Healthy", "1.0.0", "Test", DateTimeOffset.UtcNow, [], Tier: null); + _apiClient.GetHealthAsync(Arg.Any()) + .Returns(Task.FromResult(response)); + + // Act + IRenderedComponent cut = Render(); + cut.WaitForState(() => !cut.Find(".mud-paper").TextContent.Contains("Checking")); + + // Assert + cut.Markup.Should().NotContain("Tier"); + } + + [Theory] + [InlineData("free", "Free (App Service F1 + SQL serverless)")] + [InlineData("basic", "Basic (App Service B1 + SQL Basic)")] + [InlineData("premium", "premium")] + public void Health_WhenTierIsSet_RendersTierLabel(string tier, string expectedLabel) + { + // Arrange + var response = new HealthResponse("Healthy", "1.0.0", "Test", DateTimeOffset.UtcNow, [], Tier: tier); + _apiClient.GetHealthAsync(Arg.Any()) + .Returns(Task.FromResult(response)); + + // Act + IRenderedComponent cut = Render(); + cut.WaitForState(() => !cut.Find(".mud-paper").TextContent.Contains("Checking")); + + // Assert + cut.Markup.Should().Contain("Tier"); + cut.Markup.Should().Contain(expectedLabel); + } }