2022-04-17 07:25:49 -07:00
|
|
|
package services_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/jtom38/newsbot/collector/database"
|
2022-04-17 07:25:49 -07:00
|
|
|
"github.com/jtom38/newsbot/collector/services"
|
|
|
|
)
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
var YouTubeRecord database.Source = database.Source{
|
|
|
|
ID: uuid.New(),
|
|
|
|
Name: "dadjokes",
|
|
|
|
Source: "reddit",
|
|
|
|
Site: "reddit",
|
|
|
|
Url: "https://youtube.com/gamegrumps",
|
|
|
|
}
|
|
|
|
|
2022-04-17 07:25:49 -07:00
|
|
|
func TestGetPageParser(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
|
|
_, err := yc.GetParser(YouTubeRecord.Url)
|
2022-04-17 07:25:49 -07:00
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetChannelId(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
2022-04-17 07:25:49 -07:00
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
_, err = yc.GetChannelId(parser)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullFeed(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
2022-04-17 07:25:49 -07:00
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
_, err = yc.GetChannelId(parser)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
_, err = yc.PullFeed()
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetAvatarUri(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
res, err := yc.GetAvatarUri()
|
|
|
|
if err != nil { panic(err) }
|
2022-05-15 21:48:23 -07:00
|
|
|
if res == "" { panic(services.ErrMissingAuthorImage)}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetVideoTags(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
var videoUri = "https://www.youtube.com/watch?v=k_sQEXOBe68"
|
|
|
|
|
|
|
|
parser, err := yc.GetParser(videoUri)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
tags, err := yc.GetTags(parser)
|
|
|
|
if err == nil && tags == "" { panic("err was empty but value was missing.")}
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetChannelTags(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
2022-04-17 07:25:49 -07:00
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
tags, err := yc.GetTags(parser)
|
|
|
|
if err == nil && tags == "" { panic("no err but expected value was missing.")}
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetVideoThumbnail(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
parser, err := yc.GetParser("https://www.youtube.com/watch?v=k_sQEXOBe68")
|
|
|
|
if err != nil {panic(err) }
|
|
|
|
|
|
|
|
thumb, err := yc.GetVideoThumbnail(parser)
|
|
|
|
if err == nil && thumb == "" { panic("no err but expected result was missing")}
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckSource(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
|
|
|
_, err := yc.GetContent()
|
2022-04-17 07:25:49 -07:00
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckUriCache(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
item := "demo"
|
|
|
|
|
|
|
|
services.YoutubeUriCache = append(services.YoutubeUriCache, &item)
|
|
|
|
res := yc.CheckUriCache(&item)
|
|
|
|
if res == false { panic("expected a value to come back")}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckUriCacheFails(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
yc := services.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
item := "demo1"
|
|
|
|
|
|
|
|
res := yc.CheckUriCache(&item)
|
|
|
|
if res == true { panic("expected no value to come back")}
|
|
|
|
|
|
|
|
}
|