snipe-it/tests/Feature/CustomFields/Api/DeleteCustomFieldsTest.php

55 lines
1.9 KiB
PHP
Raw Normal View History

<?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()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customField = CustomField::factory()->create();
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.customfields.destroy', $customField))
->assertForbidden();
2024-09-16 14:32:38 -07:00
$this->assertDatabaseHas('custom_fields', ['id' => $customField->id]);
}
2024-09-16 14:25:11 -07:00
public function testCustomFieldsCannotBeDeletedIfTheyHaveAssociatedFieldsets()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customField = CustomField::factory()->create();
2024-09-16 14:25:11 -07:00
$customFieldset = CustomFieldset::factory()->create();
$customField->fieldset()->attach($customFieldset, ['order' => 1, 'required' => 'false']);
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
->deleteJson(route('api.customfields.destroy', $customField))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('error');
2024-09-16 14:25:11 -07:00
$this->assertDatabaseHas('custom_fields', ['id' => $customField->id]);
}
2024-09-16 14:25:11 -07:00
public function testCustomFieldsCanBeDeleted()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customField = CustomField::factory()->create();
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
->deleteJson(route('api.customfields.destroy', $customField))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('success');
2024-09-16 14:25:11 -07:00
$this->assertDatabaseMissing('custom_fields', ['id' => $customField->id]);
}
}