@@ -142,3 +142,176 @@ impl Command for PrCommand {
142142 Ok ( ( ) )
143143 }
144144}
145+
146+ #[ cfg( test) ]
147+ mod tests {
148+ use super :: * ;
149+ use crate :: config:: { Config , Repository } ;
150+
151+ #[ tokio:: test]
152+ async fn test_pr_command_no_repositories ( ) {
153+ let config = Config {
154+ repositories : vec ! [ ] ,
155+ recipes : vec ! [ ] ,
156+ } ;
157+ let context = CommandContext {
158+ config,
159+ tag : vec ! [ ] ,
160+ exclude_tag : vec ! [ ] ,
161+ repos : None ,
162+ parallel : false ,
163+ } ;
164+
165+ let pr_command = PrCommand {
166+ title : "Test PR" . to_string ( ) ,
167+ body : "Test body" . to_string ( ) ,
168+ branch_name : None ,
169+ base_branch : None ,
170+ commit_msg : None ,
171+ draft : false ,
172+ token : "test_token" . to_string ( ) ,
173+ create_only : false ,
174+ } ;
175+
176+ let result = pr_command. execute ( & context) . await ;
177+ assert ! ( result. is_ok( ) ) ;
178+ }
179+
180+ #[ tokio:: test]
181+ async fn test_pr_command_with_filters ( ) {
182+ let repository = Repository {
183+ name : "test-repo" . to_string ( ) ,
184+ url : "https://github.com/test/repo.git" . to_string ( ) ,
185+ path : Some ( "./test-repo" . to_string ( ) ) ,
186+ branch : None ,
187+ tags : vec ! [ "api" . to_string( ) ] ,
188+ config_dir : None ,
189+ } ;
190+
191+ let config = Config {
192+ repositories : vec ! [ repository] ,
193+ recipes : vec ! [ ] ,
194+ } ;
195+
196+ let context = CommandContext {
197+ config,
198+ tag : vec ! [ "nonexistent" . to_string( ) ] ,
199+ exclude_tag : vec ! [ ] ,
200+ repos : None ,
201+ parallel : false ,
202+ } ;
203+
204+ let pr_command = PrCommand {
205+ title : "Test PR" . to_string ( ) ,
206+ body : "Test body" . to_string ( ) ,
207+ branch_name : Some ( "feature/test" . to_string ( ) ) ,
208+ base_branch : Some ( "main" . to_string ( ) ) ,
209+ commit_msg : Some ( "Test commit" . to_string ( ) ) ,
210+ draft : true ,
211+ token : "test_token" . to_string ( ) ,
212+ create_only : true ,
213+ } ;
214+
215+ let result = pr_command. execute ( & context) . await ;
216+ assert ! ( result. is_ok( ) ) ;
217+ }
218+
219+ #[ tokio:: test]
220+ async fn test_pr_command_execution_paths ( ) {
221+ let repository = Repository {
222+ name : "test-repo" . to_string ( ) ,
223+ url : "https://github.com/test/repo.git" . to_string ( ) ,
224+ path : Some ( "./nonexistent-path" . to_string ( ) ) ,
225+ branch : None ,
226+ tags : vec ! [ "backend" . to_string( ) ] ,
227+ config_dir : None ,
228+ } ;
229+
230+ let config = Config {
231+ repositories : vec ! [ repository] ,
232+ recipes : vec ! [ ] ,
233+ } ;
234+
235+ let context = CommandContext {
236+ config,
237+ tag : vec ! [ "backend" . to_string( ) ] ,
238+ exclude_tag : vec ! [ ] ,
239+ repos : None ,
240+ parallel : false ,
241+ } ;
242+
243+ let pr_command = PrCommand {
244+ title : "Integration Test PR" . to_string ( ) ,
245+ body : "Integration test body" . to_string ( ) ,
246+ branch_name : None ,
247+ base_branch : None ,
248+ commit_msg : None ,
249+ draft : false ,
250+ token : "test_token" . to_string ( ) ,
251+ create_only : false ,
252+ } ;
253+
254+ // This will hit the error handling paths since the repo doesn't exist
255+ let result = pr_command. execute ( & context) . await ;
256+ assert ! ( result. is_err( ) ) ; // Expect error due to nonexistent repository
257+ }
258+
259+ #[ tokio:: test]
260+ async fn test_pr_command_parallel_execution ( ) {
261+ let repository = Repository {
262+ name : "test-repo-parallel" . to_string ( ) ,
263+ url : "https://github.com/test/repo.git" . to_string ( ) ,
264+ path : Some ( "./nonexistent-parallel" . to_string ( ) ) ,
265+ branch : None ,
266+ tags : vec ! [ "test" . to_string( ) ] ,
267+ config_dir : None ,
268+ } ;
269+
270+ let config = Config {
271+ repositories : vec ! [ repository] ,
272+ recipes : vec ! [ ] ,
273+ } ;
274+
275+ let context = CommandContext {
276+ config,
277+ tag : vec ! [ "test" . to_string( ) ] ,
278+ exclude_tag : vec ! [ ] ,
279+ repos : None ,
280+ parallel : true , // Test parallel execution path
281+ } ;
282+
283+ let pr_command = PrCommand {
284+ title : "Parallel Test PR" . to_string ( ) ,
285+ body : "Parallel test body" . to_string ( ) ,
286+ branch_name : None ,
287+ base_branch : None ,
288+ commit_msg : None ,
289+ draft : false ,
290+ token : "test_token" . to_string ( ) ,
291+ create_only : false ,
292+ } ;
293+
294+ // This will hit the parallel execution error handling paths
295+ let result = pr_command. execute ( & context) . await ;
296+ assert ! ( result. is_err( ) ) ; // Expect error due to nonexistent repository
297+ }
298+
299+ #[ tokio:: test]
300+ async fn test_pr_command_module_exists ( ) {
301+ // Test to ensure the PR command module is properly accessible
302+ let pr_command = PrCommand {
303+ title : "Module Test" . to_string ( ) ,
304+ body : "Module test body" . to_string ( ) ,
305+ branch_name : None ,
306+ base_branch : None ,
307+ commit_msg : None ,
308+ draft : false ,
309+ token : "test_token" . to_string ( ) ,
310+ create_only : false ,
311+ } ;
312+
313+ assert_eq ! ( pr_command. title, "Module Test" ) ;
314+ assert ! ( !pr_command. draft) ;
315+ assert ! ( !pr_command. create_only) ;
316+ }
317+ }
0 commit comments