mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
* feat(work-orders): enrich board search overdue filters and 0-based paging * fix(work-orders): align stacked services with CI build * fix(tests): pass userDataService in comment service unit test * fix(work-orders): use dedicated overdue query flag Stop treating WorkOrderType.Other as an overdue sentinel. Board and advanced search now accept overdue=true while types=Other filters real Other rows; combining both uses OR. * test(work-orders): cover overdue date/status boundary and Other type-filter Lock the PR #23 overdue regression boundary through the public advanced search service. Prove overdue filtering is driven by past-due date plus non-terminal status, not by the WorkOrderType.Other sentinel: - Other + future/not-completed excluded from overdue - past-due + Scheduled included; past-due + Completed/Canceled excluded - types=[PM, Other] keeps real Other rows and does not pull past-due rows - assert 0-based paging (Page=0) is preserved alongside overdue/type filters --------- Co-authored-by: Arthur Bassi <arthur.winiarski.ranger@outlook.com> Co-authored-by: Alexandre Brandizzi <alex_brandizzi@hotmail.com>
213 lines
6.6 KiB
C#
213 lines
6.6 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Data.SeaHavenIndustries.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Implementation;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
using SeaHaven.Services.DTOs;
|
|
using SeaHaven.Services.Implementation;
|
|
|
|
namespace SeaHavenIndustries.Tests;
|
|
|
|
public class WorkOrderBoardDataServiceTests
|
|
{
|
|
private static ApplicationDbContext CreateContext()
|
|
{
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.Options;
|
|
return new ApplicationDbContext(options);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoardRows_ReturnsScheduledInWeekAndUnscheduled()
|
|
{
|
|
await using var context = CreateContext();
|
|
var weekStart = new DateOnly(2026, 6, 22);
|
|
|
|
context.Vendors.Add(new Vendor { Id = 1, CompanyName = "Acme HVAC", ContactName = "Tech", Phone = "555-0100" });
|
|
context.Dispatches.Add(new Dispatch
|
|
{
|
|
Id = 10,
|
|
VendorId = 1,
|
|
ScheduledDate = new DateTime(2026, 6, 24, 8, 0, 0)
|
|
});
|
|
|
|
context.workOrders.AddRange(
|
|
new WorkOrder
|
|
{
|
|
Id = 1,
|
|
InternalWONumber = "10000000001",
|
|
ScheduledDate = new DateTime(2026, 6, 23),
|
|
LifecycleStatus = LifecycleStatus.Scheduled,
|
|
PrimaryDispatchId = 10,
|
|
SiteCode = "BK5"
|
|
},
|
|
new WorkOrder
|
|
{
|
|
Id = 2,
|
|
InternalWONumber = "10000000002",
|
|
ScheduledDate = null,
|
|
LifecycleStatus = LifecycleStatus.Incomplete,
|
|
SiteCode = "BK6"
|
|
},
|
|
new WorkOrder
|
|
{
|
|
Id = 3,
|
|
InternalWONumber = "10000000003",
|
|
ScheduledDate = new DateTime(2026, 7, 1),
|
|
LifecycleStatus = LifecycleStatus.Scheduled
|
|
});
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
var service = new WorkOrderBoardDataService(context);
|
|
var result = await service.GetBoardRowsAsync(new WorkOrderBoardQuery(
|
|
weekStart,
|
|
weekStart.AddDays(4),
|
|
null,
|
|
false,
|
|
null,
|
|
false,
|
|
null,
|
|
null));
|
|
|
|
Assert.Single(result.ScheduledRows);
|
|
Assert.Equal(1, result.ScheduledRows[0].Id);
|
|
Assert.Equal("Acme HVAC", result.ScheduledRows[0].VendorName);
|
|
Assert.Single(result.UnscheduledRows);
|
|
Assert.Equal(2, result.UnscheduledRows[0].Id);
|
|
Assert.Equal(1, result.ScheduledTotalBeforeSearch);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoardRows_FiltersByDispatcher()
|
|
{
|
|
await using var context = CreateContext();
|
|
var weekStart = new DateOnly(2026, 6, 22);
|
|
|
|
context.workOrders.AddRange(
|
|
new WorkOrder
|
|
{
|
|
Id = 1,
|
|
AssignTo = "user-a",
|
|
ScheduledDate = new DateTime(2026, 6, 23),
|
|
LifecycleStatus = LifecycleStatus.Scheduled
|
|
},
|
|
new WorkOrder
|
|
{
|
|
Id = 2,
|
|
AssignTo = "user-b",
|
|
ScheduledDate = new DateTime(2026, 6, 24),
|
|
LifecycleStatus = LifecycleStatus.Scheduled
|
|
});
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
var service = new WorkOrderBoardDataService(context);
|
|
var result = await service.GetBoardRowsAsync(new WorkOrderBoardQuery(
|
|
weekStart,
|
|
weekStart.AddDays(4),
|
|
new[] { "user-a" },
|
|
false,
|
|
null,
|
|
false,
|
|
null,
|
|
null));
|
|
|
|
Assert.Single(result.ScheduledRows);
|
|
Assert.Equal("user-a", result.ScheduledRows[0].AssignTo);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoardRows_MyWorkOrders_FiltersCurrentUser()
|
|
{
|
|
await using var context = CreateContext();
|
|
var weekStart = new DateOnly(2026, 6, 22);
|
|
|
|
context.workOrders.AddRange(
|
|
new WorkOrder
|
|
{
|
|
Id = 1,
|
|
AssignTo = "me",
|
|
ScheduledDate = new DateTime(2026, 6, 23),
|
|
LifecycleStatus = LifecycleStatus.Scheduled
|
|
},
|
|
new WorkOrder
|
|
{
|
|
Id = 2,
|
|
AssignTo = "other",
|
|
ScheduledDate = new DateTime(2026, 6, 23),
|
|
LifecycleStatus = LifecycleStatus.Scheduled
|
|
});
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
var service = new WorkOrderBoardDataService(context);
|
|
var result = await service.GetBoardRowsAsync(new WorkOrderBoardQuery(
|
|
weekStart,
|
|
weekStart.AddDays(4),
|
|
null,
|
|
true,
|
|
null,
|
|
false,
|
|
null,
|
|
"me"));
|
|
|
|
Assert.Single(result.ScheduledRows);
|
|
Assert.Equal(1, result.ScheduledRows[0].Id);
|
|
}
|
|
}
|
|
|
|
public class WorkOrderBoardServiceTests
|
|
{
|
|
private static ApplicationDbContext CreateContext()
|
|
{
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.Options;
|
|
return new ApplicationDbContext(options);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoardAsync_ComputesCountsAndPastDue()
|
|
{
|
|
await using var context = CreateContext();
|
|
var weekStart = new DateOnly(2026, 6, 22);
|
|
|
|
context.workOrders.Add(new WorkOrder
|
|
{
|
|
Id = 1,
|
|
InternalWONumber = "10000000001",
|
|
ScheduledDate = new DateTime(2026, 6, 24, 12, 0, 0, DateTimeKind.Utc),
|
|
LifecycleStatus = LifecycleStatus.Scheduled
|
|
});
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
var dataService = new WorkOrderBoardDataService(context);
|
|
var boardService = new WorkOrderBoardService(dataService);
|
|
|
|
var response = await boardService.GetBoardAsync(new WorkOrderBoardQueryDto
|
|
{
|
|
WeekStart = weekStart
|
|
}, null);
|
|
|
|
Assert.Equal(1, response.Counts.Total);
|
|
Assert.Single(response.Scheduled);
|
|
Assert.True(response.Scheduled[0].IsPastDue);
|
|
Assert.Equal("wednesday", response.Scheduled[0].DayGroup);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoardAsync_InvalidWeekWindow_Throws()
|
|
{
|
|
await using var context = CreateContext();
|
|
var boardService = new WorkOrderBoardService(new WorkOrderBoardDataService(context));
|
|
|
|
await Assert.ThrowsAsync<ArgumentException>(() => boardService.GetBoardAsync(new WorkOrderBoardQueryDto
|
|
{
|
|
WeekStart = new DateOnly(2026, 6, 22),
|
|
WeekEnd = new DateOnly(2026, 6, 15)
|
|
}, null));
|
|
}
|
|
}
|