feat: support both ticket link directions (KAN-12)
This commit is contained in:
@@ -83,6 +83,74 @@ class ProjectTicketLinkControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_counterpart_label_can_be_selected_from_the_current_ticket(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create(['key' => 'CORE']);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = $project->ticketPriorities()->firstOrFail();
|
||||
$taskType = $project->ticketTypes()->where('is_parent', false)->firstOrFail();
|
||||
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
||||
'label' => 'Blocks',
|
||||
'counterpart_label' => 'Blocked by',
|
||||
]);
|
||||
$blockingTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
$blockedTicket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 2,
|
||||
'ticket_key' => 'CORE-2',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $taskType->id,
|
||||
]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit', 'view']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.tickets.links.store', [$project, $blockedTicket]), [
|
||||
'linked_ticket_id' => $blockingTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
'link_direction' => 'counterpart',
|
||||
])
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $blockedTicket]))
|
||||
->assertSessionHas('status', 'Blocked by link was saved.');
|
||||
|
||||
$this->assertDatabaseHas('ticket_links', [
|
||||
'source_ticket_id' => $blockingTicket->id,
|
||||
'target_ticket_id' => $blockedTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
'ticket_id' => $blockedTicket->id,
|
||||
'summary' => 'Linked CORE-1 as Blocked by.',
|
||||
]);
|
||||
$this->assertDatabaseHas('ticket_worklog_entries', [
|
||||
'ticket_id' => $blockingTicket->id,
|
||||
'summary' => 'Linked CORE-2 as Blocks.',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.tickets.links.store', [$project, $blockedTicket]), [
|
||||
'linked_ticket_id' => $blockingTicket->id,
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
'link_direction' => 'source',
|
||||
])
|
||||
->assertSessionHas('status', 'Blocks link was saved.');
|
||||
|
||||
$this->assertSame(1, TicketLink::query()->count());
|
||||
$this->assertDatabaseHas('ticket_links', [
|
||||
'source_ticket_id' => $blockedTicket->id,
|
||||
'target_ticket_id' => $blockingTicket->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure ticket links cannot target the current ticket or a ticket from another project.
|
||||
*/
|
||||
@@ -144,6 +212,15 @@ class ProjectTicketLinkControllerTest extends TestCase
|
||||
])
|
||||
->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,
|
||||
'link_direction' => 'sideways',
|
||||
])
|
||||
->assertSessionHasErrors('link_direction');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user