From 3a0a13d06d377bc86695006885730f57cb641bc2 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Mar 2024 16:35:06 -0600 Subject: [PATCH] tests written but something not working... --- tests/Feature/Api/Assets/AssetStoreTest.php | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php index 92a58a500..f7a0aaf6d 100644 --- a/tests/Feature/Api/Assets/AssetStoreTest.php +++ b/tests/Feature/Api/Assets/AssetStoreTest.php @@ -438,4 +438,70 @@ class AssetStoreTest extends TestCase $json->has('messages.company_id')->etc(); }); } + + public function testCustomFieldCheckboxPassesValidationForValidOptionsWithString() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => 'One, Two, Three', + ]) + ->assertOk() + ->assertStatusMessageIs('success'); + } + + public function testCustomFieldCheckboxPassesValidationForValidOptionsWithArray() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => ['One', 'Two', 'Three'], + ]) + ->assertOk() + ->assertStatusMessageIs('success'); + } + + public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithString() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => "One, Two, Four, Five", + ]) + ->assertStatusMessageIs('error'); + } + + public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithArray() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => ['One', 'Two', 'Four', 'Five'] + ]) + ->assertStatusMessageIs('error'); + } }