Skip to content

Commit b7b5f65

Browse files
committed
ai feedback
1 parent aed897b commit b7b5f65

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/Feature/Controllers/SearchIncludingRelationshipsOperationsTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff 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(

0 commit comments

Comments
 (0)