Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ public function getProcesses(Request $request)
$category = $request->input('category', null);
if ($category === 'recent') {
$processes->orderByRecentRequests();
} elseif (!empty($category)) {
$processes->processCategory($category);
} elseif ($category !== null && $category !== '') {
$categoryId = filter_var($category, FILTER_VALIDATE_INT);
if ($categoryId === false) {
$processes->whereRaw('1 = 0');
} else {
$processes->processCategory($categoryId);
}
}
// Filter pmql
$pmql = $request->input('pmql', '');
Expand Down
50 changes: 50 additions & 0 deletions tests/Feature/Api/ProcessLaunchpadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessCategory;
use ProcessMaker\Models\ProcessLaunchpad;
use ProcessMaker\Models\ProcessRequest;
use Tests\Feature\Shared\RequestHelper;
Expand All @@ -16,6 +17,8 @@ class ProcessLaunchpadTest extends TestCase

const API_TEST_URL = '/process_launchpad';

const PROCESSES_API_TEST_URL = '/process_bookmarks/processes';

const STRUCTURE = [
'launchpad',
'media',
Expand Down Expand Up @@ -49,6 +52,53 @@ public function testGetProcessLaunchpad()
$this->assertNotEmpty($response);
}

public function testGetProcessesReturnsEmptyCollectionForNonNumericCategory()
{
Process::factory()->create();

$response = $this->apiCall('GET', self::PROCESSES_API_TEST_URL, [
'category' => 'lorem',
]);

$response->assertOk()
->assertJsonCount(0, 'data')
->assertJsonPath('meta.total', 0);
}

public function testGetProcessesReturnsEmptyCollectionForMissingNumericCategory()
{
Process::factory()->create();

$response = $this->apiCall('GET', self::PROCESSES_API_TEST_URL, [
'category' => '0',
]);

$response->assertOk()
->assertJsonCount(0, 'data')
->assertJsonPath('meta.total', 0);
}

public function testGetProcessesFiltersByValidCategory()
{
$category = ProcessCategory::factory()->create();
$otherCategory = ProcessCategory::factory()->create();
$process = Process::factory()->create([
'process_category_id' => $category->id,
]);
Process::factory()->create([
'process_category_id' => $otherCategory->id,
]);

$response = $this->apiCall('GET', self::PROCESSES_API_TEST_URL, [
'category' => $category->id,
]);

$response->assertOk()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.id', $process->id)
->assertJsonPath('meta.total', 1);
}

/**
* Test store process launchpad
*/
Expand Down
Loading