fix no-votes issue with wrong check for 0 value
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user