-
Notifications
You must be signed in to change notification settings - Fork 62
/
tweet_params_test.go
147 lines (144 loc) · 4.12 KB
/
tweet_params_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package twitter
import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
"time"
)
func TestTweetOptions_addQuery(t *testing.T) {
type fields struct {
Expansions []Expansion
MediaFields []MediaField
PlaceFields []PlaceField
PollFields []PollField
TweetFields []TweetField
UserFields []UserField
}
type args struct {
req *http.Request
}
tests := []struct {
name string
fields fields
args args
want url.Values
}{
{
name: "no queries",
fields: fields{},
args: args{
req: httptest.NewRequest(http.MethodGet, "https://www.go-twitter.com", nil),
},
want: url.Values{},
},
{
name: "queries",
fields: fields{
Expansions: []Expansion{ExpansionAuthorID},
MediaFields: []MediaField{MediaFieldType, MediaFieldWidth},
PlaceFields: []PlaceField{PlaceFieldID, PlaceFieldPlaceType},
PollFields: []PollField{PollFieldOptions},
TweetFields: []TweetField{TweetFieldPossiblySensitve, TweetFieldNonPublicMetrics},
UserFields: []UserField{UserFieldProfileImageURL, UserFieldUserName},
},
args: args{
req: httptest.NewRequest(http.MethodGet, "https://www.go-twitter.com", nil),
},
want: url.Values{
"expansions": []string{strings.Join(expansionStringArray([]Expansion{ExpansionAuthorID}), ",")},
"media.fields": []string{strings.Join(mediaFieldStringArray([]MediaField{MediaFieldType, MediaFieldWidth}), ",")},
"place.fields": []string{strings.Join(placeFieldStringArray([]PlaceField{PlaceFieldID, PlaceFieldPlaceType}), ",")},
"poll.fields": []string{strings.Join(pollFieldStringArray([]PollField{PollFieldOptions}), ",")},
"tweet.fields": []string{strings.Join(tweetFieldStringArray([]TweetField{TweetFieldPossiblySensitve, TweetFieldNonPublicMetrics}), ",")},
"user.fields": []string{strings.Join(userFieldStringArray([]UserField{UserFieldProfileImageURL, UserFieldUserName}), ",")},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := TweetFieldOptions{
Expansions: tt.fields.Expansions,
MediaFields: tt.fields.MediaFields,
PlaceFields: tt.fields.PlaceFields,
PollFields: tt.fields.PollFields,
TweetFields: tt.fields.TweetFields,
UserFields: tt.fields.UserFields,
}
opts.addQuery(tt.args.req)
if reflect.DeepEqual(tt.args.req.URL.Query(), tt.want) == false {
t.Errorf("TweetOptions.addQuery() got %v want %v", tt.args.req.URL.Query(), tt.want)
}
})
}
}
func TestTweetRecentSearchOptions_addQuery(t *testing.T) {
type fields struct {
query string
StartTime time.Time
EndTime time.Time
MaxResult int
NextToken string
SinceID string
UntilID string
}
type args struct {
req *http.Request
}
tests := []struct {
name string
fields fields
args args
want url.Values
}{
{
name: "no queries",
fields: fields{
query: "python",
},
args: args{
req: httptest.NewRequest(http.MethodGet, "https://www.go-twitter.com", nil),
},
want: url.Values{
"query": []string{"python"},
},
},
{
name: "queries",
fields: fields{
query: "python",
NextToken: "112233445566",
StartTime: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC),
EndTime: time.Date(2020, time.February, 20, 0, 0, 0, 0, time.UTC),
},
args: args{
req: httptest.NewRequest(http.MethodGet, "https://www.go-twitter.com", nil),
},
want: url.Values{
"query": []string{"python"},
"next_token": []string{"112233445566"},
"end_time": []string{"2020-02-20T00:00:00Z"},
"start_time": []string{"2020-01-01T00:00:00Z"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := TweetRecentSearchOptions{
query: tt.fields.query,
StartTime: tt.fields.StartTime,
EndTime: tt.fields.EndTime,
MaxResult: tt.fields.MaxResult,
NextToken: tt.fields.NextToken,
SinceID: tt.fields.SinceID,
UntilID: tt.fields.UntilID,
}
opts.addQuery(tt.args.req)
if reflect.DeepEqual(tt.args.req.URL.Query(), tt.want) == false {
t.Errorf("TweetRecentSearchOptions.addQuery() got %v want %v", tt.args.req.URL.Query(), tt.want)
}
})
}
}