From c7468184ba08cd8d607acf4ed22dd9bce381788e Mon Sep 17 00:00:00 2001 From: Umputun Date: Sat, 26 Jan 2019 17:05:54 -0600 Subject: [PATCH] fix unexpected blocking if +1 vote in positive score only mode on 0 --- backend/app/store/service/service.go | 2 +- backend/app/store/service/service_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/store/service/service.go b/backend/app/store/service/service.go index ccfdae20..eadd6059 100644 --- a/backend/app/store/service/service.go +++ b/backend/app/store/service/service.go @@ -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) } diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go index 3e568a59..82fd5653 100644 --- a/backend/app/store/service/service_test.go +++ b/backend/app/store/service/service_test.go @@ -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) {