mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add tests for delete custom fieldsets endpoint
This commit is contained in:
parent
2047cfed09
commit
3105f53aff
|
@ -326,6 +326,11 @@ class UserFactory extends Factory
|
||||||
return $this->appendPermission(['customfields.delete' => '1']);
|
return $this->appendPermission(['customfields.delete' => '1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteCustomFieldsets()
|
||||||
|
{
|
||||||
|
return $this->appendPermission(['customfields.delete' => '1']);
|
||||||
|
}
|
||||||
|
|
||||||
private function appendPermission(array $permission)
|
private function appendPermission(array $permission)
|
||||||
{
|
{
|
||||||
return $this->state(function ($currentState) use ($permission) {
|
return $this->state(function ($currentState) use ($permission) {
|
||||||
|
|
|
@ -12,6 +12,8 @@ class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequire
|
||||||
{
|
{
|
||||||
public function testRequiresPermission()
|
public function testRequiresPermission()
|
||||||
{
|
{
|
||||||
|
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
|
||||||
|
|
||||||
$customField = CustomField::factory()->create();
|
$customField = CustomField::factory()->create();
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->create())
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
@ -21,6 +23,8 @@ class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequire
|
||||||
|
|
||||||
public function testCustomFieldsCanBeDeleted()
|
public function testCustomFieldsCanBeDeleted()
|
||||||
{
|
{
|
||||||
|
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
|
||||||
|
|
||||||
$customField = CustomField::factory()->create();
|
$customField = CustomField::factory()->create();
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
|
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
|
||||||
|
|
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue