Skip to content

Commit

Permalink
Adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmPaulis committed Dec 7, 2023
1 parent 0d01ffc commit 70e09ae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
13 changes: 3 additions & 10 deletions ProcessMaker/Http/Controllers/Api/BookmarkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function index(Request $request)
}
// Get the processes
$processes = $processes
->select('processes.*')
->select('processes.*', 'bookmark.id as bookmark_id')
->leftJoin('user_process_bookmarks as bookmark', 'bookmark.process_id', '=', 'processes.id')
->where('bookmark.user_id', $user->id)
->get()
Expand All @@ -54,17 +54,10 @@ public function store(Request $request, Process $process)
return new ApiResource($bookmark->refresh());
}

public function destroy(Request $request, Process $process)
public function destroy(Bookmark $bookmark)
{
// Get the current user
if ($request->user_id !== Auth::user()->id) {
abort(403);
}

// Delete bookmark
Bookmark::where('process_id', $process->id)
->where('user_id', $request->user_id)
->delete();
$bookmark->delete();

return response([], 204);
}
Expand Down
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
// Process Bookmark
Route::get('process_bookmarks', [BookmarkController::class, 'index'])->name('process_bookmarks.index')->middleware('can:view-processes');
Route::post('process_bookmarks/{process}', [BookmarkController::class, 'store'])->name('process_bookmarks.store')->middleware('can:edit-processes');
Route::delete('process_bookmarks/{process}', [BookmarkController::class, 'destroy'])->name('process_bookmarks.destroy')->middleware('can:edit-processes');
Route::delete('process_bookmarks/{bookmark}', [BookmarkController::class, 'destroy'])->name('process_bookmarks.destroy')->middleware('can:edit-processes');

// Process Categories
Route::get('process_categories', [ProcessCategoryController::class, 'index'])->name('process_categories.index')->middleware('can:view-process-categories');
Expand Down
24 changes: 2 additions & 22 deletions tests/Feature/Api/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,15 @@ public function testStoreBookmark()
$response->assertStatus(201);
}

/**
* Test delete bookmark with error 403
*/
public function testDeleteBookmark403()
{
// Create a fake
$process = Process::factory()->create();
// Call the api DELETE
$response = $this->apiCall('DELETE', self::API_TEST_URL .'/'. $process->id, []);
// Validate the header status code
$response->assertStatus(403);
}


/**
* Test delete bookmark
*/
public function testDeleteBookmark()
{
// Create a fake
$process = Process::factory()->create();
$user = User::factory()->create();
Auth::login($user);
// Call the api POST
$this->apiCall('POST', self::API_TEST_URL .'/'. $process->id, []);
$bookmark = Bookmark::factory()->create();
// Call the api DELETE
$response = $this->apiCall('DELETE', self::API_TEST_URL .'/'. $process->id, [
'user_id' => $user->id
]);
$response = $this->apiCall('DELETE', self::API_TEST_URL .'/'. $bookmark->id);
// Validate the header status code
$response->assertStatus(204);
}
Expand Down

0 comments on commit 70e09ae

Please sign in to comment.