@@ -0,0 +1,55 @@
|
||||
package vidser
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"91porn-server/models/v/vidmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func TestDeterministicOrderVideos(t *testing.T) {
|
||||
source := []*vidmod.VideoModel{
|
||||
{ID: primitive.NewObjectID()},
|
||||
{ID: primitive.NewObjectID()},
|
||||
{ID: primitive.NewObjectID()},
|
||||
{ID: primitive.NewObjectID()},
|
||||
}
|
||||
first := append([]*vidmod.VideoModel(nil), source...)
|
||||
retry := append([]*vidmod.VideoModel(nil), source...)
|
||||
deterministicOrderVideos(first, "module:token-a")
|
||||
deterministicOrderVideos(retry, "module:token-a")
|
||||
if !reflect.DeepEqual(videoIDs(first), videoIDs(retry)) {
|
||||
t.Fatal("same refresh token must return the same order")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNextRefreshCandidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
candidateCount int
|
||||
returnedCount int
|
||||
want bool
|
||||
}{
|
||||
{name: "candidate pool has remaining videos", candidateCount: 30, returnedCount: 20, want: true},
|
||||
{name: "candidate pool exactly fits response", candidateCount: 20, returnedCount: 20, want: false},
|
||||
{name: "candidate pool is smaller than page size", candidateCount: 12, returnedCount: 12, want: false},
|
||||
{name: "empty candidate pool", candidateCount: 0, returnedCount: 0, want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := hasNextRefreshCandidate(tt.candidateCount, tt.returnedCount); got != tt.want {
|
||||
t.Fatalf("hasNextRefreshCandidate(%d, %d) = %t, want %t", tt.candidateCount, tt.returnedCount, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func videoIDs(videos []*vidmod.VideoModel) []primitive.ObjectID {
|
||||
ids := make([]primitive.ObjectID, len(videos))
|
||||
for i := range videos {
|
||||
ids[i] = videos[i].ID
|
||||
}
|
||||
return ids
|
||||
}
|
||||
Reference in New Issue
Block a user