44package  shared
55
66import  (
7- 	"net/url" 
87	"testing" 
98	"time" 
109
1110	actions_model "code.gitea.io/gitea/models/actions" 
1211	"code.gitea.io/gitea/models/unittest" 
13- 	"code.gitea.io/gitea/services/context" 
1412	"code.gitea.io/gitea/services/contexttest" 
1513
1614	"github.com/stretchr/testify/assert" 
@@ -20,15 +18,6 @@ func TestMain(m *testing.M) {
2018	unittest .MainTest (m )
2119}
2220
23- // setFormValue is a helper function to set form values in test context 
24- func  setFormValue (ctx  * context.APIContext , key , value  string ) {
25- 	// Initialize the form if it's nil 
26- 	if  ctx .Req .Form  ==  nil  {
27- 		ctx .Req .Form  =  make (url.Values )
28- 	}
29- 	ctx .Req .Form .Set (key , value )
30- }
31- 
3221// TestListRunsWorkflowFiltering tests that ListRuns properly handles 
3322// the workflow_id path parameter for filtering runs by workflow. 
3423func  TestListRunsWorkflowFiltering (t  * testing.T ) {
@@ -77,62 +66,49 @@ func TestListRunsExcludePullRequestsParam(t *testing.T) {
7766	unittest .PrepareTestEnv (t )
7867
7968	// Test case 1: With exclude_pull_requests=true 
80- 	ctx , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
69+ 	ctx , _  :=  contexttest .MockAPIContext (t , "user2/repo1?exclude_pull_requests=true " )
8170	contexttest .LoadRepo (t , ctx , 1 )
8271	contexttest .LoadUser (t , ctx , 2 )
8372
84- 	// Set up form value 
85- 	setFormValue (ctx , "exclude_pull_requests" , "true" )
86- 
8773	// Call the actual parsing logic from ListRuns 
8874	opts  :=  actions_model.FindRunOptions {
8975		RepoID : ctx .Repo .Repository .ID ,
9076	}
9177
92- 	if  exclude  :=  ctx .FormString ("exclude_pull_requests" ); exclude  !=  ""  {
93- 		if  exclude  ==  "true"  ||  exclude  ==  "1"  {
94- 			opts .ExcludePullRequests  =  true 
95- 		}
78+ 	if  ctx .FormBool ("exclude_pull_requests" ) {
79+ 		opts .ExcludePullRequests  =  true 
9680	}
9781
9882	// Verify the ExcludePullRequests is correctly set based on the form value 
9983	assert .True (t , opts .ExcludePullRequests )
10084
10185	// Test case 2: With exclude_pull_requests=1 
102- 	ctx2 , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
86+ 	ctx2 , _  :=  contexttest .MockAPIContext (t , "user2/repo1?exclude_pull_requests=1 " )
10387	contexttest .LoadRepo (t , ctx2 , 1 )
10488	contexttest .LoadUser (t , ctx2 , 2 )
10589
106- 	setFormValue (ctx2 , "exclude_pull_requests" , "1" )
107- 
10890	opts2  :=  actions_model.FindRunOptions {
10991		RepoID : ctx2 .Repo .Repository .ID ,
11092	}
11193
112- 	if  exclude  :=  ctx2 .FormString ("exclude_pull_requests" ); exclude  !=  ""  {
113- 		if  exclude  ==  "true"  ||  exclude  ==  "1"  {
114- 			opts2 .ExcludePullRequests  =  true 
115- 		}
94+ 	if  ctx2 .FormBool ("exclude_pull_requests" ) {
95+ 		opts2 .ExcludePullRequests  =  true 
11696	}
11797
11898	// Verify the ExcludePullRequests is correctly set for "1" value 
11999	assert .True (t , opts2 .ExcludePullRequests )
120100
121101	// Test case 3: With exclude_pull_requests=false (should not set the flag) 
122- 	ctx3 , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
102+ 	ctx3 , _  :=  contexttest .MockAPIContext (t , "user2/repo1?exclude_pull_requests=false " )
123103	contexttest .LoadRepo (t , ctx3 , 1 )
124104	contexttest .LoadUser (t , ctx3 , 2 )
125105
126- 	setFormValue (ctx3 , "exclude_pull_requests" , "false" )
127- 
128106	opts3  :=  actions_model.FindRunOptions {
129107		RepoID : ctx3 .Repo .Repository .ID ,
130108	}
131109
132- 	if  exclude  :=  ctx3 .FormString ("exclude_pull_requests" ); exclude  !=  ""  {
133- 		if  exclude  ==  "true"  ||  exclude  ==  "1"  {
134- 			opts3 .ExcludePullRequests  =  true 
135- 		}
110+ 	if  ctx3 .FormBool ("exclude_pull_requests" ) {
111+ 		opts3 .ExcludePullRequests  =  true 
136112	}
137113
138114	// Verify the ExcludePullRequests is NOT set for "false" value 
@@ -147,12 +123,10 @@ func TestListRunsCheckSuiteIDParam(t *testing.T) {
147123	const  testSuiteID  int64  =  12345 
148124
149125	// Test case: With check_suite_id parameter 
150- 	ctx , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
126+ 	ctx , _  :=  contexttest .MockAPIContext (t , "user2/repo1?check_suite_id=12345 " )
151127	contexttest .LoadRepo (t , ctx , 1 )
152128	contexttest .LoadUser (t , ctx , 2 )
153129
154- 	setFormValue (ctx , "check_suite_id" , "12345" )
155- 
156130	// Call the actual parsing logic from ListRuns 
157131	opts  :=  actions_model.FindRunOptions {
158132		RepoID : ctx .Repo .Repository .ID ,
@@ -173,12 +147,10 @@ func TestListRunsCreatedParam(t *testing.T) {
173147	unittest .PrepareTestEnv (t )
174148
175149	// Test case 1: With created in date range format 
176- 	ctx , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
150+ 	ctx , _  :=  contexttest .MockAPIContext (t , "user2/repo1?created=2023-01-01..2023-12-31 " )
177151	contexttest .LoadRepo (t , ctx , 1 )
178152	contexttest .LoadUser (t , ctx , 2 )
179153
180- 	setFormValue (ctx , "created" , "2023-01-01..2023-12-31" )
181- 
182154	opts  :=  actions_model.FindRunOptions {
183155		RepoID : ctx .Repo .Repository .ID ,
184156	}
@@ -204,12 +176,10 @@ func TestListRunsCreatedParam(t *testing.T) {
204176	assert .Equal (t , expectedEnd , opts .CreatedBefore )
205177
206178	// Test case 2: With created in ">=" format 
207- 	ctx2 , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
179+ 	ctx2 , _  :=  contexttest .MockAPIContext (t , "user2/repo1?created=>=2023-01-01 " )
208180	contexttest .LoadRepo (t , ctx2 , 1 )
209181	contexttest .LoadUser (t , ctx2 , 2 )
210182
211- 	setFormValue (ctx2 , "created" , ">=2023-01-01" )
212- 
213183	opts2  :=  actions_model.FindRunOptions {
214184		RepoID : ctx2 .Repo .Repository .ID ,
215185	}
@@ -229,12 +199,10 @@ func TestListRunsCreatedParam(t *testing.T) {
229199	assert .True (t , opts2 .CreatedBefore .IsZero ())
230200
231201	// Test case 3: With created in exact date format 
232- 	ctx3 , _  :=  contexttest .MockAPIContext (t , "user2/repo1" )
202+ 	ctx3 , _  :=  contexttest .MockAPIContext (t , "user2/repo1?created=2023-06-15 " )
233203	contexttest .LoadRepo (t , ctx3 , 1 )
234204	contexttest .LoadUser (t , ctx3 , 2 )
235205
236- 	setFormValue (ctx3 , "created" , "2023-06-15" )
237- 
238206	opts3  :=  actions_model.FindRunOptions {
239207		RepoID : ctx3 .Repo .Repository .ID ,
240208	}
0 commit comments