add site rss test

This commit is contained in:
Umputun
2018-05-17 00:12:42 -05:00
parent dfe6d644ae
commit 1616135336
2 changed files with 63 additions and 9 deletions
+62 -8
View File
@@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestServer_Rss(t *testing.T) {
func TestServer_RssPost(t *testing.T) {
srv, port := prep(t)
assert.NotNil(t, srv)
defer cleanup(srv)
@@ -24,7 +24,6 @@ func TestServer_Rss(t *testing.T) {
pubDate := time.Now().Format(time.RFC1123Z)
// get created comment by id
res, code := get(t, fmt.Sprintf("http://dev:password@127.0.0.1:%d/api/v1/rss/post?site=radio-t&url=https://radio-t.com/blah1", port))
assert.Equal(t, 200, code)
@@ -47,14 +46,69 @@ func TestServer_Rss(t *testing.T) {
</channel>
</rss>`, pubDate, pubDate)
// clean formatting, i.e. multiple spaces, \t, \n
expected, res = cleanRssFormatting(expected, res)
assert.Equal(t, expected, res)
}
func TestServer_RssSite(t *testing.T) {
srv, port := prep(t)
assert.NotNil(t, srv)
defer cleanup(srv)
pubDate := time.Now().Format(time.RFC1123Z)
r := strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/blah10", "site": "radio-t"}}`)
resp, err := http.Post(fmt.Sprintf("http://dev:password@127.0.0.1:%d/api/v1/comment", port), "application/json", r)
assert.Nil(t, err)
assert.Equal(t, http.StatusCreated, resp.StatusCode)
r = strings.NewReader(`{"text": "xyz test", "locator":{"url": "https://radio-t.com/blah11", "site": "radio-t"}}`)
resp, err = http.Post(fmt.Sprintf("http://dev:password@127.0.0.1:%d/api/v1/comment", port), "application/json", r)
assert.Nil(t, err)
assert.Equal(t, http.StatusCreated, resp.StatusCode)
res, code := get(t, fmt.Sprintf("http://dev:password@127.0.0.1:%d/api/v1/rss/site?site=radio-t", port))
assert.Equal(t, 200, code)
assert.Nil(t, err)
t.Log(res)
expected := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Remark42 comments</title>
<link>radio-t</link>
<description>comment updates</description>
<pubDate>%s</pubDate>
<item>
<title>developer one</title>
<link>https://radio-t.com/blah11</link>
<description>&lt;p&gt;xyz test&lt;/p&gt;&#xA;</description>
<author>developer one</author>
<pubDate>%s</pubDate>
</item>
<item>
<title>developer one</title>
<link>https://radio-t.com/blah10</link>
<description>&lt;p&gt;test 123&lt;/p&gt;&#xA;</description>
<author>developer one</author>
<pubDate>%s</pubDate>
</item>
</channel>
</rss>`, pubDate, pubDate, pubDate)
expected, res = cleanRssFormatting(expected, res)
assert.Equal(t, expected, res)
}
// clean formatting, i.e. multiple spaces, \t, \n
func cleanRssFormatting(expected, actual string) (string, string) {
reSpaces := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
expected = strings.Replace(expected, "\n", " ", -1)
expected = strings.Replace(expected, "\t", " ", -1)
res = strings.Replace(res, "\n", " ", -1)
reSpaces := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
expected = reSpaces.ReplaceAllString(expected, " ")
res = reSpaces.ReplaceAllString(res, " ")
assert.Equal(t, expected, res)
actual = strings.Replace(actual, "\n", " ", -1)
actual = reSpaces.ReplaceAllString(actual, " ")
return expected, actual
}
+1 -1
View File
@@ -1,6 +1,6 @@
### find request with tree
GET {{host}}/api/v1/find?site=remark&sort=-score&format=tree&url=https://remark42.com/demo/
GET {{host}}/api/v1/find?site=remark&sort=-active&format=tree&url=https://remark42.com/demo/
### find request with plain
GET {{host}}/api/v1/find?site=remark&sort=-score&format=plain&url=https://remark42.com/demo/