diff --git a/app/rest/api/rss.go b/app/rest/api/rss.go index 542c97b6..f9439838 100644 --- a/app/rest/api/rss.go +++ b/app/rest/api/rss.go @@ -15,6 +15,9 @@ import ( const maxRssItems = 20 +// ui uses links like #remark42__comment- +const uiNav = "#remark42__comment-" + func (s *Rest) rssRoutes() chi.Router { router := chi.NewRouter() router.Get("/post", s.rssPostCommentsCtrl) @@ -105,7 +108,7 @@ func (s *Rest) toRssFeed(url string, comments []store.Comment) (string, error) { for i, c := range comments { f := feeds.Item{ Title: c.User.Name, - Link: &feeds.Link{Href: c.Locator.URL}, + Link: &feeds.Link{Href: c.Locator.URL + uiNav + c.ID}, Description: c.Text, Created: c.Timestamp, Author: &feeds.Author{Name: c.User.Name}, diff --git a/app/rest/api/rss_test.go b/app/rest/api/rss_test.go index 964468ae..a3ff7c70 100644 --- a/app/rest/api/rss_test.go +++ b/app/rest/api/rss_test.go @@ -2,13 +2,13 @@ package api import ( "fmt" - "net/http" "regexp" "strings" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/umputun/remark/app/store" ) func TestServer_RssPost(t *testing.T) { @@ -18,24 +18,15 @@ func TestServer_RssPost(t *testing.T) { waitOnMinChange() - // add one more comment - r := strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`) - - client := &http.Client{Timeout: 5 * time.Second} - req, err := http.NewRequest("POST", ts.URL+"/api/v1/comment", r) - assert.Nil(t, err) - withBasicAuth(req, "dev", "password") - - resp, err := client.Do(req) - assert.Nil(t, err) - assert.Equal(t, http.StatusCreated, resp.StatusCode) - + c1 := store.Comment{ + Text: "test 123", + Locator: store.Locator{URL: "https://radio-t.com/blah1", SiteID: "radio-t"}, + } + id1 := addComment(t, c1, ts) pubDate := time.Now().Format(time.RFC1123Z) res, code := get(t, ts.URL+"/api/v1/rss/post?site=radio-t&url=https://radio-t.com/blah1") assert.Equal(t, 200, code) - - assert.Nil(t, err) t.Log(res) expected := fmt.Sprintf(` @@ -46,13 +37,13 @@ func TestServer_RssPost(t *testing.T) { %s developer one - https://radio-t.com/blah1 + https://radio-t.com/blah1#remark42__comment-%s <p>test 123</p> developer one %s - `, pubDate, pubDate) + `, pubDate, id1, pubDate) expected, res = cleanRssFormatting(expected, res) assert.Equal(t, expected, res) @@ -67,28 +58,19 @@ func TestServer_RssSite(t *testing.T) { pubDate := time.Now().Format(time.RFC1123Z) - client := &http.Client{Timeout: 5 * time.Second} - - r := strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/blah10", "site": "radio-t"}}`) - req, err := http.NewRequest("POST", ts.URL+"/api/v1/comment", r) - assert.Nil(t, err) - withBasicAuth(req, "dev", "password") - resp, err := client.Do(req) - 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"}}`) - req, err = http.NewRequest("POST", ts.URL+"/api/v1/comment", r) - assert.Nil(t, err) - withBasicAuth(req, "dev", "password") - resp, err = client.Do(req) - assert.Nil(t, err) - assert.Equal(t, http.StatusCreated, resp.StatusCode) + c1 := store.Comment{ + Text: "test 123", + Locator: store.Locator{URL: "https://radio-t.com/blah10", SiteID: "radio-t"}, + } + c2 := store.Comment{ + Text: "xyz test", + Locator: store.Locator{URL: "https://radio-t.com/blah11", SiteID: "radio-t"}, + } + id1 := addComment(t, c1, ts) + id2 := addComment(t, c2, ts) res, code := get(t, ts.URL+"/api/v1/rss/site?site=radio-t") assert.Equal(t, 200, code) - - assert.Nil(t, err) t.Log(res) expected := fmt.Sprintf(` @@ -99,20 +81,20 @@ func TestServer_RssSite(t *testing.T) { %s developer one - https://radio-t.com/blah11 + https://radio-t.com/blah11#remark42__comment-%s <p>xyz test</p> developer one %s developer one - https://radio-t.com/blah10 + https://radio-t.com/blah10#remark42__comment-%s <p>test 123</p> developer one %s - `, pubDate, pubDate, pubDate) + `, pubDate, id2, pubDate, id1, pubDate) expected, res = cleanRssFormatting(expected, res) assert.Equal(t, expected, res)