create(); Faculty::factory()->create(); $this->department = Department::factory()->create(); $this->data = Department::factory()->make()->only([ 'position', 'name', 'description', 'slug', 'faculty_id', ]); $this->user = User::factory()->create([ 'name' => 'admin', 'email' => 'test@example.com', 'password' => 123456 ]); } public function testIndexDepartmentsPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('departments.index')); $response->assertOk(); } public function testCreateDepartmentPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('departments.create')); $response->assertOk(); } public function testStoreDepartment(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->post(route('departments.store', $this->data)); $response->assertRedirect(route('departments.index')); $this->assertDatabaseHas('departments', $this->data); } public function testShowDepartmentPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('departments.show', $this->department)); $response->assertOk(); } public function testEditDepartmentPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('departments.edit', $this->department)); $response->assertOk(); } public function testUpdateDepartment(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->patch(route('departments.update', $this->department), $this->data); $response->assertRedirect(route('departments.index')); $this->assertDatabaseHas('departments', $this->data); } public function testDestroyDepartment(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->delete(route('departments.destroy', $this->department)); $response->assertRedirect(route('departments.index')); $this->assertDatabaseMissing('departments', $this->department->toArray()); } }