From 1616135336d0c66aa9dd44caddc505867267397b Mon Sep 17 00:00:00 2001 From: Umputun Date: Thu, 17 May 2018 00:12:42 -0500 Subject: [PATCH] add site rss test --- app/rest/api/rss_test.go | 70 +++++++++++++++++++++++++++++++++++----- remark.rest | 2 +- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/app/rest/api/rss_test.go b/app/rest/api/rss_test.go index a76dec16..e5e3d50a 100644 --- a/app/rest/api/rss_test.go +++ b/app/rest/api/rss_test.go @@ -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) { `, 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(` + + Remark42 comments + radio-t + comment updates + %s + + developer one + https://radio-t.com/blah11 + <p>xyz test</p> + developer one + %s + + + developer one + https://radio-t.com/blah10 + <p>test 123</p> + developer one + %s + + + `, 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 } diff --git a/remark.rest b/remark.rest index 31f5fc03..f24b4a8c 100644 --- a/remark.rest +++ b/remark.rest @@ -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/