twitter-scrapper/profile_test.go

54 lines
1.4 KiB
Go
Raw Normal View History

2019-09-21 11:56:06 +03:00
package twitterscraper
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func TestGetProfile(t *testing.T) {
2020-05-14 18:01:30 +02:00
loc := time.FixedZone("UTC", 0)
joined := time.Date(2007,02, 20,6,35,0,0, loc)
2019-09-21 11:56:06 +03:00
sample := Profile{
2020-05-14 18:01:30 +02:00
Avatar: "https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png",
Biography: "Whats happening?!",
Birthday: "March 21",
2019-09-21 11:56:06 +03:00
Joined: &joined,
2020-05-14 18:01:30 +02:00
Location: "Everywhere",
Name: "Twitter",
URL: "https://twitter.com/Twitter",
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)
}
var cmpOptions = cmp.Options{
cmpopts.IgnoreFields(Profile{}, "FollowersCount"),
cmpopts.IgnoreFields(Profile{}, "FollowingCount"),
cmpopts.IgnoreFields(Profile{}, "LikesCount"),
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
}
if profile.LikesCount == 0 {
2019-09-21 12:06:42 +03:00
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
}
}