47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
package playletser
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
"videoweb/pub/models/playletmod"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
func TestOperateListFiltersAndSorts(t *testing.T) {
|
|
for _, typ := range []int64{operateListLatest, operateListHot, operateListOriginal, operateListRandom} {
|
|
filter := operateListFilter(typ)
|
|
if filter[playletmod.FN.Playlet.Status] != playletmod.StatusUp {
|
|
t.Fatalf("type %d must contain the up status filter", typ)
|
|
}
|
|
_, recommend := filter[playletmod.FN.Playlet.IsRecommend]
|
|
if recommend != (typ == operateListOriginal) {
|
|
t.Fatalf("type %d recommend filter = %v", typ, recommend)
|
|
}
|
|
}
|
|
if got := operateListSort(operateListLatest)[0].Key; got != playletmod.FN.Playlet.UpdatedAt {
|
|
t.Fatalf("latest sort = %s", got)
|
|
}
|
|
if got := operateListSort(operateListHot)[0].Key; got != playletmod.FN.Playlet.HeatValue {
|
|
t.Fatalf("hot sort = %s", got)
|
|
}
|
|
}
|
|
|
|
func TestOperateRandomPipelineIsStableWithinDay(t *testing.T) {
|
|
filter := bson.M{playletmod.FN.Playlet.Status: playletmod.StatusUp}
|
|
day := time.Date(2026, 10, 24, 1, 0, 0, 0, time.UTC)
|
|
first := operateRandomPipeline(filter, 20, 10, day)
|
|
second := operateRandomPipeline(filter, 20, 10, day.Add(time.Hour))
|
|
if !reflect.DeepEqual(first, second) {
|
|
t.Fatal("random order changed within one China Standard Time day")
|
|
}
|
|
third := operateRandomPipeline(filter, 20, 10, day.Add(24*time.Hour))
|
|
if reflect.DeepEqual(first, third) {
|
|
t.Fatal("random order did not change on the next China Standard Time day")
|
|
}
|
|
if first[4]["$skip"] != int64(20) || first[5]["$limit"] != int64(10) {
|
|
t.Fatalf("pagination stages = %v", first)
|
|
}
|
|
}
|