mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add failing test
This commit is contained in:
parent
833dace2b4
commit
b59bf3e7dc
|
@ -4,6 +4,8 @@ namespace Tests\Feature\AssetModels\Ui;
|
||||||
|
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
use App\Models\CustomField;
|
||||||
|
use App\Models\CustomFieldset;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
@ -19,7 +21,7 @@ class UpdateAssetModelsTest extends TestCase
|
||||||
->assertStatus(403)
|
->assertStatus(403)
|
||||||
->assertForbidden();
|
->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserCanEditAssetModels()
|
public function testUserCanEditAssetModels()
|
||||||
{
|
{
|
||||||
$category = Category::factory()->forAssets()->create();
|
$category = Category::factory()->forAssets()->create();
|
||||||
|
@ -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.'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue