diff --git a/backend/app/store/service/service.go b/backend/app/store/service/service.go index 1517acca..36710160 100644 --- a/backend/app/store/service/service.go +++ b/backend/app/store/service/service.go @@ -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 } diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go index 1de00e78..b5b22297 100644 --- a/backend/app/store/service/service_test.go +++ b/backend/app/store/service/service_test.go @@ -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) {