From b0063b1d4a0af2f78c3b7c4334256a89cfa661b0 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 31 Jul 2024 11:57:35 -0500 Subject: [PATCH] test written --- tests/Feature/Assets/Api/UpdateAssetTest.php | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Assets/Api/UpdateAssetTest.php b/tests/Feature/Assets/Api/UpdateAssetTest.php index 2a57d38391..499ea61f28 100644 --- a/tests/Feature/Assets/Api/UpdateAssetTest.php +++ b/tests/Feature/Assets/Api/UpdateAssetTest.php @@ -269,8 +269,6 @@ class UpdateAssetTest extends TestCase { $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); - // hmm, for some reason this customfield isn't attached to a fieldset - // need to check out these factory methods... $field = CustomField::factory()->testEncrypted()->create(); $asset = Asset::factory()->hasEncryptedCustomField($field)->create(); $superuser = User::factory()->superuser()->create(); @@ -456,4 +454,27 @@ class UpdateAssetTest extends TestCase ]) ->assertStatusMessageIs('success'); } + + public function testCustomFieldCannotBeUpdatedIfNotOnCurrentAssetModel() + { + $customField = CustomField::factory()->create(); + $customField2 = CustomField::factory()->create(); + $asset = Asset::factory()->hasMultipleCustomFields([$customField])->create(); + $user = User::factory()->editAssets()->create(); + + // successful + $this->actingAsForApi($user)->patchJson(route('api.assets.update', $asset->id), [ + $customField->db_column_name() => 'test attribute', + ])->assertStatusMessageIs('success'); + + // custom field exists, but not on this asset model + $this->actingAsForApi($user)->patchJson(route('api.assets.update', $asset->id), [ + $customField2->db_column_name() => 'test attribute', + ])->assertStatusMessageIs('error'); + + // custom field does not exist + $this->actingAsForApi($user)->patchJson(route('api.assets.update', $asset->id), [ + '_snipeit_non_existent_custom_field_50' => 'test attribute', + ])->assertStatusMessageIs('error'); + } }