56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package staff
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
base "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
|
)
|
|
|
|
func TestDeliveryAllowedActions(t *testing.T) {
|
|
tests := map[int][]string{
|
|
base.StatusReady: {"start"},
|
|
base.StatusDelivering: {"append_tracks", "arrive", "exception"},
|
|
base.StatusAwaitingConfirmation: {"submit_receipt", "exception"},
|
|
base.StatusException: {"recover"},
|
|
}
|
|
for status, expected := range tests {
|
|
actual := deliveryAllowedActions(status)
|
|
if len(actual) != len(expected) {
|
|
t.Fatalf("status %d actions = %v, want %v", status, actual, expected)
|
|
}
|
|
for index := range expected {
|
|
if actual[index] != expected[index] {
|
|
t.Fatalf("status %d actions = %v, want %v", status, actual, expected)
|
|
}
|
|
}
|
|
}
|
|
if actions := deliveryAllowedActions(base.StatusCompleted); len(actions) != 0 {
|
|
t.Fatalf("completed order exposed actions: %v", actions)
|
|
}
|
|
}
|
|
|
|
func TestCoordinateDistanceMeters(t *testing.T) {
|
|
distance, ok := coordinateDistanceMeters("121.5500", "31.2250", "121.5501", "31.2251")
|
|
if !ok || distance <= 0 || distance >= 20 {
|
|
t.Fatalf("unexpected nearby distance: %f, valid=%v", distance, ok)
|
|
}
|
|
if _, ok := coordinateDistanceMeters("invalid", "31.2250", "121.5501", "31.2251"); ok {
|
|
t.Fatal("invalid coordinate accepted")
|
|
}
|
|
}
|
|
|
|
func TestValidTrackPoint(t *testing.T) {
|
|
point := deliveryTrackPointRequest{
|
|
RequestNo: "track-1", Longitude: "121.55", Latitude: "31.22",
|
|
OccurredAt: time.Now(), Source: "gps",
|
|
}
|
|
if !validTrackPoint(point) {
|
|
t.Fatal("valid track point rejected")
|
|
}
|
|
point.Latitude = "91"
|
|
if validTrackPoint(point) {
|
|
t.Fatal("out-of-range latitude accepted")
|
|
}
|
|
}
|