fix unexpected blocking if +1 vote in positive score only mode on 0
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user