-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for delete custom fields endpoint
- Loading branch information
1 parent
e3268d3
commit 2047cfe
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); | ||
} | ||
} |