2024-05-01 17:49:38 -07:00
|
|
|
package cron_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2024-05-09 19:09:32 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/domain"
|
2024-05-01 17:49:38 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/services"
|
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRssPullsCorrectly(t *testing.T) {
|
|
|
|
conn, err := setupInMemoryDb()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
db := services.NewRepositoryService(conn)
|
2024-05-01 18:26:32 -07:00
|
|
|
rowsCreated, err := db.Sources.Create(ctx, domain.SourceCollectorRss, "Gitea - Newsbot.api", "https://git.jamestombleson.com/jtom38/newsbot-api.rss", "rss,gitea,newsbot.api", true)
|
2024-05-01 17:49:38 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
if rowsCreated != 1 {
|
|
|
|
t.Error("failed to create the source record")
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
client := cron.NewScheduler(ctx, conn)
|
2024-05-01 18:26:32 -07:00
|
|
|
client.CollectRssPosts()
|
2024-05-01 17:49:38 -07:00
|
|
|
|
|
|
|
articles, err := db.Articles.ListByPage(ctx, 0, 100)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log(len(articles))
|
|
|
|
}
|