Skip to content

Commit

Permalink
Add without search method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vradev-ph committed Oct 11, 2023
1 parent 48040f7 commit 1dd160f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Http/Routing/PendingResourceRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,20 @@ public function withoutBatch(): PendingResourceRegistration

return $this;
}

/**
* Disables the search operation on the resource.
*
* @return $this
*/
public function withoutSearch(): PendingResourceRegistration
{
$except = Arr::get($this->options, 'except');

$except = array_merge($except, ['search']);

$this->except($except);

return $this;
}
}
45 changes: 45 additions & 0 deletions tests/Unit/OrionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,49 @@ function () {
$this->assertRouteRegistered('api.projects.users.batchDestroy', ['DELETE'], 'api/projects/{project}/users/batch', DummyController::class.'@batchDestroy');
$this->assertRouteRegistered('api.projects.users.batchRestore', ['POST'], 'api/projects/{project}/users/batch/restore', DummyController::class.'@batchRestore');
}

/** @test */
public function registering_resource_without_batch_removes_routes(): void
{
Route::group(
['as' => 'api.', 'prefix' => 'api'],
function () {
Orion::resource('projects', DummyController::class)->withoutBatch();
}
);

$this->assertRouteRegistered('api.projects.search', ['POST'], 'api/projects/search', DummyController::class.'@search');
$this->assertRouteRegistered('api.projects.index', ['GET', 'HEAD'], 'api/projects', DummyController::class.'@index');
$this->assertRouteRegistered('api.projects.store', ['POST'], 'api/projects', DummyController::class.'@store');
$this->assertRouteRegistered('api.projects.show', ['GET', 'HEAD'], 'api/projects/{project}', DummyController::class.'@show');
$this->assertRouteRegistered('api.projects.update', ['PUT', 'PATCH'], 'api/projects/{project}', DummyController::class.'@update');
$this->assertRouteRegistered('api.projects.destroy', ['DELETE'], 'api/projects/{project}', DummyController::class.'@destroy');

$this->assertRouteNotRegistered('api.projects.batchStore');
$this->assertRouteNotRegistered('api.projects.batchUpdate');
$this->assertRouteNotRegistered('api.projects.batchDestroy');
}

/** @test */
public function registering_resource_without_search_removes_routes(): void
{
Route::group(
['as' => 'api.', 'prefix' => 'api'],
function () {
Orion::resource('projects', DummyController::class)->withoutSearch();
}
);

$this->assertRouteNotRegistered('api.projects.search');

$this->assertRouteRegistered('api.projects.index', ['GET', 'HEAD'], 'api/projects', DummyController::class.'@index');
$this->assertRouteRegistered('api.projects.store', ['POST'], 'api/projects', DummyController::class.'@store');
$this->assertRouteRegistered('api.projects.show', ['GET', 'HEAD'], 'api/projects/{project}', DummyController::class.'@show');
$this->assertRouteRegistered('api.projects.update', ['PUT', 'PATCH'], 'api/projects/{project}', DummyController::class.'@update');
$this->assertRouteRegistered('api.projects.destroy', ['DELETE'], 'api/projects/{project}', DummyController::class.'@destroy');

$this->assertRouteRegistered('api.projects.batchStore', ['POST'], 'api/projects/batch', DummyController::class.'@batchStore');
$this->assertRouteRegistered('api.projects.batchUpdate', ['PATCH'], 'api/projects/batch', DummyController::class.'@batchUpdate');
$this->assertRouteRegistered('api.projects.batchDestroy', ['DELETE'], 'api/projects/batch', DummyController::class.'@batchDestroy');
}
}

0 comments on commit 1dd160f

Please sign in to comment.