@@ -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"
@@ -474,19 +476,38 @@ func TestIssueRedirect(t *testing.T) {
474476 session := loginUser (t , "user2" )
475477
476478 // Test external tracker where style not set (shall default numeric)
477- req := NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker" , " issues" , "1" ) )
479+ req := NewRequest (t , "GET" , "/ org26/ repo_external_tracker/ issues/1" )
478480 resp := session .MakeRequest (t , req , http .StatusSeeOther )
479481 assert .Equal (t , "https://tracker.com/org26/repo_external_tracker/issues/1" , test .RedirectURL (resp ))
480482
481483 // Test external tracker with numeric style
482- req = NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker_numeric" , " issues" , "1" ) )
484+ req = NewRequest (t , "GET" , "/ org26/ repo_external_tracker_numeric/ issues/1" )
483485 resp = session .MakeRequest (t , req , http .StatusSeeOther )
484486 assert .Equal (t , "https://tracker.com/org26/repo_external_tracker_numeric/issues/1" , test .RedirectURL (resp ))
485487
486488 // Test external tracker with alphanumeric style (for a pull request)
487- req = NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker_alpha" , " issues" , "1" ) )
489+ req = NewRequest (t , "GET" , "/ org26/ repo_external_tracker_alpha/ issues/1" )
488490 resp = session .MakeRequest (t , req , http .StatusSeeOther )
489- assert .Equal (t , "/" + path .Join ("org26" , "repo_external_tracker_alpha" , "pulls" , "1" ), test .RedirectURL (resp ))
491+ assert .Equal (t , "/org26/repo_external_tracker_alpha/pulls/1" , test .RedirectURL (resp ))
492+
493+ // test to check that the PR redirection works if the issue unit is disabled
494+ // repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request)
495+ // will redirect to pulls
496+ req = NewRequest (t , "GET" , "/user2/repo1/issues/2" )
497+ resp = session .MakeRequest (t , req , http .StatusSeeOther )
498+ assert .Equal (t , "/user2/repo1/pulls/2" , test .RedirectURL (resp ))
499+
500+ repoUnit := unittest .AssertExistsAndLoadBean (t , & repo_model.RepoUnit {RepoID : 1 , Type : unit .TypeIssues })
501+
502+ // disable issue unit, it will be reset
503+ _ , err := db .DeleteByID [repo_model.RepoUnit ](t .Context (), repoUnit .ID )
504+ assert .NoError (t , err )
505+
506+ // even if the issue unit is disabled, visiting an issue which is a pull request
507+ // will still redirect to pull request
508+ req = NewRequest (t , "GET" , "/user2/repo1/issues/2" )
509+ resp = session .MakeRequest (t , req , http .StatusSeeOther )
510+ assert .Equal (t , "/user2/repo1/pulls/2" , test .RedirectURL (resp ))
490511}
491512
492513func TestSearchIssues (t * testing.T ) {
0 commit comments