Implement ticket links and blocker state
This commit is contained in:
@@ -8,6 +8,8 @@ use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketFieldValue;
|
||||
use App\Models\TicketLink;
|
||||
use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\TicketWorklogEntry;
|
||||
use App\Models\User;
|
||||
@@ -40,6 +42,10 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'label' => 'Story Points',
|
||||
'position' => 1,
|
||||
]);
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
@@ -49,6 +55,14 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Ticket detail test',
|
||||
]);
|
||||
$linkedTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Linked ticket',
|
||||
]);
|
||||
|
||||
TicketFieldValue::factory()->create([
|
||||
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||
@@ -56,6 +70,11 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'value_number' => 5,
|
||||
'value_user_id' => null,
|
||||
]);
|
||||
TicketLink::factory()->create([
|
||||
'source_ticket_id' => $ticket->id,
|
||||
'target_ticket_id' => $linkedTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
|
||||
TicketWorklogEntry::factory()->create([
|
||||
'actor_id' => $viewer->id,
|
||||
@@ -76,6 +95,8 @@ class ProjectTicketControllerTest extends TestCase
|
||||
->where('ticket.field_values.0.ticket_field_definition.label', 'Story Points')
|
||||
->where('ticket.field_values.0.value_number', 5)
|
||||
->where('ticket.worklog_entries.0.actor.name', $viewer->name)
|
||||
->where('linkedTickets.0.linked_ticket.ticket_key', 'CORE-2')
|
||||
->where('linkedTickets.0.ticket_link_type.label', 'Relates to')
|
||||
->where('canEditTicket', false),
|
||||
);
|
||||
}
|
||||
@@ -108,6 +129,9 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'title' => 'Updated title',
|
||||
'description' => 'Updated description',
|
||||
'acceptance_criteria' => 'Updated criteria',
|
||||
'blocked_comment' => $ticket->blocked_comment,
|
||||
'is_blocked' => $ticket->is_blocked,
|
||||
'parent_ticket_id' => $ticket->parent_ticket_id,
|
||||
'ticket_type_id' => $ticket->ticket_type_id,
|
||||
'ticket_priority_id' => $ticket->ticket_priority_id,
|
||||
'field_values' => [],
|
||||
@@ -186,6 +210,9 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'title' => 'Updated title',
|
||||
'description' => 'Updated description',
|
||||
'acceptance_criteria' => 'Updated acceptance criteria',
|
||||
'blocked_comment' => $ticket->blocked_comment,
|
||||
'is_blocked' => $ticket->is_blocked,
|
||||
'parent_ticket_id' => $ticket->parent_ticket_id,
|
||||
'ticket_type_id' => $parentType->id,
|
||||
'ticket_priority_id' => $highPriority->id,
|
||||
'field_values' => [
|
||||
@@ -276,6 +303,8 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'title' => $childTicket->title,
|
||||
'description' => $childTicket->description,
|
||||
'acceptance_criteria' => $childTicket->acceptance_criteria,
|
||||
'blocked_comment' => $childTicket->blocked_comment,
|
||||
'is_blocked' => $childTicket->is_blocked,
|
||||
'parent_ticket_id' => $candidateParent->id,
|
||||
'ticket_type_id' => $childTicket->ticket_type_id,
|
||||
'ticket_priority_id' => $childTicket->ticket_priority_id,
|
||||
@@ -330,6 +359,8 @@ class ProjectTicketControllerTest extends TestCase
|
||||
'title' => $childTicket->title,
|
||||
'description' => $childTicket->description,
|
||||
'acceptance_criteria' => $childTicket->acceptance_criteria,
|
||||
'blocked_comment' => $childTicket->blocked_comment,
|
||||
'is_blocked' => $childTicket->is_blocked,
|
||||
'parent_ticket_id' => $parentTicket->id,
|
||||
'ticket_type_id' => $childTicket->ticket_type_id,
|
||||
'ticket_priority_id' => $childTicket->ticket_priority_id,
|
||||
@@ -422,4 +453,134 @@ class ProjectTicketControllerTest extends TestCase
|
||||
->where('childTicketTree.1.ticket_key', $directTask->ticket_key),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure blocked tickets require a blocker comment.
|
||||
*/
|
||||
public function test_blocked_tickets_require_a_blocker_comment_when_updating(): void
|
||||
{
|
||||
$editor = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $editor, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($editor)
|
||||
->from(route('projects.tickets.show', [$project, $ticket]))
|
||||
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
||||
'title' => $ticket->title,
|
||||
'description' => $ticket->description,
|
||||
'acceptance_criteria' => $ticket->acceptance_criteria,
|
||||
'ticket_type_id' => $ticket->ticket_type_id,
|
||||
'ticket_priority_id' => $ticket->ticket_priority_id,
|
||||
'parent_ticket_id' => $ticket->parent_ticket_id,
|
||||
'is_blocked' => true,
|
||||
'blocked_comment' => '',
|
||||
'field_values' => [],
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHasErrors('blocked_comment');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'is_blocked' => false,
|
||||
'blocked_comment' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure blocking and unblocking a ticket persists the state and logs both changes.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_block_and_unblock_tickets(): void
|
||||
{
|
||||
$editor = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $editor, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($editor)
|
||||
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
||||
'title' => $ticket->title,
|
||||
'description' => $ticket->description,
|
||||
'acceptance_criteria' => $ticket->acceptance_criteria,
|
||||
'ticket_type_id' => $ticket->ticket_type_id,
|
||||
'ticket_priority_id' => $ticket->ticket_priority_id,
|
||||
'parent_ticket_id' => $ticket->parent_ticket_id,
|
||||
'is_blocked' => true,
|
||||
'blocked_comment' => 'Waiting for dependency approval.',
|
||||
'field_values' => [],
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHas('status', 'CORE-1 was updated.');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'is_blocked' => true,
|
||||
'blocked_comment' => 'Waiting for dependency approval.',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
'ticket_id' => $ticket->id,
|
||||
'actor_id' => $editor->id,
|
||||
'entry_type' => 'updated',
|
||||
'summary' => 'Updated blocker comment and blocked state.',
|
||||
]);
|
||||
|
||||
$this->actingAs($editor)
|
||||
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
||||
'title' => $ticket->title,
|
||||
'description' => $ticket->description,
|
||||
'acceptance_criteria' => $ticket->acceptance_criteria,
|
||||
'ticket_type_id' => $ticket->ticket_type_id,
|
||||
'ticket_priority_id' => $ticket->ticket_priority_id,
|
||||
'parent_ticket_id' => $ticket->parent_ticket_id,
|
||||
'is_blocked' => false,
|
||||
'blocked_comment' => '',
|
||||
'field_values' => [],
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHas('status', 'CORE-1 was updated.');
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'is_blocked' => false,
|
||||
'blocked_comment' => null,
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
2,
|
||||
TicketWorklogEntry::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->where('entry_type', 'updated')
|
||||
->where('summary', 'Updated blocker comment and blocked state.')
|
||||
->count(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user