Add more tests for Asset Model index and store methods

This commit is contained in:
Marcus Moore 2024-06-17 14:51:59 -07:00
parent 08bd39dbba
commit 672aabf4ac
No known key found for this signature in database
3 changed files with 58 additions and 38 deletions

View file

@ -0,0 +1,23 @@
<?php
namespace Tests\Feature\AssetModels\Ui;
use App\Models\User;
use Tests\TestCase;
class AssetModelIndexTest extends TestCase
{
public function testPermissionRequiredToViewAssetModelList()
{
$this->actingAs(User::factory()->create())
->get(route('models.index'))
->assertForbidden();
}
public function testUserCanListAssetModels()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('models.index'))
->assertOk();
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Tests\Feature\AssetModels\Ui;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\User;
use Tests\TestCase;
class AssetModelStoreTest extends TestCase
{
public function testPermissionRequiredToStoreAssetModel()
{
$this->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());
}
}

View file

@ -1,38 +0,0 @@
<?php
namespace Tests\Feature\AssetModels\Ui;
use App\Models\Category;
use App\Models\AssetModel;
use App\Models\Company;
use App\Models\CustomField;
use App\Models\Statuslabel;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Tests\TestCase;
class AssetModelsTest extends TestCase
{
public function testUserCanListAssetModels()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('models.index'))
->assertStatus(200);
}
public function testUserCanCreateAssetModels()
{
$this->actingAs(User::factory()->superuser()->create())
->post(route('models.index'), [
'name' => 'Test Model',
'category_id' => Category::factory()->create()->id
])
->assertStatus(302)
->assertRedirect(route('models.index'));
}
}