diff --git a/tests/Feature/AssetModels/Ui/AssetModelStoreTest.php b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php similarity index 89% rename from tests/Feature/AssetModels/Ui/AssetModelStoreTest.php rename to tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php index 81b07237c0..86710dab12 100644 --- a/tests/Feature/AssetModels/Ui/AssetModelStoreTest.php +++ b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php @@ -7,9 +7,9 @@ use App\Models\Category; use App\Models\User; use Tests\TestCase; -class AssetModelStoreTest extends TestCase +class CreateAssetModelsTest extends TestCase { - public function testPermissionRequiredToStoreAssetModel() + public function testPermissionRequiredToCreateAssetModel() { $this->actingAs(User::factory()->create()) ->post(route('models.store'), [ @@ -32,4 +32,5 @@ class AssetModelStoreTest extends TestCase $this->assertTrue(AssetModel::where('name', 'Test Model')->exists()); } + } diff --git a/tests/Feature/AssetModels/Ui/AssetModelIndexTest.php b/tests/Feature/AssetModels/Ui/IndexAssetModelsTest.php similarity index 91% rename from tests/Feature/AssetModels/Ui/AssetModelIndexTest.php rename to tests/Feature/AssetModels/Ui/IndexAssetModelsTest.php index a73d425723..495de30f0a 100644 --- a/tests/Feature/AssetModels/Ui/AssetModelIndexTest.php +++ b/tests/Feature/AssetModels/Ui/IndexAssetModelsTest.php @@ -5,7 +5,7 @@ namespace Tests\Feature\AssetModels\Ui; use App\Models\User; use Tests\TestCase; -class AssetModelIndexTest extends TestCase +class IndexAssetModelsTest extends TestCase { public function testPermissionRequiredToViewAssetModelList() { diff --git a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php new file mode 100644 index 0000000000..e03e6c5762 --- /dev/null +++ b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php @@ -0,0 +1,73 @@ +actingAs(User::factory()->create()) + ->post(route('models.store'), [ + 'name' => 'Test Model', + 'category_id' => Category::factory()->create()->id + ]) + ->assertForbidden(); + } + + public function testUserCanCreateAssetModels() + { + $this->assertFalse(AssetModel::where('name', 'Test Model')->exists()); + + $this->actingAs(User::factory()->superuser()->create()) + ->post(route('models.store'), [ + 'name' => 'Test Model', + 'category_id' => Category::factory()->create()->id + ]) + ->assertRedirect(route('models.index')); + + $this->assertTrue(AssetModel::where('name', 'Test Model')->exists()); + } + + public function testUserCanEditAssetModels() + { + $model = AssetModel::factory()->create(['name' => 'Test Model', 'category_id' => Category::factory()->create()->id]); + $this->assertTrue(AssetModel::where('name', 'Test Model')->exists()); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->put(route('models.update', ['model' => $model]), [ + 'name' => 'Test Model Edited', + 'category_id' => $model->category_id, + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors() + ->assertRedirect(route('models.index')); + + $this->followRedirects($response)->assertSee('Success'); + $this->assertTrue(AssetModel::where('name', 'Test Model Edited')->exists()); + + } + + public function testUserCannotChangeAssetModelCategoryType() + { + $model = AssetModel::factory()->create(['name' => 'Test Model', 'category_id' => Category::factory()->forAssets()->create()->id]); + $this->assertTrue(AssetModel::where('name', 'Test Model')->exists()); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->put(route('models.update', ['model' => $model]), [ + 'name' => 'Test Model Edited', + 'category_id' => Category::factory()->forAccessories()->create()->id, + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors() + ->assertRedirect(route('models.index')); + + $this->followRedirects($response)->assertSee(trans('general.error')); + $this->assertFalse(AssetModel::where('name', 'Test Model Edited')->exists()); + + } +}