package constants import "testing" // Who may be handed another booking. // // The rule these lock down replaced `availabilitystatus == "Available"`, which // treated a rider's first order as a lock: from then on they were invisible to // every assignment path, and the per-rider load caps that exist to decide this // never ran. A courier round is multi-stop; carrying something is the normal // state of a working miler, not a reason to be skipped. func TestMilerCanTakeWork(t *testing.T) { cases := []struct { status string want bool why string }{ {MilerAvailable, true, "idle and on duty"}, {MilerAssigned, true, "holding stops — the case the old rule wrongly excluded"}, {MilerOnPickup, true, "mid-collection, still adding to the round"}, {MilerAtCustomer, true, "at a door, next stop can still be planned"}, {MilerPickedUp, true, "parcels in hand"}, {MilerOnDelivery, true, "running the round"}, {MilerOffline, false, "not on duty"}, {MilerBreak, false, "on a break — do not pile work on"}, {MilerBlocked, false, "blocked by ops"}, {"", false, "unknown status is off duty, never a default yes"}, {"available", false, "the stored values are capitalised; a case slip must not silently pass"}, {"Retired", false, "a status nobody has taught this rule about is off duty"}, } for _, tc := range cases { if got := MilerCanTakeWork(tc.status); got != tc.want { t.Errorf("MilerCanTakeWork(%q) = %v, want %v (%s)", tc.status, got, tc.want, tc.why) } } } // The off-duty states are excluded by omission, so a status added to the enum // later is off duty until somebody decides otherwise. This fails if a new // constant is added to the list without being considered here. func TestMilerWorkingStatusesExcludesOffDuty(t *testing.T) { offDuty := []string{MilerOffline, MilerBreak, MilerBlocked} for _, bad := range offDuty { for _, s := range MilerWorkingStatuses { if s == bad { t.Errorf("%q must not be in MilerWorkingStatuses", bad) } } } if len(MilerWorkingStatuses) != 6 { t.Errorf("MilerWorkingStatuses has %d entries, expected 6 — a status was added or removed; "+ "confirm it should receive work before updating this count", len(MilerWorkingStatuses)) } }