mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 07:13:12 +00:00
GET /dashboard/stats now returns unassigned: open (not Completed or Canceled) work orders with no dispatcher in the selected period, within the caller's server-derived account scope. It uses the same filters as the Unassigned board search, so the Dashboard number equals the list it drills into. A dispatcher-scoped Dashboard has no unassigned work and returns 0.
56 lines
2 KiB
C#
56 lines
2 KiB
C#
using System.Security.Claims;
|
|
using Api.SeaHavenIndustries.Controllers;
|
|
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using SeaHaven.Services.DTOs;
|
|
using SeaHaven.Services.Interfaces;
|
|
using Xunit;
|
|
|
|
namespace Api.SeaHavenIndustries.Tests;
|
|
|
|
public class DashboardControllerTests
|
|
{
|
|
private static object Prop(object source, string name) =>
|
|
source.GetType().GetProperty(name)!.GetValue(source)!;
|
|
|
|
private static DashboardController NewController(Mock<IDashboardService> service) =>
|
|
new(service.Object)
|
|
{
|
|
ControllerContext = new ControllerContext
|
|
{
|
|
HttpContext = new DefaultHttpContext()
|
|
}
|
|
};
|
|
|
|
// Guards the Stats wire object, not the service DTO. GetKpiCountsAsync and
|
|
// DashboardStatsDTO already carried these three counts; the regression this
|
|
// pins is the controller's anonymous response silently dropping them, which
|
|
// is what left the tiles with nothing to read.
|
|
[Fact]
|
|
public async Task GetStats_SerialisesKpiCountsOnWireObject()
|
|
{
|
|
var service = new Mock<IDashboardService>();
|
|
service.Setup(s => s.GetStatsAsync(
|
|
It.IsAny<ClaimsPrincipal>(),
|
|
It.IsAny<DashboardStatsQueryDTO>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(new DashboardStatsDTO
|
|
{
|
|
ScheduledTomorrow = 3,
|
|
PendingUplifts = 5,
|
|
AvetaPending = 7,
|
|
Unassigned = 11
|
|
});
|
|
|
|
var result = await NewController(service).GetStats(
|
|
new DashboardStatsQueryDTO(), CancellationToken.None);
|
|
|
|
var body = result.Should().BeOfType<OkObjectResult>().Subject.Value!;
|
|
((int)Prop(body, "scheduledTomorrow")).Should().Be(3);
|
|
((int)Prop(body, "pendingUplifts")).Should().Be(5);
|
|
((int)Prop(body, "avetaPending")).Should().Be(7);
|
|
((int)Prop(body, "unassigned")).Should().Be(11);
|
|
}
|
|
}
|