Skip to content

Commit 3105f53

Browse files
committed
Add tests for delete custom fieldsets endpoint
1 parent 2047cfe commit 3105f53

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

database/factories/UserFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ public function deleteCustomFields()
326326
return $this->appendPermission(['customfields.delete' => '1']);
327327
}
328328

329+
public function deleteCustomFieldsets()
330+
{
331+
return $this->appendPermission(['customfields.delete' => '1']);
332+
}
333+
329334
private function appendPermission(array $permission)
330335
{
331336
return $this->state(function ($currentState) use ($permission) {

tests/Feature/CustomFields/Api/DeleteCustomFieldsTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequire
1212
{
1313
public function testRequiresPermission()
1414
{
15+
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
16+
1517
$customField = CustomField::factory()->create();
1618

1719
$this->actingAsForApi(User::factory()->create())
@@ -21,6 +23,8 @@ public function testRequiresPermission()
2123

2224
public function testCustomFieldsCanBeDeleted()
2325
{
26+
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
27+
2428
$customField = CustomField::factory()->create();
2529

2630
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Tests\Feature\CustomFieldsets\Api;
4+
5+
use App\Models\CustomField;
6+
use App\Models\CustomFieldset;
7+
use App\Models\User;
8+
use Tests\Concerns\TestsPermissionsRequirement;
9+
use Tests\TestCase;
10+
11+
class DeleteCustomFieldsetsTest extends TestCase implements TestsPermissionsRequirement
12+
{
13+
public function testRequiresPermission()
14+
{
15+
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
16+
17+
$customFieldset = CustomFieldset::factory()->create();
18+
19+
$this->actingAsForApi(User::factory()->create())
20+
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
21+
->assertForbidden();
22+
}
23+
24+
public function testCanDeleteCustomFieldsets()
25+
{
26+
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
27+
28+
$customFieldset = CustomFieldset::factory()->create();
29+
30+
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
31+
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
32+
->assertStatusMessageIs('success');
33+
34+
$this->assertDatabaseMissing('custom_fieldsets', ['id' => $customFieldset->id]);
35+
}
36+
37+
public function testCannotDeleteCustomFieldsetWithAssociatedFields()
38+
{
39+
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
40+
41+
$customField = CustomField::factory()->create();
42+
$customFieldset = CustomFieldset::factory()->create();
43+
44+
$customField->fieldset()->attach($customFieldset, ['order' => 1, 'required' => 'false']);
45+
46+
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
47+
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
48+
->assertStatusMessageIs('error');
49+
50+
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
51+
}
52+
53+
public function testCannotDeleteCustomFieldsetWithAssociatedModels()
54+
{
55+
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
56+
57+
$customFieldset = CustomFieldset::factory()->hasModels()->create();
58+
59+
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
60+
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
61+
->assertStatusMessageIs('error');
62+
63+
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
64+
}
65+
}

0 commit comments

Comments
 (0)