|
19 | 19 |
|
20 | 20 | namespace LaravelJsonApi\Laravel\Tests\Integration\Routing;
|
21 | 21 |
|
| 22 | +use App\Http\Controllers\Api\V1\PostController; |
22 | 23 | use Illuminate\Contracts\Routing\Registrar;
|
| 24 | +use Illuminate\Support\Facades\Route; |
23 | 25 | use LaravelJsonApi\Laravel\Facades\JsonApiRoute;
|
24 | 26 |
|
25 | 27 | class ActionsTest extends TestCase
|
@@ -244,4 +246,29 @@ public function testIdConstraintWorks(string $method): void
|
244 | 246 |
|
245 | 247 | $this->assertNotFound($method, '/api/v1/posts/123abc/-actions/foo-bar');
|
246 | 248 | }
|
| 249 | + |
| 250 | + /** |
| 251 | + * @see https://github.com/laravel-json-api/laravel/issues/90 |
| 252 | + */ |
| 253 | + public function testWithMiddleware(): void |
| 254 | + { |
| 255 | + $server = $this->createServer('v1'); |
| 256 | + $this->createSchema($server, 'posts', '\d+'); |
| 257 | + |
| 258 | + $this->defaultApiRoutes(function () { |
| 259 | + Route::name('api.')->middleware('my-middleware1')->group(function () { |
| 260 | + JsonApiRoute::server('v1')->prefix('v1')->resources(function ($server) { |
| 261 | + $server->resource('posts', PostController::class) |
| 262 | + ->actions(function ($actions) { |
| 263 | + $actions->withId()->get('image'); |
| 264 | + })->middleware('my-middleware2'); |
| 265 | + }); |
| 266 | + }); |
| 267 | + }); |
| 268 | + |
| 269 | + $route = $this->assertMatch('GET', '/api/v1/posts/123/image'); |
| 270 | + $this->assertSame("App\Http\Controllers\Api\V1\PostController@image", $route->action['controller']); |
| 271 | + $this->assertSame("api.v1.posts.image", $route->getName()); |
| 272 | + $this->assertSame(['api', 'my-middleware1', 'jsonapi:v1', 'my-middleware2'], $route->action['middleware']); |
| 273 | + } |
247 | 274 | }
|
0 commit comments