forked from Jeadie/notion-rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotion_dao_integ_test.go
95 lines (84 loc) · 2.12 KB
/
notion_dao_integ_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//go:build integration
// +build integration
package main
import (
"context"
"fmt"
"github.com/jomei/notionapi"
"net/url"
"testing"
"time"
)
func TestGetOldUnstarredRSSItems(t *testing.T) {
nDao, err := ConstructNotionDaoFromEnv()
if err != nil {
t.Fatalf(err.Error())
}
itemUrl, _ := url.Parse("https://github.com/Jeadie/notion-rss")
published := time.Now().Add(-1 * time.Hour)
t.Run("Should use created time, not published time", func(t *testing.T) {
// Setup
err := nDao.AddRssItem(RssItem{
title: "notion-rss integration test",
link: *itemUrl,
content: []string{},
categories: []string{"Integration testing", "notion", "rss"},
feedName: "Integration Test",
published: &published,
})
if err != nil {
t.Fatalf(err.Error())
}
pages := nDao.GetOldUnstarredRSSItems(time.Now().Add(-1 * time.Minute))
if len(pages) > 0 {
fmt.Println(pages)
t.Errorf("No pages are expected to exist that are this old")
}
})
t.Run("Should return items olderThan", func(t *testing.T) {
// Setup
err := nDao.AddRssItem(RssItem{
title: "notion-rss integration test",
link: *itemUrl,
content: []string{},
categories: []string{"Integration testing", "notion", "rss"},
feedName: "Integration Test",
published: &published,
})
if err != nil {
t.Fatalf(err.Error())
}
pageIds := nDao.GetOldUnstarredRSSItems(time.Now().Add(1 * time.Hour))
if len(pageIds) == 0 {
t.Errorf("Expected GetOldUnstarredRSSItems to return an item")
}
})
cleanupContentDatabase(nDao)
}
func cleanupContentDatabase(nDao *NotionDao) {
resp, _ := nDao.client.Database.Query(context.Background(), nDao.contentDatabaseId, ¬ionapi.DatabaseQueryRequest{})
for _, p := range resp.Results {
_, err := nDao.client.Page.Update(
context.TODO(),
notionapi.PageID(p.ID),
¬ionapi.PageUpdateRequest{
Archived: true,
Properties: notionapi.Properties{},
})
if err != nil {
fmt.Printf(err.Error())
}
}
}
//
//func TestArchivePages(t *testing.T) {
//
//}
//
//func TestGetEnabledRssFeeds(t *testing.T) {
//
//}
//
//func TestAddRssItem(t *testing.T) {
//
//}