2022-06-30 14:54:58 -07:00
|
|
|
package input_test
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
2024-04-29 16:29:37 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
2024-04-23 07:15:38 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
|
2022-05-15 21:48:23 -07:00
|
|
|
)
|
|
|
|
|
2024-04-29 16:29:37 -07:00
|
|
|
var TwitchSourceRecord = domain.SourceEntity{
|
|
|
|
ID: 9999,
|
|
|
|
DisplayName: "nintendo",
|
|
|
|
Source: domain.SourceCollectorTwitch,
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
2024-04-29 16:29:37 -07:00
|
|
|
var TwitchInvalidRecord = domain.SourceEntity{
|
|
|
|
ID: 9999,
|
|
|
|
DisplayName: "EvilNintendo",
|
|
|
|
Source: domain.SourceCollectorTwitch,
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchLogin(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// reach out and confirms that the API returns posts made by the user.
|
|
|
|
func TestTwitchReturnsUserPosts(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if len(posts) == 0 {
|
|
|
|
t.Error("expected videos but got none")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsNothingDueToInvalidUserName(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchInvalidRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if len(posts) != 0 {
|
|
|
|
t.Error("expected videos but got none")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsVideoAuthor(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if posts[0].UserName == "" {
|
|
|
|
t.Error("uable to parse username")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsThumbnail(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
value, err := tc.ExtractThumbnail(posts[0])
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if value == "" {
|
|
|
|
t.Error("uable to parse username")
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsPubDate(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
date, err := tc.ExtractPubDate(posts[0])
|
|
|
|
log.Println(date)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsDescription(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = tc.ExtractDescription(posts[0])
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsAuthorImage(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2022-05-15 21:48:23 -07:00
|
|
|
_, err = tc.ExtractAuthorImage(user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsTags(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
_, err = tc.ExtractTags(posts[0], user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsTitle(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-05-15 21:48:23 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
res, err := tc.ExtractTitle(posts[0])
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if res == "" {
|
|
|
|
t.Error("expected a filled string but got nil")
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchReturnsUrl(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
user, err := tc.GetUserDetails()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
posts, err := tc.GetPosts(user)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
res, err := tc.ExtractUrl(posts[0])
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if res == "" {
|
|
|
|
t.Error("expected a filled string but got nil")
|
|
|
|
}
|
2022-05-15 21:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwitchGetContent(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
tc, err := input.NewTwitchClient()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-08 21:17:08 -07:00
|
|
|
tc.ReplaceSourceRecord(TwitchSourceRecord)
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
err = tc.Login()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2022-05-15 21:48:23 -07:00
|
|
|
posts, err := tc.GetContent()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if len(posts) == 0 {
|
|
|
|
t.Error("posts came back with 0 posts")
|
|
|
|
}
|
|
|
|
if len(posts) != 20 {
|
|
|
|
t.Error("expected 20 posts")
|
|
|
|
}
|
|
|
|
}
|