File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
tests/Feature/Controllers Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace Lomkit \Rest \Http \Requests ;
44
5+ use Illuminate \Validation \Rule ;
56use Lomkit \Rest \Http \Resource ;
67
78class DestroyRequest extends RestRequest
@@ -32,10 +33,15 @@ public function rules()
3233 */
3334 public function destroyRules (Resource $ resource )
3435 {
36+ $ model = $ resource ::newModel ();
37+
3538 return [
3639 'resources ' => [
3740 'required ' , 'array ' ,
3841 ],
42+ 'resources.* ' => [
43+ Rule::exists ($ model ->getTable (), $ model ->getKeyName ())
44+ ]
3945 ];
4046 }
4147}
Original file line number Diff line number Diff line change @@ -56,6 +56,28 @@ public function test_deleting_a_non_authorized_model_with_an_authorized_one(): v
5656 $ this ->assertDatabaseHas ('models ' , $ modelDeletable ->only ('id ' ));
5757 }
5858
59+ public function test_deleting_a_not_existing_model (): void
60+ {
61+ $ model = ModelFactory::new ()->count (1 )->createOne ();
62+
63+ Gate::policy (Model::class, GreenPolicy::class);
64+
65+ $ response = $ this ->delete (
66+ '/api/models ' ,
67+ [
68+ 'resources ' => [
69+ 'undefined-id ' ,
70+ $ model ->getKey ()
71+ ],
72+ ],
73+ ['Accept ' => 'application/json ' ]
74+ );
75+
76+ $ response ->assertStatus (422 );
77+ $ response ->assertExactJsonStructure (['message ' , 'errors ' => ['resources.0 ' ]]);
78+ $ this ->assertDatabaseHas ('models ' , $ model ->only ('id ' ));
79+ }
80+
5981 public function test_deleting_a_model (): void
6082 {
6183 $ model = ModelFactory::new ()->count (1 )->createOne ();
You can’t perform that action at this time.
0 commit comments