39 lines
1.4 KiB
Go
39 lines
1.4 KiB
Go
package playletser
|
|
|
|
import (
|
|
"testing"
|
|
"videoweb/pub/models/homeconfigmod"
|
|
"videoweb/pub/models/playletmod"
|
|
)
|
|
|
|
func TestHomeConfigPlayletQueryForConfig(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
config homeconfigmod.HomeConfig
|
|
field string
|
|
category int64
|
|
recommended bool
|
|
}{
|
|
{name: "legacy recommendation", config: homeconfigmod.HomeConfig{SortType: homeconfigmod.SortTypeRecommend}, field: playletmod.FN.Playlet.RecommendRank, recommended: true},
|
|
{name: "new likes", config: homeconfigmod.HomeConfig{RecommendType: 2}, field: playletmod.FN.Playlet.CountLike},
|
|
{name: "new category", config: homeconfigmod.HomeConfig{RecommendType: 5, CategoryId: 42}, field: playletmod.FN.Playlet.RecommendRank, category: 42},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
filter, sort, category := homeConfigPlayletQueryForConfig(&tt.config)
|
|
if category != tt.category {
|
|
t.Fatalf("category = %d, want %d", category, tt.category)
|
|
}
|
|
if len(sort) == 0 || sort[0].Key != tt.field {
|
|
t.Fatalf("sort = %v, want %s", sort, tt.field)
|
|
}
|
|
if _, ok := filter[playletmod.FN.Playlet.IsRecommend]; ok != tt.recommended {
|
|
t.Fatalf("recommend filter = %v, want %v", ok, tt.recommended)
|
|
}
|
|
if tt.category > 0 && filter[playletmod.FN.Playlet.CategoryIds] != tt.category {
|
|
t.Fatalf("category filter = %v", filter)
|
|
}
|
|
})
|
|
}
|
|
}
|