fix no-votes issue with wrong check for 0 value

This commit is contained in:
Umputun
2018-11-24 12:19:54 -06:00
parent 1432ec44d7
commit 154e23f8fb
2 changed files with 3 additions and 4 deletions
+2 -2
View File
@@ -101,8 +101,8 @@ func (s *DataStore) Vote(locator store.Locator, commentID string, userID string,
return comment, errors.Errorf("user %s already voted for %s", userID, commentID)
}
maxVotes := s.MaxVotes
if s.MaxVotes <= 0 {
maxVotes := s.MaxVotes // 0 value allowed and treated as "no comments allowed"
if s.MaxVotes < 0 { // any negative value reset max votes to unlimited
maxVotes = UnlimitedVotes
}
+1 -2
View File
@@ -139,8 +139,7 @@ func TestService_VotesDisabled(t *testing.T) {
b := DataStore{Interface: prepStoreEngine(t), AdminStore: admin.NewStaticKeyStore("secret 123"), MaxVotes: 0}
_, err := b.Vote(store.Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, "id-1", "user2", true)
assert.NotNil(t, err, "vote limit reached")
assert.True(t, strings.HasPrefix(err.Error(), "maximum number of votes exceeded for comment id-1"))
assert.EqualError(t, err, "maximum number of votes exceeded for comment id-1")
}
func TestService_VoteAggressive(t *testing.T) {