38 lines
1.9 KiB
Go
38 lines
1.9 KiB
Go
package sys
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"hotgo/internal/consts"
|
|
)
|
|
|
|
func TestCanAdminMatchOrder(t *testing.T) {
|
|
now := time.Date(2026, 10, 18, 12, 0, 0, 0, time.UTC)
|
|
tests := []struct {
|
|
name string
|
|
dispatchMode int
|
|
orderStatus int
|
|
approvalRequestId uint64
|
|
scheduledMatchAt string
|
|
want bool
|
|
}{
|
|
{name: "manual matching order", dispatchMode: consts.TradeAutoDispatchDisabled, orderStatus: consts.TradeOrderMatching, want: true},
|
|
{name: "auto before schedule", dispatchMode: consts.TradeAutoDispatchEnabled, orderStatus: consts.TradeOrderMatching, scheduledMatchAt: now.Add(time.Minute).Format(time.RFC3339), want: true},
|
|
{name: "auto at schedule", dispatchMode: consts.TradeAutoDispatchEnabled, orderStatus: consts.TradeOrderMatching, scheduledMatchAt: now.Format(time.RFC3339), want: false},
|
|
{name: "auto after schedule", dispatchMode: consts.TradeAutoDispatchEnabled, orderStatus: consts.TradeOrderMatching, scheduledMatchAt: now.Add(-time.Minute).Format(time.RFC3339), want: false},
|
|
{name: "legacy auto without schedule", dispatchMode: consts.TradeAutoDispatchEnabled, orderStatus: consts.TradeOrderMatching, want: true},
|
|
{name: "invalid schedule", dispatchMode: consts.TradeAutoDispatchEnabled, orderStatus: consts.TradeOrderMatching, scheduledMatchAt: "invalid", want: false},
|
|
{name: "already completed", dispatchMode: consts.TradeAutoDispatchDisabled, orderStatus: consts.TradeOrderCompleted, want: false},
|
|
{name: "approval pending", dispatchMode: consts.TradeAutoDispatchDisabled, orderStatus: consts.TradeOrderMatching, approvalRequestId: 9, want: false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := canAdminMatchOrder(tt.dispatchMode, tt.orderStatus, tt.approvalRequestId, tt.scheduledMatchAt, now)
|
|
if got != tt.want {
|
|
t.Fatalf("canAdminMatchOrder() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|