36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
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)
|
|
}
|
|
}
|