fix unexpected blocking if +1 vote in positive score only mode on 0

This commit is contained in:
Umputun
2019-01-26 17:05:54 -06:00
parent cb5fc79dbe
commit c7468184ba
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -155,7 +155,7 @@ func (s *DataStore) Vote(locator store.Locator, commentID string, userID string,
return comment, errors.Errorf("maximum number of votes exceeded for comment %s", commentID)
}
if s.PositiveScore && comment.Score <= 0 {
if s.PositiveScore && comment.Score <= 0 && !val {
return comment, errors.Errorf("minimal score reached for comment %s", commentID)
}
@@ -325,11 +325,15 @@ func TestService_VotePositive(t *testing.T) {
_, err := b.Vote(store.Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, "id-1", "user2", false)
assert.EqualError(t, err, "minimal score reached for comment id-1")
_, err = b.Vote(store.Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, "id-1", "user3", true)
assert.Nil(t, err, "minimal score doesn't affect positive vote")
b = DataStore{Interface: prepStoreEngine(t), AdminStore: admin.NewStaticKeyStore("secret 123"),
MaxVotes: -1, PositiveScore: false}
c, err := b.Vote(store.Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, "id-1", "user2", false)
assert.Nil(t, err, "minimal score ignored")
assert.Equal(t, -1, c.Score)
}
func TestService_Pin(t *testing.T) {