Skip to content

Commit

Permalink
Ensure review dismissal only dismisses the correct review (#15477)
Browse files Browse the repository at this point in the history
Fix #15472

Signed-off-by: Andrew Thornton art27@cantab.net
  • Loading branch information
zeripath authored Apr 15, 2021
1 parent 61bae62 commit 9d07fac
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
6 changes: 5 additions & 1 deletion models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,11 @@ func DismissReview(review *Review, isDismiss bool) (err error) {

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
}
Expand Down
60 changes: 53 additions & 7 deletions models/review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,57 @@ func TestGetReviewersByIssueID(t *testing.T) {
}

func TestDismissReview(t *testing.T) {
review1 := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
review2 := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.NoError(t, DismissReview(review1, true))
assert.NoError(t, DismissReview(review2, true))
assert.NoError(t, DismissReview(review2, true))
assert.NoError(t, DismissReview(review2, false))
assert.NoError(t, DismissReview(review2, false))
assert.NoError(t, PrepareTestDatabase())

rejectReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
requestReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
approveReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 8}).(*Review)
assert.False(t, rejectReviewExample.Dismissed)
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)

}

0 comments on commit 9d07fac

Please sign in to comment.