69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Helpdesk\Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Modules\Helpdesk\Models\Ticket;
|
|
use Tests\TestCase;
|
|
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
|
|
|
|
final class TicketTimeLogTest extends TestCase
|
|
{
|
|
use BuildsHelpdeskFixtures;
|
|
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* It stores a time log for an authorized ticket user.
|
|
*/
|
|
public function test_authorized_user_can_log_ticket_time(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$company = $this->createCompany();
|
|
$user = $this->createUserForCompany($company);
|
|
$ticket = $this->createTicketForCompany($company, [
|
|
'created_by_id' => $user->id,
|
|
'assigned_to_id' => $user->id,
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->post(route('helpdesk.tickets.time-logs.store', $ticket), [
|
|
'minutes' => 45,
|
|
'description' => 'Investigated the issue and updated the ticket.',
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->assertDatabaseHas('helpdesk_time_logs', [
|
|
'ticket_id' => $ticket->id,
|
|
'user_id' => $user->id,
|
|
'minutes' => 45,
|
|
'description' => 'Investigated the issue and updated the ticket.',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* It rejects invalid logged minutes.
|
|
*/
|
|
public function test_ticket_time_log_requires_valid_minutes(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$company = $this->createCompany();
|
|
$user = $this->createUserForCompany($company);
|
|
$ticket = $this->createTicketForCompany($company, [
|
|
'created_by_id' => $user->id,
|
|
'assigned_to_id' => $user->id,
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->from(route('helpdesk.tickets.show', $ticket))
|
|
->post(route('helpdesk.tickets.time-logs.store', $ticket), [
|
|
'minutes' => 0,
|
|
])
|
|
->assertRedirect(route('helpdesk.tickets.show', $ticket))
|
|
->assertSessionHasErrors('minutes');
|
|
}
|
|
}
|