mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 15:23:12 +00:00
Do not project VendorId/VendorName for Cancelled, Canceled, or Refused primary dispatches, and expose PrimaryDispatchStatus on the board DTO.
102 lines
3.3 KiB
C#
102 lines
3.3 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Data.SeaHavenIndustries.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Implementation;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
using SeaHaven.Services.Implementation;
|
|
|
|
namespace SeaHavenIndustries.Tests;
|
|
|
|
public class WorkOrderBoardInactiveVendorTests
|
|
{
|
|
private static ApplicationDbContext CreateContext()
|
|
{
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.Options;
|
|
return new ApplicationDbContext(options);
|
|
}
|
|
|
|
private static async Task SeedPrimaryDispatchAsync(
|
|
ApplicationDbContext context,
|
|
string? dispatchStatus,
|
|
string? companyName)
|
|
{
|
|
context.Vendors.Add(new Vendor { Id = 1, CompanyName = companyName });
|
|
context.Dispatches.Add(new Dispatch
|
|
{
|
|
Id = 10,
|
|
VendorId = 1,
|
|
WorkOrderId = 1,
|
|
Status = dispatchStatus,
|
|
ScheduledDate = new DateTime(2026, 6, 24, 8, 0, 0)
|
|
});
|
|
context.workOrders.Add(new WorkOrder
|
|
{
|
|
Id = 1,
|
|
InternalWONumber = "10000000001",
|
|
ScheduledDate = new DateTime(2026, 6, 23),
|
|
LifecycleStatus = LifecycleStatus.Scheduled,
|
|
PrimaryDispatchId = 10,
|
|
SiteCode = "BK5"
|
|
});
|
|
await context.SaveChangesAsync();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Cancelled")]
|
|
[InlineData("Canceled")]
|
|
[InlineData("Refused")]
|
|
public async Task GetBoardRows_InactivePrimaryDispatch_OmitsVendorAssignment(string status)
|
|
{
|
|
await using var context = CreateContext();
|
|
await SeedPrimaryDispatchAsync(context, status, "Acme HVAC");
|
|
var weekStart = new DateOnly(2026, 6, 22);
|
|
|
|
var result = await new WorkOrderBoardDataService(context).GetBoardRowsAsync(new WorkOrderBoardQuery(
|
|
weekStart,
|
|
weekStart.AddDays(4),
|
|
null,
|
|
false,
|
|
null,
|
|
false,
|
|
null,
|
|
null));
|
|
|
|
var raw = Assert.Single(result.ScheduledRows);
|
|
Assert.Null(raw.VendorId);
|
|
Assert.Null(raw.VendorName);
|
|
Assert.Equal(status, raw.PrimaryDispatchStatus);
|
|
|
|
var dto = WorkOrderBoardService.MapRawRow(raw, DateTime.UtcNow);
|
|
Assert.Null(dto.VendorId);
|
|
Assert.Null(dto.VendorName);
|
|
Assert.Equal(status, dto.PrimaryDispatchStatus);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBoardRows_LiveDispatchWithEmptyCompanyName_KeepsVendorId()
|
|
{
|
|
await using var context = CreateContext();
|
|
await SeedPrimaryDispatchAsync(context, "Sent", "");
|
|
var weekStart = new DateOnly(2026, 6, 22);
|
|
|
|
var result = await new WorkOrderBoardDataService(context).GetBoardRowsAsync(new WorkOrderBoardQuery(
|
|
weekStart,
|
|
weekStart.AddDays(4),
|
|
null,
|
|
false,
|
|
null,
|
|
false,
|
|
null,
|
|
null));
|
|
|
|
var raw = Assert.Single(result.ScheduledRows);
|
|
Assert.Equal(1, raw.VendorId);
|
|
Assert.Equal("Sent", raw.PrimaryDispatchStatus);
|
|
|
|
var dto = WorkOrderBoardService.MapRawRow(raw, DateTime.UtcNow);
|
|
Assert.Equal(1, dto.VendorId);
|
|
Assert.Equal("Sent", dto.PrimaryDispatchStatus);
|
|
}
|
|
}
|