166 lines
3.8 KiB
Go
166 lines
3.8 KiB
Go
// Copyright 2025 eat-pray-ai & OpenWaygate
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package commentThread
|
|
|
|
import (
|
|
"math"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/eat-pray-ai/yutu/pkg/common"
|
|
"google.golang.org/api/youtube/v3"
|
|
)
|
|
|
|
func TestNewCommentThread(t *testing.T) {
|
|
svc := &youtube.Service{}
|
|
type args struct {
|
|
opts []Option
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want ICommentThread[youtube.CommentThread]
|
|
}{
|
|
{
|
|
name: "with all options",
|
|
args: args{
|
|
opts: []Option{
|
|
WithIds([]string{"thread1", "thread2"}),
|
|
WithAllThreadsRelatedToChannelId("relatedChannel123"),
|
|
WithAuthorChannelId("author123"),
|
|
WithChannelId("channel123"),
|
|
WithMaxResults(100),
|
|
WithModerationStatus("published"),
|
|
WithOrder("time"),
|
|
WithSearchTerms("test search"),
|
|
WithTextFormat("html"),
|
|
WithTextOriginal("This is a comment thread"),
|
|
WithVideoId("video123"),
|
|
WithParts([]string{"id", "snippet"}),
|
|
WithOutput("json"),
|
|
WithJsonpath("items.id"),
|
|
WithService(svc),
|
|
},
|
|
},
|
|
want: &CommentThread{
|
|
Fields: &common.Fields{
|
|
Service: svc,
|
|
Parts: []string{"id", "snippet"},
|
|
Output: "json",
|
|
Jsonpath: "items.id",
|
|
},
|
|
Ids: []string{"thread1", "thread2"},
|
|
AllThreadsRelatedToChannelId: "relatedChannel123",
|
|
AuthorChannelId: "author123",
|
|
ChannelId: "channel123",
|
|
MaxResults: 100,
|
|
ModerationStatus: "published",
|
|
Order: "time",
|
|
SearchTerms: "test search",
|
|
TextFormat: "html",
|
|
TextOriginal: "This is a comment thread",
|
|
VideoId: "video123",
|
|
},
|
|
},
|
|
{
|
|
name: "with no options",
|
|
args: args{
|
|
opts: []Option{},
|
|
},
|
|
want: &CommentThread{Fields: &common.Fields{}},
|
|
},
|
|
{
|
|
name: "with zero max results",
|
|
args: args{
|
|
opts: []Option{
|
|
WithMaxResults(0),
|
|
},
|
|
},
|
|
want: &CommentThread{
|
|
Fields: &common.Fields{},
|
|
MaxResults: math.MaxInt64,
|
|
},
|
|
},
|
|
{
|
|
name: "with negative max results",
|
|
args: args{
|
|
opts: []Option{
|
|
WithMaxResults(-20),
|
|
},
|
|
},
|
|
want: &CommentThread{
|
|
Fields: &common.Fields{},
|
|
MaxResults: 1,
|
|
},
|
|
},
|
|
{
|
|
name: "with empty string values",
|
|
args: args{
|
|
opts: []Option{
|
|
WithAllThreadsRelatedToChannelId(""),
|
|
WithAuthorChannelId(""),
|
|
WithChannelId(""),
|
|
WithModerationStatus(""),
|
|
WithOrder(""),
|
|
WithSearchTerms(""),
|
|
WithTextFormat(""),
|
|
WithTextOriginal(""),
|
|
WithVideoId(""),
|
|
WithParts(nil),
|
|
WithOutput(""),
|
|
WithJsonpath(""),
|
|
},
|
|
},
|
|
want: &CommentThread{
|
|
Fields: &common.Fields{
|
|
Parts: nil,
|
|
Output: "",
|
|
Jsonpath: "",
|
|
},
|
|
AllThreadsRelatedToChannelId: "",
|
|
AuthorChannelId: "",
|
|
ChannelId: "",
|
|
ModerationStatus: "",
|
|
Order: "",
|
|
SearchTerms: "",
|
|
TextFormat: "",
|
|
TextOriginal: "",
|
|
VideoId: "",
|
|
},
|
|
},
|
|
{
|
|
name: "with partial options",
|
|
args: args{
|
|
opts: []Option{
|
|
WithIds([]string{"thread1"}),
|
|
WithVideoId("video456"),
|
|
WithTextOriginal("Partial comment thread"),
|
|
WithMaxResults(50),
|
|
WithOutput("yaml"),
|
|
},
|
|
},
|
|
want: &CommentThread{
|
|
Fields: &common.Fields{Output: "yaml"},
|
|
Ids: []string{"thread1"},
|
|
VideoId: "video456",
|
|
TextOriginal: "Partial comment thread",
|
|
MaxResults: 50,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(
|
|
tt.name, func(t *testing.T) {
|
|
if got := NewCommentThread(tt.args.opts...); !reflect.DeepEqual(
|
|
got, tt.want,
|
|
) {
|
|
t.Errorf("%s\nNewCommentThread() = %v\nwant %v", tt.name, got, tt.want)
|
|
}
|
|
},
|
|
)
|
|
}
|
|
}
|