Skip to content

Commit 473601f

Browse files
authored
Merge pull request #140 from Lomkit/fix/mutate-key
🐛 mutate crash when no mutate key provided
2 parents 5ccdac8 + 5817306 commit 473601f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Http/Requests/MutateRequest.php

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class MutateRequest extends RestRequest
1717
public function rules()
1818
{
1919
return [
20+
'mutate' => ['required'],
2021
'mutate.*' => new MutateRules(
2122
$this->route()->controller::newResource(),
2223
$this,

tests/Feature/Controllers/MutateCreateOperationsTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ public function test_creating_a_resource_using_not_authorized_field(): void
4141
$response->assertJsonStructure(['message', 'errors' => ['mutate.0.attributes']]);
4242
}
4343

44+
public function test_creating_a_resource_using_no_mutate_key(): void
45+
{
46+
Gate::policy(Model::class, GreenPolicy::class);
47+
48+
$response = $this->post(
49+
'/api/models/mutate',
50+
[],
51+
['Accept' => 'application/json']
52+
);
53+
54+
$response->assertStatus(422);
55+
$response->assertJsonStructure(['message', 'errors' => ['mutate']]);
56+
}
57+
4458
public function test_creating_a_resource_using_not_authorized_attach_root_operator(): void
4559
{
4660
Gate::policy(Model::class, GreenPolicy::class);

0 commit comments

Comments
 (0)