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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user