2022-06-30 14:54:58 -07:00
|
|
|
package input_test
|
2022-04-29 13:02:25 -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
|
|
|
ffxiv "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
|
2022-04-29 13:02:25 -07:00
|
|
|
)
|
|
|
|
|
2024-05-09 18:59:50 -07:00
|
|
|
var FFXIVRecord entity.SourceEntity = entity.SourceEntity{
|
2024-05-01 18:26:14 -07:00
|
|
|
ID: 9999,
|
|
|
|
DisplayName: "Final Fantasy XIV - NA",
|
|
|
|
Source: domain.SourceCollectorFfxiv,
|
|
|
|
Url: "https://na.finalfantasyxiv.com/lodestone/",
|
|
|
|
Tags: "ffxiv, final, fantasy, xiv, na, lodestone",
|
2022-06-08 21:17:08 -07:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:02:25 -07:00
|
|
|
func TestFfxivGetParser(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
_, err := fc.GetParser()
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivPullFeed(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if len(links) == 0 {
|
|
|
|
t.Error("expected links to come back but got 0")
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivExtractThumbnail(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
thumb, err := fc.ExtractThumbnail(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if thumb == "" {
|
|
|
|
t.Error("expected a link but got nothing.")
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivExtractPubDate(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
_, err = fc.ExtractPubDate(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivExtractDescription(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
_, err = fc.ExtractDescription(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivExtractAuthor(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
author, err := fc.ExtractAuthor(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if author == "" {
|
|
|
|
t.Error("failed to locate the author name")
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivExtractTags(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
res, err := fc.ExtractTags(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if res == "" {
|
|
|
|
t.Error("failed to locate the tags")
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivExtractTitle(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
res, err := fc.ExtractTitle(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if res == "" {
|
|
|
|
t.Error("failed to locate the tags")
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFFxivExtractAuthorIamge(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
parser := fc.GetBrowser()
|
|
|
|
defer parser.Close()
|
|
|
|
|
|
|
|
links, err := fc.PullFeed(parser)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
|
|
|
|
page := fc.GetPage(parser, links[0])
|
|
|
|
defer page.Close()
|
|
|
|
|
|
|
|
res, err := fc.ExtractAuthorImage(page)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if res == "" {
|
|
|
|
t.Error("failed to locate the tags")
|
|
|
|
}
|
2022-04-29 13:02:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFfxivCheckSource(t *testing.T) {
|
2022-06-08 21:17:08 -07:00
|
|
|
fc := ffxiv.NewFFXIVClient(FFXIVRecord)
|
2022-04-29 13:02:25 -07:00
|
|
|
fc.CheckSource()
|
2022-12-04 08:49:17 -08:00
|
|
|
|
|
|
|
}
|