Add failing test

This commit is contained in:
Marcus Moore 2024-08-21 16:49:29 -07:00
parent 59832126cb
commit 833bcb282f
No known key found for this signature in database

View file

@ -4,6 +4,8 @@ namespace Tests\Feature\AssetModels\Ui;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Tests\TestCase;
@ -62,4 +64,41 @@ class UpdateAssetModelsTest extends TestCase
}
public function test_default_values_remain_unchanged_after_validation_error_occurs()
{
$this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL');
$assetModel = AssetModel::factory()->create();
$customFieldset = CustomFieldset::factory()->create();
[$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create();
$customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]);
$customFieldset->fields()->attach($customFieldTwo, ['order' => 2, 'required' => false]);
$assetModel->fieldset()->associate($customFieldset);
$assetModel->defaultValues()->attach($customFieldOne, ['default_value' => 'first default value']);
$assetModel->defaultValues()->attach($customFieldTwo, ['default_value' => 'second default value']);
$this->actingAs(User::factory()->superuser()->create())
->put(route('models.update', ['model' => $assetModel]), [
// should trigger validation error without name, etc, and NOT remove or change default values
'add_default_values' => '1',
'fieldset_id' => $customFieldset->id,
'default_values' => [
$customFieldOne->id => 'changed value',
$customFieldTwo->id => 'changed value',
],
]);
$this->assertEquals(
2,
$assetModel->fresh()->defaultValues->filter(function (CustomField $field) {
return in_array($field->pivot->default_value, ['first default value', 'second default value']);
})->count(),
'Default field values were changed unexpectedly.'
);
}
}