2019-09-21 11:56:06 +03:00
|
|
|
package twitterscraper
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
2020-12-11 20:58:49 +02:00
|
|
|
"time"
|
2019-09-21 11:56:06 +03:00
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetProfile(t *testing.T) {
|
2020-12-11 20:58:49 +02:00
|
|
|
loc := time.FixedZone("UTC", 0)
|
|
|
|
|
joined := time.Date(2007, 02, 20, 14, 35, 54, 0, loc)
|
2019-09-21 11:56:06 +03:00
|
|
|
sample := Profile{
|
2020-12-11 20:58:49 +02:00
|
|
|
Avatar: "https://pbs.twimg.com/profile_images/1308010958862905345/-SGZioPb_normal.jpg",
|
|
|
|
|
Banner: "https://pbs.twimg.com/profile_banners/783214/1604501727",
|
2020-11-09 11:14:42 +02:00
|
|
|
Biography: "What's happening!?",
|
2020-12-11 20:58:49 +02:00
|
|
|
// Birthday: "March 21",
|
|
|
|
|
IsPrivate: false,
|
|
|
|
|
IsVerified: true,
|
|
|
|
|
Joined: &joined,
|
|
|
|
|
Location: "everywhere",
|
|
|
|
|
Name: "Twitter",
|
|
|
|
|
PinnedTweetIDs: []string{},
|
|
|
|
|
URL: "https://twitter.com/Twitter",
|
|
|
|
|
UserID: "783214",
|
|
|
|
|
Username: "Twitter",
|
|
|
|
|
Website: "https://about.twitter.com/",
|
2019-09-21 11:56:06 +03:00
|
|
|
}
|
|
|
|
|
|
2020-05-14 18:01:30 +02:00
|
|
|
profile, err := GetProfile("Twitter")
|
2019-09-21 11:56:06 +03:00
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 10:17:51 +03:00
|
|
|
cmpOptions := cmp.Options{
|
2019-09-21 11:56:06 +03:00
|
|
|
cmpopts.IgnoreFields(Profile{}, "FollowersCount"),
|
|
|
|
|
cmpopts.IgnoreFields(Profile{}, "FollowingCount"),
|
2020-12-11 20:58:49 +02:00
|
|
|
cmpopts.IgnoreFields(Profile{}, "FriendsCount"),
|
2019-09-21 11:56:06 +03:00
|
|
|
cmpopts.IgnoreFields(Profile{}, "LikesCount"),
|
2020-12-11 20:58:49 +02:00
|
|
|
cmpopts.IgnoreFields(Profile{}, "ListedCount"),
|
2019-09-21 11:56:06 +03:00
|
|
|
cmpopts.IgnoreFields(Profile{}, "TweetsCount"),
|
|
|
|
|
}
|
|
|
|
|
if diff := cmp.Diff(sample, profile, cmpOptions...); diff != "" {
|
|
|
|
|
t.Error("Resulting profile does not match the sample", diff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if profile.FollowersCount == 0 {
|
2019-09-21 12:06:42 +03:00
|
|
|
t.Error("Expected FollowersCount is greater than zero")
|
2019-09-21 11:56:06 +03:00
|
|
|
}
|
|
|
|
|
if profile.FollowingCount == 0 {
|
2019-09-21 12:06:42 +03:00
|
|
|
t.Error("Expected FollowingCount is greater than zero")
|
2019-09-21 11:56:06 +03:00
|
|
|
}
|
2020-12-11 20:58:49 +02:00
|
|
|
if profile.LikesCount == 0 {
|
|
|
|
|
t.Error("Expected LikesCount is greater than zero")
|
|
|
|
|
}
|
2019-09-21 11:56:06 +03:00
|
|
|
if profile.TweetsCount == 0 {
|
2019-09-21 12:06:42 +03:00
|
|
|
t.Error("Expected TweetsCount is greater than zero")
|
2019-09-21 11:56:06 +03:00
|
|
|
}
|
|
|
|
|
}
|