updates on the sweeper and eligibility things in the order

This commit is contained in:
2026-10-06 15:41:16 +05:30
parent 9b94be1f07
commit efad4d3d12
10 changed files with 803 additions and 35 deletions

View File

@@ -0,0 +1,35 @@
package controllers
import (
"testing"
"doormile/constants"
"doormile/models"
)
// Cancelling an order from the console must close the rider's assignment on
// it. It used to stay Assigned/Accepted for good, and auto-assignment counted
// it against the rider's cap — enough cancelled orders and the rider was never
// offered another. Uses rtoTestDB (consignmentReturn_pg_test.go): skipped
// unless REGISTRY_TEST_DSN points at a throwaway database.
func TestCancelClosesTheRidersAssignment(t *testing.T) {
gdb := rtoTestDB(t)
rider := 38
must(t, gdb.Create(&models.PickupBooking{Bookingid: 71, Bookingno: "DM-T71", Status: constants.BookingMilerAssigned,
Assignedmileruserid: &rider}).Error)
must(t, gdb.Create(&models.BookingAssignment{Bookingid: 71, Mileruserid: rider, Assignmentstatus: constants.AssignmentAccepted}).Error)
// A closed assignment on the same booking must be left as it is.
must(t, gdb.Create(&models.BookingAssignment{Bookingid: 71, Mileruserid: 21, Assignmentstatus: constants.AssignmentRejected}).Error)
closeOpenAssignments(71, "Order cancelled by Doormile operations")
var rows []models.BookingAssignment
must(t, gdb.Where("bookingid = ?", 71).Order("mileruserid").Find(&rows).Error)
got := map[int]string{}
for _, r := range rows {
got[r.Mileruserid] = r.Assignmentstatus
}
if got[38] != constants.AssignmentCancelled || got[21] != constants.AssignmentRejected {
t.Fatalf("assignments after cancel = %v", got)
}
}