Files
snipe-it/tests/Feature/Departments/Ui/CreateDepartmentsTest.php
2026-03-16 17:40:57 -07:00

44 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Departments\Ui;
use App\Models\Company;
use App\Models\Department;
use App\Models\User;
use Tests\TestCase;
class CreateDepartmentsTest extends TestCase
{
public function test_page_renders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('departments.create'))
->assertOk();
}
public function test_permission_required_to_create_department()
{
$this->actingAs(User::factory()->create())
->post(route('departments.store'), [
'name' => 'Test Department',
'company_id' => Company::factory()->create()->id,
])
->assertForbidden();
}
public function test_user_can_create_departments()
{
$this->assertFalse(Department::where('name', 'Test Department')->exists());
$this->actingAs(User::factory()->superuser()->create())
->post(route('departments.store'), [
'name' => 'Test Department',
'company_id' => Company::factory()->create()->id,
'notes' => 'Test Note',
])
->assertRedirect(route('departments.index'));
$this->assertTrue(Department::where('name', 'Test Department')->where('notes', 'Test Note')->exists());
}
}