55use Illuminate \Foundation \Testing \RefreshDatabase ;
66use Illuminate \Support \Facades \Auth ;
77use ProcessMaker \Models \Process ;
8+ use ProcessMaker \Models \ProcessCategory ;
89use ProcessMaker \Models \ProcessLaunchpad ;
910use ProcessMaker \Models \ProcessRequest ;
1011use Tests \Feature \Shared \RequestHelper ;
@@ -16,6 +17,8 @@ class ProcessLaunchpadTest extends TestCase
1617
1718 const API_TEST_URL = '/process_launchpad ' ;
1819
20+ const PROCESSES_API_TEST_URL = '/process_bookmarks/processes ' ;
21+
1922 const STRUCTURE = [
2023 'launchpad ' ,
2124 'media ' ,
@@ -49,6 +52,53 @@ public function testGetProcessLaunchpad()
4952 $ this ->assertNotEmpty ($ response );
5053 }
5154
55+ public function testGetProcessesReturnsEmptyCollectionForNonNumericCategory ()
56+ {
57+ Process::factory ()->create ();
58+
59+ $ response = $ this ->apiCall ('GET ' , self ::PROCESSES_API_TEST_URL , [
60+ 'category ' => 'lorem ' ,
61+ ]);
62+
63+ $ response ->assertOk ()
64+ ->assertJsonCount (0 , 'data ' )
65+ ->assertJsonPath ('meta.total ' , 0 );
66+ }
67+
68+ public function testGetProcessesReturnsEmptyCollectionForMissingNumericCategory ()
69+ {
70+ Process::factory ()->create ();
71+
72+ $ response = $ this ->apiCall ('GET ' , self ::PROCESSES_API_TEST_URL , [
73+ 'category ' => '0 ' ,
74+ ]);
75+
76+ $ response ->assertOk ()
77+ ->assertJsonCount (0 , 'data ' )
78+ ->assertJsonPath ('meta.total ' , 0 );
79+ }
80+
81+ public function testGetProcessesFiltersByValidCategory ()
82+ {
83+ $ category = ProcessCategory::factory ()->create ();
84+ $ otherCategory = ProcessCategory::factory ()->create ();
85+ $ process = Process::factory ()->create ([
86+ 'process_category_id ' => $ category ->id ,
87+ ]);
88+ Process::factory ()->create ([
89+ 'process_category_id ' => $ otherCategory ->id ,
90+ ]);
91+
92+ $ response = $ this ->apiCall ('GET ' , self ::PROCESSES_API_TEST_URL , [
93+ 'category ' => $ category ->id ,
94+ ]);
95+
96+ $ response ->assertOk ()
97+ ->assertJsonCount (1 , 'data ' )
98+ ->assertJsonPath ('data.0.id ' , $ process ->id )
99+ ->assertJsonPath ('meta.total ' , 1 );
100+ }
101+
52102 /**
53103 * Test store process launchpad
54104 */
0 commit comments