43 lines
1.6 KiB
PHP
43 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Helpdesk\Tests\Feature;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Modules\Helpdesk\Services\AgentAssignmentService;
|
|
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
|
|
use Tests\TestCase;
|
|
|
|
final class AgentAssignmentTest extends TestCase
|
|
{
|
|
use BuildsHelpdeskFixtures;
|
|
use RefreshDatabase;
|
|
|
|
public function test_assignment_selects_least_loaded_agent(): void
|
|
{
|
|
$fixtures = $this->seedLookupData();
|
|
$busy = $this->agent(['name' => 'Busy Agent']);
|
|
$quiet = $this->agent(['name' => 'Quiet Agent']);
|
|
$this->ticket(['agent' => $busy, 'status_id' => $fixtures['open']->id, 'priority_id' => $fixtures['normal']->id]);
|
|
$this->ticket(['agent' => $busy, 'status_id' => $fixtures['open']->id, 'priority_id' => $fixtures['normal']->id]);
|
|
|
|
$selected = app(AgentAssignmentService::class)->selectAgentId(null);
|
|
|
|
self::assertSame($quiet->id, $selected);
|
|
}
|
|
|
|
public function test_assignment_prefers_category_agents_when_category_has_agents(): void
|
|
{
|
|
$fixtures = $this->seedLookupData();
|
|
$generalAgent = $this->agent(['name' => 'General Agent']);
|
|
$categoryAgent = $this->agent(['name' => 'Category Agent']);
|
|
$fixtures['category']->agents()->attach($categoryAgent->id);
|
|
$this->ticket(['agent' => $generalAgent, 'status_id' => $fixtures['open']->id, 'priority_id' => $fixtures['normal']->id]);
|
|
|
|
$selected = app(AgentAssignmentService::class)->selectAgentId($fixtures['category']->id);
|
|
|
|
self::assertSame($categoryAgent->id, $selected);
|
|
}
|
|
}
|