api: don't auto-upvote new comments
This commit is contained in:
parent
57e5bc7abc
commit
e93733510b
@ -47,7 +47,7 @@ func TestCommentListBasics(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if c[0].Direction != 1 {
|
if c[0].Direction != 0 {
|
||||||
t.Errorf("expected c.Direction = 1 got c.Direction = %d", c[0].Direction)
|
t.Errorf("expected c.Direction = 1 got c.Direction = %d", c[0].Direction)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,6 @@ func commentNew(commenterHex string, domain string, path string, parentHex strin
|
|||||||
return "", errorInternal
|
return "", errorInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = commentVote(commenterHex, commentHex, 1); err != nil {
|
|
||||||
logger.Warningf("error: cannot upvote new comment automatically: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return commentHex, nil
|
return commentHex, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ func TestCommentNewUpvoted(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if score != 1 {
|
if score != 0 {
|
||||||
t.Errorf("expected comment to be auto-upvoted")
|
t.Errorf("expected comment to be at 0 points")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,23 @@ func commentVote(commenterHex string, commentHex string, direction int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statement := `
|
statement := `
|
||||||
|
SELECT commenterHex
|
||||||
|
FROM comments
|
||||||
|
WHERE commentHex = $1;
|
||||||
|
`
|
||||||
|
row := db.QueryRow(statement, commentHex)
|
||||||
|
|
||||||
|
var authorHex string
|
||||||
|
if err := row.Scan(&authorHex); err != nil {
|
||||||
|
logger.Errorf("erorr selecting authorHex for vote")
|
||||||
|
return errorInternal
|
||||||
|
}
|
||||||
|
|
||||||
|
if authorHex == commenterHex {
|
||||||
|
return errorSelfVote
|
||||||
|
}
|
||||||
|
|
||||||
|
statement = `
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
votes (commentHex, commenterHex, direction, voteDate)
|
votes (commentHex, commenterHex, direction, voteDate)
|
||||||
VALUES ($1, $2, $3, $4 )
|
VALUES ($1, $2, $3, $4 )
|
||||||
|
@ -14,42 +14,48 @@ func TestCommentVoteBasics(t *testing.T) {
|
|||||||
|
|
||||||
c0, _ := commentNew(cr0, "example.com", "/path.html", "root", "**foo**", "approved", time.Now().UTC())
|
c0, _ := commentNew(cr0, "example.com", "/path.html", "root", "**foo**", "approved", time.Now().UTC())
|
||||||
|
|
||||||
commentVote(cr0, c0, -1)
|
if err := commentVote(cr0, c0, 1); err != errorSelfVote {
|
||||||
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -1 {
|
t.Errorf("expected err=errorSelfVote got err=%v", err)
|
||||||
t.Errorf("expected c[0].Score = -1 got c[0].Score = %d", c[0].Score)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commentVote(cr1, c0, -1)
|
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != 0 {
|
||||||
commentVote(cr2, c0, -1)
|
t.Errorf("expected c[0].Score = 0 got c[0].Score = %d", c[0].Score)
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commentVote(cr1, c0, -1)
|
if err := commentVote(cr1, c0, -1); err != nil {
|
||||||
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -3 {
|
t.Errorf("unexpected error voting: %v", err)
|
||||||
t.Errorf("expected c[0].Score = -3 got c[0].Score = %d", c[0].Score)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := commentVote(cr2, c0, -1); err != nil {
|
||||||
|
t.Errorf("unexpected error voting: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commentVote(cr1, c0, 0)
|
|
||||||
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -2 {
|
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)
|
t.Errorf("expected c[0].Score = -2 got c[0].Score = %d", c[0].Score)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c1, _ := commentNew(cr1, "example.com", "/path.html", "root", "**bar**", "approved", time.Now().UTC())
|
if err := commentVote(cr1, c0, -1); err != nil {
|
||||||
|
t.Errorf("unexpected error voting: %v", err)
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commentVote(cr1, c1, 0)
|
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[0].Score != -2 {
|
||||||
if c, _, _ := commentList("temp", "example.com", "/path.html", false); c[1].Score != 0 {
|
t.Errorf("expected c[0].Score = -2 got c[0].Score = %d", c[0].Score)
|
||||||
t.Errorf("expected c[1].Score = 0 got c[1].Score = %d", c[1].Score)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := commentVote(cr1, c0, 0); err != nil {
|
||||||
|
t.Errorf("unexpected error voting: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,3 +39,4 @@ var errorNotModerator = errors.New("You need to be a moderator to do that.")
|
|||||||
var errorNotADirectory = errors.New("The given path is not a directory.")
|
var errorNotADirectory = errors.New("The given path is not a directory.")
|
||||||
var errorGzip = errors.New("Cannot GZip content.")
|
var errorGzip = errors.New("Cannot GZip content.")
|
||||||
var errorCannotDownloadDisqus = errors.New("We could not download your Disqus export file.")
|
var errorCannotDownloadDisqus = errors.New("We could not download your Disqus export file.")
|
||||||
|
var errorSelfVote = errors.New("You cannot vote on your own comment.")
|
||||||
|
Loading…
Reference in New Issue
Block a user