1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api: Add go files

I know this is a huge commit, but I can't be bothered to check
this in part by part.
This commit is contained in:
Adhityaa
2018-05-27 20:10:42 +05:30
parent 60e7e59841
commit a090770b73
95 changed files with 4203 additions and 0 deletions

55
api/comment_vote_test.go Normal file
View File

@ -0,0 +1,55 @@
package main
import (
"testing"
"time"
)
func TestCommentVoteBasics(t *testing.T) {
failTestOnError(t, setupTestEnv())
cr0, _ := commenterNew("test1@example.com", "Test1", "undefined", "http://example.com/photo.jpg", "google")
cr1, _ := commenterNew("test2@example.com", "Test2", "undefined", "http://example.com/photo.jpg", "google")
cr2, _ := commenterNew("test3@example.com", "Test3", "undefined", "http://example.com/photo.jpg", "google")
c0, _ := commentNew(cr0, "example.com", "/path.html", "root", "**foo**", "approved", time.Now().UTC())
commentVote(cr0, c0, -1)
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -1 {
t.Errorf("expected c[0].Score = -1 got c[0].Score = %d", c[0].Score)
return
}
commentVote(cr1, c0, -1)
commentVote(cr2, c0, -1)
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -3 {
t.Errorf("expected c[0].Score = -3 got c[0].Score = %d", c[0].Score)
return
}
commentVote(cr1, c0, -1)
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -3 {
t.Errorf("expected c[0].Score = -3 got c[0].Score = %d", c[0].Score)
return
}
commentVote(cr1, c0, 0)
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -2 {
t.Errorf("expected c[0].Score = -2 got c[0].Score = %d", c[0].Score)
return
}
c1, _ := commentNew(cr1, "example.com", "/path.html", "root", "**bar**", "approved", time.Now().UTC())
commentVote(cr0, c1, 0)
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[1].Score != 1 {
t.Errorf("expected c[1].Score = 1 got c[1].Score = %d", c[1].Score)
return
}
commentVote(cr1, c1, 0)
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[1].Score != 0 {
t.Errorf("expected c[1].Score = 0 got c[1].Score = %d", c[1].Score)
return
}
}