File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
tests/Feature/Controllers Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -331,7 +331,9 @@ public function test_getting_a_list_of_resources_including_belongs_to_has_many_r
331331 $ matchingModelBelongsToRelation
332332 ->only ((new BelongsToResource ())->getFields (app ()->make (RestRequest::class))),
333333 [
334- 'models ' => $ matchingModelBelongsToRelation ->models
334+ 'models ' => $ matchingModelBelongsToRelation ->models ()
335+ ->orderBy ('id ' )
336+ ->get ()
335337 ->map (function ($ model ) {
336338 return $ model ->only ((new ModelResource ())->getFields (app ()->make (RestRequest::class)));
337339 })
@@ -346,6 +348,32 @@ public function test_getting_a_list_of_resources_including_belongs_to_has_many_r
346348 );
347349 }
348350
351+ public function test_including_unauthorized_nested_relation_returns_validation_error (): void
352+ {
353+ Gate::policy (Model::class, GreenPolicy::class);
354+ Gate::policy (BelongsToRelation::class, GreenPolicy::class);
355+
356+ $ response = $ this ->post (
357+ '/api/models/search ' ,
358+ [
359+ 'search ' => [
360+ 'includes ' => [
361+ [
362+ 'relation ' => 'belongsToRelation ' ,
363+ 'includes ' => [
364+ ['relation ' => 'unauthorized ' ],
365+ ],
366+ ],
367+ ],
368+ ],
369+ ],
370+ ['Accept ' => 'application/json ' ]
371+ );
372+
373+ $ response ->assertStatus (422 );
374+ $ response ->assertExactJsonStructure (['message ' , 'errors ' => ['search.includes.0.includes.0.relation ' ]]);
375+ }
376+
349377 public function test_getting_a_list_of_resources_including_distant_relation_with_intermediary_search_query_condition (): void
350378 {
351379 $ matchingModel = ModelFactory::new ()->create (
You can’t perform that action at this time.
0 commit comments