Implement ticket statuses
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -36,6 +37,9 @@ class ProjectBoardControllerTest extends TestCase
|
||||
'name' => 'Doing',
|
||||
'position' => 2,
|
||||
]);
|
||||
$this->createColumnStatus($todoColumn);
|
||||
$doingStatus = $this->createColumnStatus($doingColumn);
|
||||
$backlogStatus = $this->backlogStatus($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'High',
|
||||
@@ -43,21 +47,21 @@ class ProjectBoardControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
Ticket::factory()->create([
|
||||
'board_column_id' => null,
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Backlog ticket',
|
||||
]);
|
||||
|
||||
$boardTicket = Ticket::factory()->create([
|
||||
'board_column_id' => $doingColumn->id,
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $doingStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Board ticket',
|
||||
]);
|
||||
@@ -96,6 +100,8 @@ class ProjectBoardControllerTest extends TestCase
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$todoStatus = $this->createColumnStatus($todoColumn);
|
||||
$backlogStatus = $this->backlogStatus($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'High',
|
||||
@@ -103,11 +109,11 @@ class ProjectBoardControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'board_column_id' => null,
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Backlog ticket',
|
||||
]);
|
||||
@@ -116,15 +122,15 @@ class ProjectBoardControllerTest extends TestCase
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.tickets.status.update', [$project, $ticket]), [
|
||||
'board_column_id' => $todoColumn->id,
|
||||
'redirect_to' => 'backlog',
|
||||
'ticket_status_id' => $todoStatus->id,
|
||||
])
|
||||
->assertRedirect(route('projects.backlog.index', $project))
|
||||
->assertSessionHas('status', 'CORE-1 moved to Todo.');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'board_column_id' => $todoColumn->id,
|
||||
'ticket_status_id' => $todoStatus->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
@@ -155,6 +161,8 @@ class ProjectBoardControllerTest extends TestCase
|
||||
'name' => 'Done',
|
||||
'position' => 2,
|
||||
]);
|
||||
$todoStatus = $this->createColumnStatus($todoColumn);
|
||||
$doneStatus = $this->createColumnStatus($doneColumn);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'High',
|
||||
@@ -162,11 +170,11 @@ class ProjectBoardControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'board_column_id' => $todoColumn->id,
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $todoStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Board ticket',
|
||||
]);
|
||||
@@ -175,15 +183,15 @@ class ProjectBoardControllerTest extends TestCase
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.tickets.status.update', [$project, $ticket]), [
|
||||
'board_column_id' => $doneColumn->id,
|
||||
'redirect_to' => 'board',
|
||||
'ticket_status_id' => $doneStatus->id,
|
||||
])
|
||||
->assertRedirect(route('projects.board.index', $project))
|
||||
->assertSessionHas('status', 'CORE-1 moved to Done.');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'board_column_id' => $doneColumn->id,
|
||||
'ticket_status_id' => $doneStatus->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
@@ -210,6 +218,8 @@ class ProjectBoardControllerTest extends TestCase
|
||||
'name' => 'Doing',
|
||||
'position' => 1,
|
||||
]);
|
||||
$doingStatus = $this->createColumnStatus($doingColumn);
|
||||
$backlogStatus = $this->backlogStatus($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'High',
|
||||
@@ -217,11 +227,11 @@ class ProjectBoardControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'board_column_id' => $doingColumn->id,
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $doingStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Board ticket',
|
||||
]);
|
||||
@@ -230,15 +240,15 @@ class ProjectBoardControllerTest extends TestCase
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.tickets.status.update', [$project, $ticket]), [
|
||||
'board_column_id' => null,
|
||||
'redirect_to' => 'board',
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
])
|
||||
->assertRedirect(route('projects.board.index', $project))
|
||||
->assertSessionHas('status', 'CORE-1 moved to Backlog.');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'board_column_id' => null,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
@@ -266,6 +276,8 @@ class ProjectBoardControllerTest extends TestCase
|
||||
'name' => 'Foreign',
|
||||
'position' => 1,
|
||||
]);
|
||||
$otherProjectStatus = $this->createColumnStatus($otherProjectColumn);
|
||||
$backlogStatus = $this->backlogStatus($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'High',
|
||||
@@ -273,9 +285,9 @@ class ProjectBoardControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'board_column_id' => null,
|
||||
'project_id' => $project->id,
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
]);
|
||||
|
||||
@@ -284,17 +296,89 @@ class ProjectBoardControllerTest extends TestCase
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.backlog.index', $project))
|
||||
->patch(route('projects.tickets.status.update', [$project, $ticket]), [
|
||||
'board_column_id' => $otherProjectColumn->id,
|
||||
'redirect_to' => 'backlog',
|
||||
'ticket_status_id' => $otherProjectStatus->id,
|
||||
])
|
||||
->assertRedirect(route('projects.backlog.index', $project))
|
||||
->assertSessionHasErrors('board_column_id');
|
||||
->assertSessionHasErrors('ticket_status_id');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'board_column_id' => null,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseCount('ticket_worklog_entries', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the status transition relation controls valid ticket moves.
|
||||
*/
|
||||
public function test_status_moves_without_an_allowed_transition_are_rejected(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$todoColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$todoStatus = $this->createColumnStatus($todoColumn);
|
||||
$backlogStatus = $this->backlogStatus($project);
|
||||
$backlogStatus->allowedTargetStatuses()->detach($todoStatus->id);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'High',
|
||||
'position' => 2,
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Backlog ticket',
|
||||
]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.backlog.index', $project))
|
||||
->patch(route('projects.tickets.status.update', [$project, $ticket]), [
|
||||
'redirect_to' => 'backlog',
|
||||
'ticket_status_id' => $todoStatus->id,
|
||||
])
|
||||
->assertRedirect(route('projects.backlog.index', $project))
|
||||
->assertSessionHasErrors('ticket_status_id');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseCount('ticket_worklog_entries', 0);
|
||||
}
|
||||
|
||||
private function backlogStatus(Project $project): TicketStatus
|
||||
{
|
||||
return $project->ticketStatuses()
|
||||
->whereNull('board_column_id')
|
||||
->firstOrFail();
|
||||
}
|
||||
|
||||
private function createColumnStatus(BoardColumn $boardColumn): TicketStatus
|
||||
{
|
||||
return TicketStatus::factory()
|
||||
->for($boardColumn->project)
|
||||
->for($boardColumn)
|
||||
->create([
|
||||
'name' => $boardColumn->name,
|
||||
'position' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user