From d71562e6695dc12400678f101c8d1b55c456f00e Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 30 Apr 2024 01:34:32 +0200 Subject: [PATCH] add test against deactivated user for GetReviewers --- models/repo/user_repo_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/models/repo/user_repo_test.go b/models/repo/user_repo_test.go index 4dd37a50b9..b2d2b66762 100644 --- a/models/repo/user_repo_test.go +++ b/models/repo/user_repo_test.go @@ -50,7 +50,9 @@ func TestRepoGetReviewers(t *testing.T) { ctx := db.DefaultContext reviewers, err := repo_model.GetReviewers(ctx, repo1, 2, 2) assert.NoError(t, err) - assert.Len(t, reviewers, 4) + if assert.Len(t, reviewers, 4) { + assert.ElementsMatch(t, []int64{1, 4, 9, 11}, []int64{reviewers[0].ID, reviewers[1].ID, reviewers[2].ID, reviewers[3].ID}) + } // should include doer if doer is not PR poster. reviewers, err = repo_model.GetReviewers(ctx, repo1, 11, 2) @@ -80,4 +82,13 @@ func TestRepoGetReviewers(t *testing.T) { reviewers, err = repo_model.GetReviewers(ctx, repo3, 2, 2) assert.NoError(t, err) assert.Len(t, reviewers, 1) + + // do not return deactivated users + user11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 11}) + user_model.UpdateUserCols(db.DefaultContext, user11, "is_active") + reviewers, err = repo_model.GetReviewers(ctx, repo1, 2, 2) + assert.NoError(t, err) + if assert.Len(t, reviewers, 3) { + assert.NotContains(t, []int64{reviewers[0].ID, reviewers[1].ID, reviewers[2].ID}, 11) + } }