@@ -14,8 +14,10 @@ import (
1414	"testing" 
1515	"time" 
1616
17+ 	"code.gitea.io/gitea/models/db" 
1718	issues_model "code.gitea.io/gitea/models/issues" 
1819	repo_model "code.gitea.io/gitea/models/repo" 
20+ 	"code.gitea.io/gitea/models/unit" 
1921	"code.gitea.io/gitea/models/unittest" 
2022	user_model "code.gitea.io/gitea/models/user" 
2123	"code.gitea.io/gitea/modules/indexer/issues" 
@@ -24,6 +26,7 @@ import (
2426	api "code.gitea.io/gitea/modules/structs" 
2527	"code.gitea.io/gitea/modules/test" 
2628	"code.gitea.io/gitea/tests" 
29+ 	"xorm.io/builder" 
2730
2831	"github.com/PuerkitoBio/goquery" 
2932	"github.com/stretchr/testify/assert" 
@@ -488,7 +491,35 @@ func TestIssueRedirect(t *testing.T) {
488491	resp  =  session .MakeRequest (t , req , http .StatusSeeOther )
489492	assert .Equal (t , "/" + path .Join ("org26" , "repo_external_tracker_alpha" , "pulls" , "1" ), test .RedirectURL (resp ))
490493
491- 	// FIXME: add a test to check that the PR redirection works if the issue unit is disabled 
494+ 	// test to check that the PR redirection works if the issue unit is disabled 
495+ 	// repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request) 
496+ 	// will redirect to pulls 
497+ 	req  =  NewRequest (t , "GET" , path .Join ("user2" , "repo1" , "issues" , "2" ))
498+ 	resp  =  session .MakeRequest (t , req , http .StatusSeeOther )
499+ 	assert .Equal (t , "/" + path .Join ("user2" , "repo1" , "pulls" , "2" ), test .RedirectURL (resp ))
500+ 
501+ 	// disable issue unit 
502+ 	repoUnit , exist , err  :=  db .Get [repo_model.RepoUnit ](t .Context (), builder.Eq {
503+ 		"repo_id" : 1 ,
504+ 		"type" :    unit .TypeIssues ,
505+ 	})
506+ 	assert .NoError (t , err )
507+ 	assert .True (t , exist )
508+ 	assert .NotNil (t , repoUnit )
509+ 
510+ 	_ , err  =  db .DeleteByID [repo_model.RepoUnit ](t .Context (), repoUnit .ID )
511+ 	assert .NoError (t , err )
512+ 
513+ 	defer  func () {
514+ 		repoUnit .ID  =  0 
515+ 		assert .NoError (t , db .Insert (t .Context (), repoUnit ))
516+ 	}()
517+ 
518+ 	// even if the issue unit is disabled, visiting an issue which is a pull request 
519+ 	// will still redirect to pull request 
520+ 	req  =  NewRequest (t , "GET" , path .Join ("user2" , "repo1" , "issues" , "2" ))
521+ 	resp  =  session .MakeRequest (t , req , http .StatusSeeOther )
522+ 	assert .Equal (t , "/" + path .Join ("user2" , "repo1" , "pulls" , "2" ), test .RedirectURL (resp ))
492523}
493524
494525func  TestSearchIssues (t  * testing.T ) {
0 commit comments