mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 09:33:13 +00:00
83 lines
3 KiB
C#
83 lines
3 KiB
C#
using Data.SeaHavenIndustries;
|
||
using Data.SeaHavenIndustries.Enums;
|
||
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);
|
||
}
|
||
|
||
[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());
|
||
}
|
||
}
|