Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/AHKFlowApp.API.Tests/Health/HealthControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,5 +64,38 @@ public async Task GetHealth_InfrastructureEndpoint_ReturnsHealthyText()
body.Should().Be("Healthy");
}

[Fact]
public async Task GetHealth_WhenResourceTierSet_ReturnsTierInResponse()
{
// Arrange
using WebApplicationFactory<global::Program> factory = _factory.WithWebHostBuilder(builder =>
builder.ConfigureAppConfiguration((_, config) =>
config.AddInMemoryCollection(new Dictionary<string, string?> { ["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<HealthResponse>();
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<HealthResponse>();
body!.Tier.Should().BeNull();
}

public void Dispose() => _factory.Dispose();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
36 changes: 36 additions & 0 deletions tests/AHKFlowApp.UI.Blazor.Tests/Pages/HealthPageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CancellationToken>())
.Returns(Task.FromResult<HealthResponse?>(response));

// Act
IRenderedComponent<Health> cut = Render<Health>();
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<CancellationToken>())
.Returns(Task.FromResult<HealthResponse?>(response));

// Act
IRenderedComponent<Health> cut = Render<Health>();
cut.WaitForState(() => !cut.Find(".mud-paper").TextContent.Contains("Checking"));

// Assert
cut.Markup.Should().Contain("Tier");
cut.Markup.Should().Contain(expectedLabel);
}
}
Loading