mirror of
https://gitlab.com/commento/commento.git
synced 2025-06-29 22:56:37 -04:00
api,db: add comments count endpoint
Closes https://gitlab.com/commento/commento-ce/issues/27
This commit is contained in:
54
api/comment_count_test.go
Normal file
54
api/comment_count_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCommentCountBasics(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
commenterHex, _ := commenterNew("test@example.com", "Test", "undefined", "http://example.com/photo.jpg", "google", "")
|
||||
|
||||
commentNew(commenterHex, "example.com", "/path.html", "root", "**foo**", "approved", time.Now().UTC())
|
||||
commentNew(commenterHex, "example.com", "/path.html", "root", "**bar**", "approved", time.Now().UTC())
|
||||
commentNew(commenterHex, "example.com", "/path.html", "root", "**baz**", "unapproved", time.Now().UTC())
|
||||
|
||||
count, err := commentCount("example.com", "/path.html")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error counting comments: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Errorf("expected count=2 got count=%d", count)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommentCountNewPage(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
count, err := commentCount("example.com", "/path.html")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error counting comments: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Errorf("expected count=0 got count=%d", count)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommentCountEmpty(t *testing.T) {
|
||||
if _, err := commentCount("example.com", ""); err != nil {
|
||||
t.Errorf("unexpected error counting comments on empty path: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := commentCount("", ""); err == nil {
|
||||
t.Errorf("expected error not found counting comments with empty everything")
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user