Implement ticket links and blocker state
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketLink;
|
||||
use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
use Database\Seeders\ProjectSeeder;
|
||||
use Database\Seeders\ProjectTicketMetadataSeeder;
|
||||
use Database\Seeders\TicketLinkSeeder;
|
||||
use Database\Seeders\TicketLinkTypeSeeder;
|
||||
use Database\Seeders\TicketSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TicketLinkTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure the ticket link factory normalizes the stored source and target ticket ids.
|
||||
*/
|
||||
public function test_ticket_link_factory_normalizes_ticket_order(): void
|
||||
{
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$taskType = $project->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||
|
||||
$firstTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$secondTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$ticketLink = TicketLink::factory()->create([
|
||||
'source_ticket_id' => $secondTicket->id,
|
||||
'target_ticket_id' => $firstTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
|
||||
$this->assertSame($firstTicket->id, $ticketLink->source_ticket_id);
|
||||
$this->assertSame($secondTicket->id, $ticketLink->target_ticket_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the ticket link seeder creates dummy links for seeded projects.
|
||||
*/
|
||||
public function test_ticket_link_seeder_creates_dummy_links_for_seeded_projects(): void
|
||||
{
|
||||
$this->seed([
|
||||
ProjectSeeder::class,
|
||||
ProjectTicketMetadataSeeder::class,
|
||||
TicketSeeder::class,
|
||||
TicketLinkTypeSeeder::class,
|
||||
TicketLinkSeeder::class,
|
||||
]);
|
||||
|
||||
$coreProject = Project::query()->where('key', 'CORE')->firstOrFail();
|
||||
$seededTickets = Ticket::query()
|
||||
->where('project_id', $coreProject->id)
|
||||
->orderBy('sequence_number')
|
||||
->get();
|
||||
|
||||
$this->assertDatabaseHas('ticket_links', [
|
||||
'source_ticket_id' => $seededTickets[0]->id,
|
||||
'target_ticket_id' => $seededTickets[1]->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketLinkType;
|
||||
use Database\Seeders\ProjectSeeder;
|
||||
use Database\Seeders\TicketLinkTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TicketLinkTypeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure the ticket link type factory creates project-scoped labels.
|
||||
*/
|
||||
public function test_ticket_link_type_factory_creates_project_scoped_labels(): void
|
||||
{
|
||||
$ticketLinkType = TicketLinkType::factory()->create();
|
||||
|
||||
$this->assertNotNull($ticketLinkType->project_id);
|
||||
$this->assertIsString($ticketLinkType->label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the ticket link type seeder creates default labels for seeded projects.
|
||||
*/
|
||||
public function test_ticket_link_type_seeder_creates_default_labels_for_projects(): void
|
||||
{
|
||||
$this->seed([
|
||||
ProjectSeeder::class,
|
||||
TicketLinkTypeSeeder::class,
|
||||
]);
|
||||
|
||||
$coreProject = Project::query()->where('key', 'CORE')->firstOrFail();
|
||||
|
||||
$this->assertDatabaseHas('ticket_link_types', [
|
||||
'project_id' => $coreProject->id,
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_link_types', [
|
||||
'project_id' => $coreProject->id,
|
||||
'label' => 'Blocks',
|
||||
'position' => 2,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,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 Database\Seeders\BoardColumnSeeder;
|
||||
@@ -165,4 +167,72 @@ class TicketTest extends TestCase
|
||||
$this->assertSame($parentTicket->id, $childTicket->fresh()->parentTicket?->id);
|
||||
$this->assertSame([$childTicket->id], $parentTicket->fresh()->childTickets->modelKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the blocked flag is cast to a boolean for board and detail rendering.
|
||||
*/
|
||||
public function test_ticket_blocked_state_is_cast_to_boolean(): void
|
||||
{
|
||||
$ticket = Ticket::factory()->create([
|
||||
'blocked_comment' => 'Waiting for environment access.',
|
||||
'is_blocked' => 1,
|
||||
]);
|
||||
|
||||
$freshTicket = $ticket->fresh();
|
||||
|
||||
$this->assertTrue($freshTicket->is_blocked);
|
||||
$this->assertSame('Waiting for environment access.', $freshTicket->blocked_comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure tickets expose incoming and outgoing link relations.
|
||||
*/
|
||||
public function test_ticket_link_relations_are_available(): void
|
||||
{
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$taskType = $project->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||
|
||||
$sourceTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$targetTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$ticketLink = TicketLink::factory()->create([
|
||||
'source_ticket_id' => $sourceTicket->id,
|
||||
'target_ticket_id' => $targetTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
[$ticketLink->id],
|
||||
$sourceTicket->fresh()->ticketLinksAsSource->modelKeys(),
|
||||
);
|
||||
$this->assertSame(
|
||||
[$ticketLink->id],
|
||||
$targetTicket->fresh()->ticketLinksAsTarget->modelKeys(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\ProjectPermissions\ProjectPermissionService;
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketLink;
|
||||
use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectTicketLinkControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure users with edit permission can link tickets and create a worklog entry.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_link_tickets(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$taskType = $project->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'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' => $taskType->id,
|
||||
]);
|
||||
$linkedTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.tickets.links.store', [$project, $ticket]), [
|
||||
'linked_ticket_id' => $linkedTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHas('status', 'Relates to link was saved.');
|
||||
|
||||
$this->assertDatabaseHas('ticket_links', [
|
||||
'source_ticket_id' => min($ticket->id, $linkedTicket->id),
|
||||
'target_ticket_id' => max($ticket->id, $linkedTicket->id),
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
'ticket_id' => $ticket->id,
|
||||
'actor_id' => $user->id,
|
||||
'entry_type' => 'link_updated',
|
||||
'summary' => 'Linked CORE-2 as Relates to.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure ticket links cannot target the current ticket or a ticket from another project.
|
||||
*/
|
||||
public function test_ticket_links_must_target_other_tickets_within_the_same_project(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
$otherProject = Project::factory()->create();
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
app(InitializeProjectTicketMetadata::class)->handle($otherProject);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$otherPriority = TicketPriority::factory()->for($otherProject)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$taskType = $project->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||
$otherTaskType = $otherProject->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'APP-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$foreignTicket = Ticket::factory()->create([
|
||||
'project_id' => $otherProject->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'OPS-1',
|
||||
'ticket_priority_id' => $otherPriority->id,
|
||||
'ticket_type_id' => $otherTaskType->id,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.tickets.show', [$project, $ticket]))
|
||||
->post(route('projects.tickets.links.store', [$project, $ticket]), [
|
||||
'linked_ticket_id' => $ticket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHasErrors('linked_ticket_id');
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.tickets.show', [$project, $ticket]))
|
||||
->post(route('projects.tickets.links.store', [$project, $ticket]), [
|
||||
'linked_ticket_id' => $foreignTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHasErrors('linked_ticket_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure users with edit permission can remove ticket links.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_remove_ticket_links(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
$taskType = $project->ticketTypes()->where('system_key', 'task')->firstOrFail();
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'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' => $taskType->id,
|
||||
]);
|
||||
$linkedTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$ticketLink = TicketLink::factory()->create([
|
||||
'source_ticket_id' => min($ticket->id, $linkedTicket->id),
|
||||
'target_ticket_id' => max($ticket->id, $linkedTicket->id),
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('projects.tickets.links.destroy', [$project, $ticket, $ticketLink]))
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHas('status', 'Relates to link was removed.');
|
||||
|
||||
$this->assertDatabaseMissing('ticket_links', [
|
||||
'id' => $ticketLink->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
'ticket_id' => $ticket->id,
|
||||
'actor_id' => $user->id,
|
||||
'entry_type' => 'link_removed',
|
||||
'summary' => 'Removed Relates to link to CORE-2.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Projects;
|
||||
use App\Actions\ProjectPermissions\ProjectPermissionService;
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\TicketType;
|
||||
use App\Models\User;
|
||||
@@ -27,6 +28,10 @@ class ProjectTicketMetadataSettingsControllerTest extends TestCase
|
||||
'name' => 'Bug',
|
||||
'position' => 3,
|
||||
]);
|
||||
TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit']);
|
||||
|
||||
@@ -37,7 +42,8 @@ class ProjectTicketMetadataSettingsControllerTest extends TestCase
|
||||
->component('projects/settings/Metadata')
|
||||
->where('ticketTypes.0.name', 'Task')
|
||||
->where('ticketTypes.1.name', 'Parent')
|
||||
->where('ticketTypes.2.name', 'Bug'),
|
||||
->where('ticketTypes.2.name', 'Bug')
|
||||
->where('ticketLinkTypes.0.label', 'Relates to'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,4 +214,43 @@ class ProjectTicketMetadataSettingsControllerTest extends TestCase
|
||||
->assertSessionHasErrors('field_type')
|
||||
->assertRedirect(route('projects.settings.metadata', $project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure users with edit permission can manage ticket link types.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_manage_ticket_link_types(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.settings.metadata.link-types.store', $project), [
|
||||
'name' => 'Blocks',
|
||||
])
|
||||
->assertRedirect(route('projects.settings.metadata', $project))
|
||||
->assertSessionHas('status', 'Blocks link type was added.');
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.settings.metadata.link-types.update', [$project, $ticketLinkType]), [
|
||||
'name' => 'Depends on',
|
||||
'position' => 2,
|
||||
])
|
||||
->assertRedirect(route('projects.settings.metadata', $project))
|
||||
->assertSessionHas('status', 'Depends on link type was updated.');
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('projects.settings.metadata.link-types.destroy', [$project, $ticketLinkType]))
|
||||
->assertRedirect(route('projects.settings.metadata', $project))
|
||||
->assertSessionHas('status', 'Depends on link type was removed.');
|
||||
|
||||
$this->assertDatabaseMissing('ticket_link_types', [
|
||||
'id' => $ticketLinkType->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user