2026-08-31 10:49:54 -03:00
|
|
|
|
using Data.SeaHavenIndustries;
|
2026-09-08 16:22:11 -03:00
|
|
|
|
using Data.SeaHavenIndustries.Enums;
|
2026-08-31 10:49:54 -03:00
|
|
|
|
using SeaHaven.Services.Helpers;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SeaHavenIndustries.Tests;
|
|
|
|
|
|
|
|
|
|
|
|
public class WorkOrderBoardFieldMutationsTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ApplyApptTime_EmptyValue_ClearsStartAndEnd_KeepsDates()
|
|
|
|
|
|
{
|
|
|
|
|
|
var appointmentDate = new DateTime(2026, 6, 25);
|
|
|
|
|
|
var workOrder = new WorkOrder
|
|
|
|
|
|
{
|
|
|
|
|
|
ScheduledDate = appointmentDate,
|
|
|
|
|
|
ScheduledStart = new DateTime(2026, 6, 25, 9, 0, 0),
|
|
|
|
|
|
ScheduledEnd = new DateTime(2026, 6, 25, 11, 0, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
var dispatch = new Dispatch { Id = 10, ScheduledDate = appointmentDate };
|
|
|
|
|
|
|
|
|
|
|
|
WorkOrderBoardFieldMutations.ApplyApptTime(workOrder, dispatch, "");
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Null(workOrder.ScheduledStart);
|
|
|
|
|
|
Assert.Null(workOrder.ScheduledEnd);
|
|
|
|
|
|
Assert.Equal(appointmentDate, workOrder.ScheduledDate);
|
|
|
|
|
|
Assert.Equal(appointmentDate, dispatch.ScheduledDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ApplyApptTime_StartOnly_LeavesEndNull()
|
|
|
|
|
|
{
|
|
|
|
|
|
var appointmentDate = new DateTime(2026, 6, 25);
|
|
|
|
|
|
var workOrder = new WorkOrder { ScheduledDate = appointmentDate };
|
|
|
|
|
|
var dispatch = new Dispatch { Id = 10, ScheduledDate = appointmentDate };
|
|
|
|
|
|
|
|
|
|
|
|
WorkOrderBoardFieldMutations.ApplyApptTime(workOrder, dispatch, "09:00");
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(new DateTime(2026, 6, 25, 9, 0, 0), workOrder.ScheduledStart);
|
|
|
|
|
|
Assert.Null(workOrder.ScheduledEnd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ApplyApptTime_Range_SetsStartAndEnd()
|
|
|
|
|
|
{
|
|
|
|
|
|
var appointmentDate = new DateTime(2026, 6, 25);
|
|
|
|
|
|
var workOrder = new WorkOrder { ScheduledDate = appointmentDate };
|
|
|
|
|
|
var dispatch = new Dispatch { Id = 10, ScheduledDate = appointmentDate };
|
|
|
|
|
|
|
|
|
|
|
|
WorkOrderBoardFieldMutations.ApplyApptTime(workOrder, dispatch, "09:00 – 11:00");
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(new DateTime(2026, 6, 25, 9, 0, 0), workOrder.ScheduledStart);
|
|
|
|
|
|
Assert.Equal(new DateTime(2026, 6, 25, 11, 0, 0), workOrder.ScheduledEnd);
|
|
|
|
|
|
}
|
2026-09-08 16:22:11 -03:00
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ApplyScheduledDate_IncompleteWithoutAssignee_PromotesToScheduled()
|
|
|
|
|
|
{
|
|
|
|
|
|
var workOrder = new WorkOrder { LifecycleStatus = LifecycleStatus.Incomplete };
|
|
|
|
|
|
|
|
|
|
|
|
var changes = WorkOrderBoardFieldMutations.ApplyScheduledDate(
|
|
|
|
|
|
workOrder,
|
|
|
|
|
|
new DateTime(2026, 6, 25));
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(LifecycleStatus.Scheduled, workOrder.LifecycleStatus);
|
|
|
|
|
|
Assert.Contains(changes, c => c.Action == AuditActionType.StatusChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void ApplyScheduledDate_ClearsScheduled_DemotesToPending()
|
|
|
|
|
|
{
|
|
|
|
|
|
var workOrder = new WorkOrder
|
|
|
|
|
|
{
|
|
|
|
|
|
LifecycleStatus = LifecycleStatus.Scheduled,
|
|
|
|
|
|
ScheduledDate = new DateTime(2026, 6, 25)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var changes = WorkOrderBoardFieldMutations.ApplyScheduledDate(workOrder, parsed: null);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(LifecycleStatus.Pending, workOrder.LifecycleStatus);
|
|
|
|
|
|
Assert.Contains(changes, c => c.Action == AuditActionType.StatusChanged
|
|
|
|
|
|
&& c.NewValue == LifecycleStatus.Pending.ToString());
|
|
|
|
|
|
}
|
2026-08-31 10:49:54 -03:00
|
|
|
|
}
|