Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
adding more test
  • Loading branch information
pmPaulis committed Sep 27, 2024
commit a755c6aadbc83f514a1976ea754091a4219b7065
4 changes: 3 additions & 1 deletion ProcessMaker/Http/Controllers/Api/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function indexCase(Request $request, User $user = null)
// Validate the inputs, including optional ones
$request->validate([
'case_number' => 'required|integer',
'status' => 'nullable|string|in:ACTIVE,INACTIVE',
'status' => 'nullable|string|in:ACTIVE,COMPLETED',
'order_by' => 'nullable|string|in:id,element_name,due_at,user.lastname,process.name',
'order_direction' => 'nullable|string|in:asc,desc',
'page' => 'nullable|integer|min:1',
Expand All @@ -192,6 +192,8 @@ public function indexCase(Request $request, User $user = null)
$query->getUser();
// Filter only the task related to the user
$this->applyForCurrentUser($query, $user);
// Exclude non visible task
$this->excludeNonVisibleTasks($query, $request);
// Apply ordering only if a valid order_by field is provided
$query->applyOrdering($request);

Expand Down
39 changes: 36 additions & 3 deletions tests/Feature/Api/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function test_index_case_requires_case_number()
}

/**
* Test indexCase returns tasks related to the case_number.
* Test indexCase returns active tasks related to the case_number.
*
* @return void
*/
public function test_index_case_returns_tasks_for_case_number()
public function test_index_case_returns_active_tasks_for_case_number()
{
// Simulate an authenticated user
$user = User::factory()->create();
Expand All @@ -64,7 +64,40 @@ public function test_index_case_returns_tasks_for_case_number()
]);

// Call the endpoint with the 'case_number' parameter
$response = $this->apiCall('GET', self::API_TASK_BY_CASE . "?case_number=$processRequest->case_number");
$filter = "?case_number=$processRequest->case_number";
$response = $this->apiCall('GET', self::API_TASK_BY_CASE . $filter);

// Check if the response is successful and contains the expected tasks
$response->assertStatus(200);
$this->assertCount(1, $response->json('data'));
$response->assertJsonStructure([
'data' => ['*' => self::TASK_BY_CASE_STRUCTURE],
'meta',
]);
}

/**
* Test indexCase returns completed tasks related to the case_number.
*
* @return void
*/
public function test_index_case_returns_inactive_tasks_for_case_number()
{
// Simulate an authenticated user
$user = User::factory()->create();
Auth::login($user);

// Create a ProcessRequestToken associated with a specific case_number
$processRequest = ProcessRequest::factory()->create();
ProcessRequestToken::factory()->create([
'user_id' => $user->id,
'status' => 'COMPLETED',
'process_request_id' => $processRequest->id, // id del ProcessRequest
]);

// Call the endpoint with the 'case_number' parameter
$filter = "?case_number=$processRequest->case_number&status=COMPLETED";
$response = $this->apiCall('GET', self::API_TASK_BY_CASE . $filter);

// Check if the response is successful and contains the expected tasks
$response->assertStatus(200);
Expand Down