2022-06-30 14:54:58 -07:00
|
|
|
package input_test
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-05-09 18:59:50 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/domain"
|
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/entity"
|
2024-04-23 07:15:38 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
|
2022-04-17 07:25:49 -07:00
|
|
|
)
|
|
|
|
|
2024-05-09 18:59:50 -07:00
|
|
|
var YouTubeRecord = entity.SourceEntity{
|
2024-05-01 18:26:14 -07:00
|
|
|
ID: 9999,
|
|
|
|
DisplayName: "dadjokes",
|
|
|
|
Source: domain.SourceCollectorReddit,
|
|
|
|
Url: "https://youtube.com/gamegrumps",
|
2022-06-08 21:17:08 -07:00
|
|
|
}
|
|
|
|
|
2022-04-17 07:25:49 -07:00
|
|
|
func TestGetPageParser(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-06-08 21:17:08 -07:00
|
|
|
_, err := yc.GetParser(YouTubeRecord.Url)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetChannelId(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-06-08 21:17:08 -07:00
|
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
_, err = yc.GetChannelId(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullFeed(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-06-08 21:17:08 -07:00
|
|
|
parser, err := yc.GetParser(YouTubeRecord.Url)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
_, err = yc.GetChannelId(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
_, err = yc.PullFeed()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetAvatarUri(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
res, err := yc.GetAvatarUri()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if res == "" {
|
|
|
|
t.Error(input.ErrMissingAuthorImage)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetVideoTags(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.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)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
tags, err := yc.GetTags(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err == nil && tags == "" {
|
|
|
|
t.Error("err was empty but value was missing.")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetChannelTags(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.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-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
tags, err := yc.GetTags(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err == nil && tags == "" {
|
|
|
|
t.Error("no err but expected value was missing.")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetVideoThumbnail(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
parser, err := yc.GetParser("https://www.youtube.com/watch?v=k_sQEXOBe68")
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
thumb, err := yc.GetVideoThumbnail(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err == nil && thumb == "" {
|
|
|
|
t.Error("no err but expected result was missing")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckSource(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-06-08 21:17:08 -07:00
|
|
|
_, err := yc.GetContent()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckUriCache(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
item := "demo"
|
|
|
|
|
2022-06-30 14:54:58 -07:00
|
|
|
input.YoutubeUriCache = append(input.YoutubeUriCache, &item)
|
2022-04-17 07:25:49 -07:00
|
|
|
res := yc.CheckUriCache(&item)
|
2022-12-04 08:49:17 -08:00
|
|
|
if res == false {
|
|
|
|
t.Error("expected a value to come back")
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckUriCacheFails(t *testing.T) {
|
2022-06-30 14:54:58 -07:00
|
|
|
yc := input.NewYoutubeClient(YouTubeRecord)
|
2022-04-17 07:25:49 -07:00
|
|
|
item := "demo1"
|
2022-12-04 08:49:17 -08:00
|
|
|
|
2022-04-17 07:25:49 -07:00
|
|
|
res := yc.CheckUriCache(&item)
|
2022-12-04 08:49:17 -08:00
|
|
|
if res == true {
|
|
|
|
t.Error("expected no value to come back")
|
|
|
|
}
|
2022-04-17 07:25:49 -07:00
|
|
|
|
2022-12-04 08:49:17 -08:00
|
|
|
}
|