updates
This commit is contained in:
@@ -13,6 +13,40 @@ const (
|
||||
MilerBlocked = "Blocked"
|
||||
)
|
||||
|
||||
// MilerWorkingStatuses are the states in which a miler may be GIVEN more work.
|
||||
//
|
||||
// A miler carrying an order is still a miler on the road. Courier rounds are
|
||||
// multi-stop by nature, and every candidate query used to test
|
||||
// `availabilitystatus = 'Available'`, which treats the first booking as a
|
||||
// lock: the moment a rider took one order they vanished from every assignment
|
||||
// path, and the per-rider load caps that exist precisely to govern this never
|
||||
// got a chance to run. Whether a rider can take another job is a question
|
||||
// about how much they are already carrying — counted from their open
|
||||
// assignments — not about whether they are carrying anything at all.
|
||||
//
|
||||
// Offline, Break and Blocked are the only states that take a miler out. They
|
||||
// are excluded by naming the ones that are in, so a status added later is
|
||||
// off-duty until someone decides otherwise.
|
||||
var MilerWorkingStatuses = []string{
|
||||
MilerAvailable,
|
||||
MilerAssigned,
|
||||
MilerOnPickup,
|
||||
MilerAtCustomer,
|
||||
MilerPickedUp,
|
||||
MilerOnDelivery,
|
||||
}
|
||||
|
||||
// MilerCanTakeWork reports whether a miler in this state may receive another
|
||||
// booking. Load is capped separately, by counting open assignments.
|
||||
func MilerCanTakeWork(status string) bool {
|
||||
for _, s := range MilerWorkingStatuses {
|
||||
if s == status {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Booking sources — where a booking originated. Left as their stored literals:
|
||||
// "CRM_Console" predates the outward express rename and is an existing DB value.
|
||||
const (
|
||||
|
||||
57
constants/miler_work_test.go
Normal file
57
constants/miler_work_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user