mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-12 16:44:08 -08:00
Add tests for delete custom fields endpoint
This commit is contained in:
parent
e3268d32df
commit
2047cfed09
|
@ -321,6 +321,11 @@ class UserFactory extends Factory
|
||||||
return $this->appendPermission(['import' => '1']);
|
return $this->appendPermission(['import' => '1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteCustomFields()
|
||||||
|
{
|
||||||
|
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) {
|
||||||
|
|
48
tests/Feature/CustomFields/Api/DeleteCustomFieldsTest.php
Normal file
48
tests/Feature/CustomFields/Api/DeleteCustomFieldsTest.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\CustomFields\Api;
|
||||||
|
|
||||||
|
use App\Models\CustomField;
|
||||||
|
use App\Models\CustomFieldset;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\Concerns\TestsPermissionsRequirement;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequirement
|
||||||
|
{
|
||||||
|
public function testRequiresPermission()
|
||||||
|
{
|
||||||
|
$customField = CustomField::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->deleteJson(route('api.customfields.destroy', $customField))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomFieldsCanBeDeleted()
|
||||||
|
{
|
||||||
|
$customField = CustomField::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
|
||||||
|
->deleteJson(route('api.customfields.destroy', $customField))
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('custom_fields', ['id' => $customField->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomFieldsCannotBeDeletedIfTheyHaveAssociatedFieldsets()
|
||||||
|
{
|
||||||
|
$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()->deleteCustomFields()->create())
|
||||||
|
->deleteJson(route('api.customfields.destroy', $customField))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('custom_fields', ['id' => $customField->id]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue