using System.Net; using System.Net.Http; using System.Text; using Waiter.Floor.Bff.Application.Adapters; using Waiter.Floor.Bff.Contracts.Requests; namespace Waiter.Floor.Bff.Application.UnitTests; public sealed class OperationsWaiterServiceClientTests { [Fact] public async Task FetchAssignmentsAsync_MapsAssignmentsAndRecentActivity() { var client = CreateClient(""" { "contextId": "demo-context", "locationId": "restaurant-demo", "summary": "2 active waiter assignments are currently visible.", "assignments": [ { "waiterId": "waiter-01", "tableId": "T-12", "status": "serving", "activeOrders": 2 } ], "recentActivity": [ "demo-context: table T-12 requested dessert menus" ] } """); var adapter = new OperationsWaiterServiceClient(client); var response = await adapter.FetchAssignmentsAsync(new GetWaiterAssignmentsRequest("demo-context"), CancellationToken.None); Assert.Equal("restaurant-demo", response.LocationId); Assert.Single(response.Assignments); Assert.Single(response.RecentActivity); Assert.Equal("waiter-01", response.Assignments.Single().WaiterId); } [Fact] public async Task FetchRecentActivityAsync_ProjectsActivityOnlyResponse() { var client = CreateClient(""" { "contextId": "demo-context", "locationId": "restaurant-demo", "summary": "2 active waiter assignments are currently visible.", "assignments": [], "recentActivity": [ "demo-context: table T-08 is waiting for payment capture" ] } """); var adapter = new OperationsWaiterServiceClient(client); var response = await adapter.FetchRecentActivityAsync(new GetWaiterAssignmentsRequest("demo-context"), CancellationToken.None); Assert.Equal("demo-context", response.ContextId); Assert.Single(response.RecentActivity); } [Fact] public async Task SubmitOrderAsync_MapsOperationsPayloadToSubmitResponse() { var client = CreateClient(""" { "contextId": "demo-context", "orderId": "ORD-42", "accepted": true, "summary": "Order ORD-42 for table T-12 was accepted with 3 items.", "status": "queued", "submittedAtUtc": "2026-03-31T10:15:00Z" } """); var adapter = new OperationsWaiterServiceClient(client); var response = await adapter.SubmitOrderAsync(new SubmitFloorOrderRequest("demo-context", "T-12", "ORD-42", 3), CancellationToken.None); Assert.True(response.Accepted); Assert.Equal("queued", response.Status); Assert.Equal("demo-context", response.ContextId); } [Fact] public async Task UpdateOrderAsync_PrefixesAcceptedUpdateSummary() { var client = CreateClient(""" { "contextId": "demo-context", "orderId": "ORD-42", "accepted": true, "summary": "Order ORD-42 for table T-12 was accepted with 4 items.", "status": "queued", "submittedAtUtc": "2026-03-31T10:15:00Z" } """); var adapter = new OperationsWaiterServiceClient(client); var response = await adapter.UpdateOrderAsync(new UpdateFloorOrderRequest("demo-context", "T-12", "ORD-42", 4), CancellationToken.None); Assert.Contains("Updated order ORD-42.", response.Summary); Assert.Equal("queued", response.Status); } 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 SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(json, Encoding.UTF8, "application/json") }); } } }