Ensure review dismissal only dismisses the correct review (#15477)

Fix #15472

Signed-off-by: Andrew Thornton art27@cantab.net
pull/15479/head^2
zeripath 4 years ago committed by GitHub
parent 61bae620c1
commit 9d07facdeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      models/review.go
  2. 60
      models/review_test.go

@ -566,7 +566,11 @@ func DismissReview(review *Review, isDismiss bool) (err error) {
review.Dismissed = isDismiss review.Dismissed = isDismiss
_, err = x.Cols("dismissed").Update(review) if review.ID == 0 {
return ErrReviewNotExist{}
}
_, err = x.ID(review.ID).Cols("dismissed").Update(review)
return return
} }

@ -143,11 +143,57 @@ func TestGetReviewersByIssueID(t *testing.T) {
} }
func TestDismissReview(t *testing.T) { func TestDismissReview(t *testing.T) {
review1 := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review) assert.NoError(t, PrepareTestDatabase())
review2 := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.NoError(t, DismissReview(review1, true)) rejectReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
assert.NoError(t, DismissReview(review2, true)) requestReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.NoError(t, DismissReview(review2, true)) approveReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 8}).(*Review)
assert.NoError(t, DismissReview(review2, false)) assert.False(t, rejectReviewExample.Dismissed)
assert.NoError(t, DismissReview(review2, false)) assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(rejectReviewExample, true))
rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, true))
rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, true))
rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, false))
rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, false))
rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(rejectReviewExample, false))
assert.False(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(approveReviewExample, true))
assert.False(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.True(t, approveReviewExample.Dismissed)
} }

Loading…
Cancel
Save