Add tests for delete custom fieldsets endpoint

This commit is contained in:
Marcus Moore 2024-09-12 16:54:29 -07:00
parent 2047cfed09
commit 3105f53aff
No known key found for this signature in database
3 changed files with 74 additions and 0 deletions

View file

@ -326,6 +326,11 @@ class UserFactory extends Factory
return $this->appendPermission(['customfields.delete' => '1']);
}
public function deleteCustomFieldsets()
{
return $this->appendPermission(['customfields.delete' => '1']);
}
private function appendPermission(array $permission)
{
return $this->state(function ($currentState) use ($permission) {

View file

@ -12,6 +12,8 @@ class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequire
{
public function testRequiresPermission()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customField = CustomField::factory()->create();
$this->actingAsForApi(User::factory()->create())
@ -21,6 +23,8 @@ class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequire
public function testCustomFieldsCanBeDeleted()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customField = CustomField::factory()->create();
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())

View file

@ -0,0 +1,65 @@
<?php
namespace Tests\Feature\CustomFieldsets\Api;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
class DeleteCustomFieldsetsTest extends TestCase implements TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customFieldset = CustomFieldset::factory()->create();
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
->assertForbidden();
}
public function testCanDeleteCustomFieldsets()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customFieldset = CustomFieldset::factory()->create();
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
->assertStatusMessageIs('success');
$this->assertDatabaseMissing('custom_fieldsets', ['id' => $customFieldset->id]);
}
public function testCannotDeleteCustomFieldsetWithAssociatedFields()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customField = CustomField::factory()->create();
$customFieldset = CustomFieldset::factory()->create();
$customField->fieldset()->attach($customFieldset, ['order' => 1, 'required' => 'false']);
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
->assertStatusMessageIs('error');
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
}
public function testCannotDeleteCustomFieldsetWithAssociatedModels()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customFieldset = CustomFieldset::factory()->hasModels()->create();
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
->assertStatusMessageIs('error');
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
}
}