@@ -116,6 +116,31 @@ public function test_getting_a_list_of_resources_with_not_allowed_sort_field():
116116 $ response ->assertJsonStructure (['message ' , 'errors ' => ['search.sorts.0.field ' ]]);
117117 }
118118
119+ public function test_getting_a_list_of_resources_with_not_allowed_instruction (): void
120+ {
121+ ModelFactory::new ()->count (2 )->create ();
122+
123+ Gate::policy (Model::class, GreenPolicy::class);
124+
125+ $ response = $ this ->post (
126+ '/api/searchable-models/search ' ,
127+ [
128+ 'search ' => [
129+ 'text ' => [
130+ 'value ' => 'text ' ,
131+ ],
132+ 'instructions ' => [
133+ ['name ' => 'not_authorized_instruction ' ],
134+ ],
135+ ],
136+ ],
137+ ['Accept ' => 'application/json ' ]
138+ );
139+
140+ $ response ->assertStatus (422 );
141+ $ response ->assertJsonStructure (['message ' , 'errors ' => ['search.instructions.0.name ' ]]);
142+ }
143+
119144 public function test_getting_a_list_of_resources_with_allowed_filter_field (): void
120145 {
121146 ModelFactory::new ()->count (2 )->create ();
@@ -172,6 +197,34 @@ public function test_getting_a_list_of_resources_with_allowed_sort_field(): void
172197 );
173198 }
174199
200+ public function test_getting_a_list_of_resources_with_allowed_instruction (): void
201+ {
202+ ModelFactory::new ()->count (2 )->create ();
203+
204+ Gate::policy (Model::class, GreenPolicy::class);
205+
206+ $ response = $ this ->post (
207+ '/api/searchable-models/search ' ,
208+ [
209+ 'search ' => [
210+ 'text ' => [
211+ 'value ' => 'text ' ,
212+ ],
213+ 'instructions ' => [
214+ ['name ' => 'numbered ' ],
215+ ],
216+ ],
217+ ],
218+ ['Accept ' => 'application/json ' ]
219+ );
220+
221+ $ this ->assertResourcePaginated (
222+ $ response ,
223+ [],
224+ new ModelResource ()
225+ );
226+ }
227+
175228 public function test_getting_a_list_of_resources_with_not_allowed_filter_nested (): void
176229 {
177230 ModelFactory::new ()->count (2 )->create ();
@@ -227,6 +280,31 @@ public function test_getting_a_list_of_resources_with_not_allowed_filter_type():
227280 $ response ->assertJsonStructure (['message ' , 'errors ' => ['search.filters.0.type ' ]]);
228281 }
229282
283+ public function test_getting_a_list_of_resources_with_not_allowed_scopes (): void
284+ {
285+ ModelFactory::new ()->count (2 )->create ();
286+
287+ Gate::policy (Model::class, GreenPolicy::class);
288+
289+ $ response = $ this ->post (
290+ '/api/searchable-models/search ' ,
291+ [
292+ 'search ' => [
293+ 'text ' => [
294+ 'value ' => 'text ' ,
295+ ],
296+ 'scopes ' => [
297+ ['name ' => 'numbered ' ],
298+ ],
299+ ],
300+ ],
301+ ['Accept ' => 'application/json ' ]
302+ );
303+
304+ $ response ->assertStatus (422 );
305+ $ response ->assertJsonStructure (['message ' , 'errors ' => ['search.scopes ' ]]);
306+ }
307+
230308 public function test_getting_a_list_of_resources_with_scout (): void
231309 {
232310 ModelFactory::new ()->count (2 )->create ();
0 commit comments