package likemod import ( "reflect" "testing" "91porn-server/common/constant" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" ) func TestLikeVideoStatusFilterUsesCompoundIndexFields(t *testing.T) { id1 := primitive.NewObjectID() id2 := primitive.NewObjectID() ids := uniqueVideoIDs([]primitive.ObjectID{id1, id2, id1}) filter := likeVideoStatusFilter(123, ids) if got := filter["userID"]; got != uint64(123) { t.Fatalf("userID = %#v, want 123", got) } typeMatch, ok := filter["type"].(bson.M) if !ok { t.Fatalf("type filter = %T, want bson.M", filter["type"]) } gotTypes, ok := typeMatch["$in"].([]string) if !ok { t.Fatalf("type.$in = %T, want []string", typeMatch["$in"]) } wantTypes := []string{ constant.LikeTypeSP, constant.LikeTypeShort, constant.LikeTypeCover, constant.LikeTypePic, constant.LikeTypeSEED_LINK, constant.LikeTypeAiPlaza, } if !reflect.DeepEqual(gotTypes, wantTypes) { t.Fatalf("type.$in = %#v, want %#v", gotTypes, wantTypes) } objMatch, ok := filter["objID"].(bson.M) if !ok { t.Fatalf("objID filter = %T, want bson.M", filter["objID"]) } gotIDs, ok := objMatch["$in"].([]primitive.ObjectID) if !ok { t.Fatalf("objID.$in = %T, want []primitive.ObjectID", objMatch["$in"]) } if wantIDs := []primitive.ObjectID{id1, id2}; !reflect.DeepEqual(gotIDs, wantIDs) { t.Fatalf("objID.$in = %#v, want %#v", gotIDs, wantIDs) } } func TestIsLikeVideosEmptyIDsReturnsBeforeDatabaseAccess(t *testing.T) { originalDB := mdb mdb = nil t.Cleanup(func() { mdb = originalDB }) got, err := IsLikeVideos(123, nil) if err != nil { t.Fatalf("IsLikeVideos() error = %v", err) } if len(got) != 0 { t.Fatalf("IsLikeVideos() = %#v, want empty map", got) } }