109 lines
3.9 KiB
C#
109 lines
3.9 KiB
C#
using System.Net;
|
|
using System.Text;
|
|
using Restaurant.Admin.Bff.Application.Adapters;
|
|
using Restaurant.Admin.Bff.Contracts.Requests;
|
|
|
|
namespace Restaurant.Admin.Bff.Application.UnitTests;
|
|
|
|
public sealed class OperationsRestaurantAdminServiceClientTests
|
|
{
|
|
[Fact]
|
|
public async Task FetchConfigAsync_MapsFlagsWindowsAndChanges()
|
|
{
|
|
var adapter = new OperationsRestaurantAdminServiceClient(CreateClient(ConfigPayload));
|
|
|
|
var response = await adapter.FetchConfigAsync(new GetRestaurantAdminConfigRequest("demo-context"), CancellationToken.None);
|
|
|
|
Assert.Equal("v2", response.Version);
|
|
Assert.NotEmpty(response.FeatureFlags);
|
|
Assert.NotEmpty(response.ServiceWindows);
|
|
Assert.NotEmpty(response.RecentChanges);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task FetchRecentChangesAsync_ProjectsChangeHistory()
|
|
{
|
|
var adapter = new OperationsRestaurantAdminServiceClient(CreateClient(ConfigPayload));
|
|
|
|
var response = await adapter.FetchRecentChangesAsync(new GetRestaurantAdminConfigRequest("demo-context"), CancellationToken.None);
|
|
|
|
Assert.Equal(2, response.RecentChanges.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SetServiceWindowAsync_MapsUpdatedServiceWindow()
|
|
{
|
|
var adapter = new OperationsRestaurantAdminServiceClient(CreateClient("""
|
|
{
|
|
"contextId": "demo-context",
|
|
"applied": true,
|
|
"message": "Service window updated by admin-operator.",
|
|
"serviceWindow": {
|
|
"dayOfWeek": 1,
|
|
"openAt": "08:00:00",
|
|
"closeAt": "22:00:00",
|
|
"isClosed": false
|
|
}
|
|
}
|
|
"""));
|
|
|
|
var response = await adapter.SetServiceWindowAsync(
|
|
new SetServiceWindowRequest("demo-context", DayOfWeek.Monday, new TimeOnly(8, 0), new TimeOnly(22, 0), "admin-operator"),
|
|
CancellationToken.None);
|
|
|
|
Assert.True(response.Applied);
|
|
Assert.Equal(DayOfWeek.Monday, response.ServiceWindow.Day);
|
|
}
|
|
|
|
private static HttpClient CreateClient(string json)
|
|
{
|
|
return new HttpClient(new StubHttpMessageHandler(json))
|
|
{
|
|
BaseAddress = new Uri("http://operations-service:8080/")
|
|
};
|
|
}
|
|
|
|
private sealed class StubHttpMessageHandler(string json) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
|
|
{
|
|
Content = new StringContent(json, Encoding.UTF8, "application/json")
|
|
});
|
|
}
|
|
}
|
|
|
|
private const string ConfigPayload = """
|
|
{
|
|
"contextId": "demo-context",
|
|
"summary": "Restaurant admin snapshot includes current flags, service windows, and recent control-plane changes.",
|
|
"version": "v2",
|
|
"featureFlags": [
|
|
{ "key": "kitchen.dispatch.enabled", "enabled": true },
|
|
{ "key": "pos.closeout.preview", "enabled": true }
|
|
],
|
|
"serviceWindows": [
|
|
{ "dayOfWeek": 1, "openAt": "08:00:00", "closeAt": "22:00:00", "isClosed": false },
|
|
{ "dayOfWeek": 5, "openAt": "08:00:00", "closeAt": "23:30:00", "isClosed": false }
|
|
],
|
|
"recentChanges": [
|
|
{
|
|
"changeId": "CFG-100",
|
|
"category": "service-window",
|
|
"description": "Extended Friday dinner service window.",
|
|
"updatedBy": "admin-operator",
|
|
"updatedAtUtc": "2026-03-31T10:00:00Z"
|
|
},
|
|
{
|
|
"changeId": "CFG-101",
|
|
"category": "feature-flag",
|
|
"description": "Enabled POS closeout preview mode.",
|
|
"updatedBy": "ops-lead",
|
|
"updatedAtUtc": "2026-03-31T12:00:00Z"
|
|
}
|
|
]
|
|
}
|
|
""";
|
|
}
|