1621 lines
63 KiB
PHP
1621 lines
63 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Projects;
|
|
|
|
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
|
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklistMapper;
|
|
use App\Models\AcceptanceCriterion;
|
|
use App\Models\BoardColumn;
|
|
use App\Models\Project;
|
|
use App\Models\RepositoryConnection;
|
|
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\TicketStatus;
|
|
use App\Models\TicketType;
|
|
use App\Models\TicketWorklogEntry;
|
|
use App\Models\User;
|
|
use App\Models\UserGitConnection;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Tests\TestCase;
|
|
|
|
class ProjectTicketControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* Ensure users with view permission can open ticket details and inspect worklog history.
|
|
*/
|
|
public function test_users_with_view_permission_can_view_ticket_details(): void
|
|
{
|
|
$viewer = User::factory()->create();
|
|
$author = User::factory()->create([
|
|
'name' => 'Author User',
|
|
]);
|
|
$assignee = User::factory()->create([
|
|
'name' => 'Assigned User',
|
|
]);
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
'show_author' => false,
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$fieldDefinition = TicketFieldDefinition::factory()->for($project)->create([
|
|
'field_type' => 'number',
|
|
'label' => 'Complexity',
|
|
'position' => 1,
|
|
]);
|
|
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
|
'label' => 'Relates to',
|
|
'counterpart_label' => 'Relates to',
|
|
'position' => 1,
|
|
]);
|
|
|
|
$ticket = Ticket::factory()->create([
|
|
'assignee_user_id' => $assignee->id,
|
|
'author_user_id' => $author->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'story_points' => 5,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Ticket detail test',
|
|
]);
|
|
$rootCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 0,
|
|
'text' => 'User can sign in',
|
|
'is_checked' => false,
|
|
]);
|
|
AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $rootCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'Nested verification',
|
|
'is_checked' => true,
|
|
]);
|
|
$linkedTicket = Ticket::factory()->create([
|
|
'author_user_id' => $author->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 2,
|
|
'ticket_key' => 'CORE-2',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Linked ticket',
|
|
]);
|
|
|
|
TicketFieldValue::factory()->create([
|
|
'ticket_field_definition_id' => $fieldDefinition->id,
|
|
'ticket_id' => $ticket->id,
|
|
'value_number' => 3,
|
|
'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,
|
|
'entry_type' => 'updated',
|
|
'summary' => 'Updated story points.',
|
|
'ticket_id' => $ticket->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->get(route('projects.tickets.show', [$project, $ticket]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('projects/Ticket')
|
|
->where('project.id', $project->id)
|
|
->where('project.show_author', false)
|
|
->where('ticket.ticket_key', 'CORE-1')
|
|
->where('ticket.story_points', 5)
|
|
->where('ticket.acceptance_criteria.0.text', 'User can sign in')
|
|
->where('ticket.acceptance_criteria.0.checked', false)
|
|
->where('ticket.acceptance_criteria.0.indent', 0)
|
|
->where('ticket.acceptance_criteria.1.text', 'Nested verification')
|
|
->where('ticket.acceptance_criteria.1.checked', true)
|
|
->where('ticket.acceptance_criteria.1.indent', 1)
|
|
->where('ticket.assignee.name', 'Assigned User')
|
|
->where('ticket.author', null)
|
|
->where('ticket.author_user_id', null)
|
|
->where('ticket.field_values.0.ticket_field_definition.label', 'Complexity')
|
|
->where('ticket.field_values.0.value_number', 3)
|
|
->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('linkedTickets.0.ticket_link_type.counterpart_label', 'Relates to')
|
|
->where('repositoryBranches', [])
|
|
->where('repositoryPullRequests', [])
|
|
->where('canEditTicket', false)
|
|
->where('canManageProject', false),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure linked tickets show the counterpart label from the other ticket perspective.
|
|
*/
|
|
public function test_ticket_detail_uses_counterpart_link_label_for_target_ticket(): void
|
|
{
|
|
$viewer = 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)
|
|
->orderBy('position')
|
|
->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,
|
|
'title' => 'Source ticket',
|
|
]);
|
|
$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,
|
|
'title' => 'Target ticket',
|
|
]);
|
|
$ticketLinkType = TicketLinkType::factory()->for($project)->create([
|
|
'label' => 'Blocks',
|
|
'counterpart_label' => 'Blocked by',
|
|
'position' => 1,
|
|
]);
|
|
|
|
TicketLink::factory()->create([
|
|
'source_ticket_id' => $sourceTicket->id,
|
|
'target_ticket_id' => $targetTicket->id,
|
|
'ticket_link_type_id' => $ticketLinkType->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->get(route('projects.tickets.show', [$project, $targetTicket]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->where('linkedTickets.0.linked_ticket.ticket_key', 'CORE-1')
|
|
->where('linkedTickets.0.ticket_link_type.label', 'Blocked by')
|
|
->where('linkedTickets.0.ticket_link_type.counterpart_label', 'Blocked by'));
|
|
}
|
|
|
|
/**
|
|
* Ensure project admins can still inspect the author when project author visibility is disabled.
|
|
*/
|
|
public function test_project_admins_can_still_view_hidden_authors(): void
|
|
{
|
|
$admin = User::factory()->create();
|
|
$author = User::factory()->create([
|
|
'name' => 'Author User',
|
|
]);
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
'show_author' => false,
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticket = Ticket::factory()->create([
|
|
'author_user_id' => $author->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'story_points' => 5,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Admin author visibility',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $admin, ['admin', 'view']);
|
|
|
|
$this->actingAs($admin)
|
|
->get(route('projects.tickets.show', [$project, $ticket]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('projects/Ticket')
|
|
->where('ticket.author.name', 'Author User')
|
|
->where('ticket.author_user_id', $author->id)
|
|
->where('canManageProject', true),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure ticket details expose matching branches, pull requests, and inaccessible repository links.
|
|
*/
|
|
public function test_ticket_details_include_matching_branches_pull_requests_and_inaccessible_repository_links(): void
|
|
{
|
|
config()->set('inertia.ssr.enabled', false);
|
|
|
|
Http::preventStrayRequests();
|
|
Http::fake([
|
|
'https://git.example.test/api/v1/repos/core-team/kanbangit/branches*' => Http::response([
|
|
['name' => 'CORE-1-login-form'],
|
|
['name' => 'CORE-1/fix-oauth'],
|
|
['name' => 'CORE-10-should-not-match'],
|
|
['name' => 'main'],
|
|
]),
|
|
'https://git.example.test/api/v1/repos/core-team/kanbangit/pulls*' => Http::response([
|
|
[
|
|
'number' => 42,
|
|
'title' => 'Add login form',
|
|
'state' => 'open',
|
|
'merged' => false,
|
|
'html_url' => 'https://git.example.test/core-team/kanbangit/pulls/42',
|
|
'head' => [
|
|
'ref' => 'CORE-1-login-form',
|
|
],
|
|
],
|
|
[
|
|
'number' => 43,
|
|
'title' => 'Close auth gap',
|
|
'state' => 'closed',
|
|
'merged' => true,
|
|
'html_url' => 'https://git.example.test/core-team/kanbangit/pulls/43',
|
|
'head' => [
|
|
'ref' => 'CORE-1/fix-oauth',
|
|
],
|
|
],
|
|
[
|
|
'number' => 99,
|
|
'title' => 'Other ticket change',
|
|
'state' => 'open',
|
|
'merged' => false,
|
|
'html_url' => 'https://git.example.test/core-team/kanbangit/pulls/99',
|
|
'head' => [
|
|
'ref' => 'CORE-10-should-not-match',
|
|
],
|
|
],
|
|
]),
|
|
]);
|
|
|
|
$viewer = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Branch detail test',
|
|
]);
|
|
|
|
RepositoryConnection::factory()->for($project)->create([
|
|
'base_url' => 'https://git.example.test',
|
|
'owner_name' => 'core-team',
|
|
'provider_repository_id' => '501',
|
|
'repository_full_name' => 'core-team/kanbangit',
|
|
'repository_name' => 'kanbangit',
|
|
'repository_url' => 'https://git.example.test/core-team/kanbangit',
|
|
]);
|
|
RepositoryConnection::factory()->for($project)->create([
|
|
'base_url' => 'https://git.other.test',
|
|
'owner_name' => 'other-team',
|
|
'provider_repository_id' => '902',
|
|
'repository_full_name' => 'other-team/mobile',
|
|
'repository_name' => 'mobile',
|
|
'repository_url' => 'https://git.other.test/other-team/mobile',
|
|
]);
|
|
|
|
UserGitConnection::factory()->for($viewer)->create([
|
|
'base_url' => 'https://git.example.test',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->get(route('projects.tickets.show', [$project, $ticket]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('projects/Ticket')
|
|
->where('suggestedBranchName', 'core-1-branch-detail-test')
|
|
->where('repositoryBranches.0.repository_connection.repository_full_name', 'core-team/kanbangit')
|
|
->has('repositoryBranches.0.branches', 3)
|
|
->where('repositoryBranches.0.branches.0.name', 'CORE-1-login-form')
|
|
->where('repositoryBranches.0.branches.1.name', 'CORE-1/fix-oauth')
|
|
->where('repositoryBranches.0.branches.2.name', 'CORE-10-should-not-match')
|
|
->where('repositoryBranches.1.repository_connection.repository_full_name', 'other-team/mobile')
|
|
->where('repositoryBranches.1.repository_connection.has_personal_access', false)
|
|
->where('repositoryBranches.1.branches', [])
|
|
->has('repositoryPullRequests.0.pull_requests', 3)
|
|
->where('repositoryPullRequests.0.pull_requests.0.number', '42')
|
|
->where('repositoryPullRequests.0.pull_requests.0.title', 'Add login form')
|
|
->where('repositoryPullRequests.0.pull_requests.0.status', 'open')
|
|
->where('repositoryPullRequests.0.pull_requests.1.number', '43')
|
|
->where('repositoryPullRequests.0.pull_requests.1.status', 'merged')
|
|
->where('repositoryPullRequests.0.pull_requests.2.number', '99')
|
|
->where('repositoryPullRequests.0.pull_requests.2.status', 'open')
|
|
->where('repositoryPullRequests.1.repository_connection.repository_full_name', 'other-team/mobile')
|
|
->where('repositoryPullRequests.1.repository_connection.has_personal_access', false)
|
|
->where('repositoryPullRequests.1.pull_requests', []),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure the create page defaults to a board status when opened from the board.
|
|
*/
|
|
public function test_users_with_write_permission_can_view_the_ticket_create_page(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$parentTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Parent ticket',
|
|
]);
|
|
|
|
$boardColumn = BoardColumn::factory()->for($project)->create([
|
|
'name' => 'Todo',
|
|
'position' => 1,
|
|
]);
|
|
$boardStatus = TicketStatus::factory()
|
|
->for($project)
|
|
->for($boardColumn)
|
|
->create([
|
|
'name' => 'Todo',
|
|
'position' => 1,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->get(route('projects.tickets.create', [
|
|
'project' => $project,
|
|
'source' => 'board',
|
|
]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('projects/TicketCreate')
|
|
->where('defaultTicketStatusId', $boardStatus->id)
|
|
->where('parentTicketOptions.0.ticket_key', $parentTicket->ticket_key)
|
|
->where('project.id', $project->id)
|
|
->where('source', 'board')
|
|
->where('ticketStatusOptions.1.id', $boardStatus->id),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure creating tickets from the dedicated endpoint redirects to the ticket detail page.
|
|
*/
|
|
public function test_users_with_write_permission_can_create_tickets(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$assignee = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$backlogStatus = $project->ticketStatuses()
|
|
->whereNull('board_column_id')
|
|
->firstOrFail();
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->post(route('projects.tickets.store', $project), [
|
|
'acceptance_criteria' => [[
|
|
'checked' => false,
|
|
'indent' => 0,
|
|
'text' => 'The ticket exists.',
|
|
]],
|
|
'assignee_user_id' => $assignee->id,
|
|
'description' => 'Created from the dedicated page.',
|
|
'story_points' => 5,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_status_id' => $backlogStatus->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Dedicated create page',
|
|
])
|
|
->assertRedirect(route('projects.tickets.show', [$project, 1]))
|
|
->assertSessionHas('status', 'CORE-1 was created.');
|
|
|
|
$this->assertDatabaseHas('tickets', [
|
|
'assignee_user_id' => $assignee->id,
|
|
'author_user_id' => $editor->id,
|
|
'project_id' => $project->id,
|
|
'story_points' => 5,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_status_id' => $backlogStatus->id,
|
|
'title' => 'Dedicated create page',
|
|
]);
|
|
$this->assertDatabaseHas('ticket_worklog_entries', [
|
|
'actor_id' => $editor->id,
|
|
'entry_type' => 'created',
|
|
'summary' => 'Ticket was created in Backlog.',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure tickets can be created with a parent ticket assignment.
|
|
*/
|
|
public function test_users_with_write_permission_can_create_tickets_with_a_parent_ticket(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$backlogStatus = $project->ticketStatuses()
|
|
->whereNull('board_column_id')
|
|
->firstOrFail();
|
|
$parentTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Parent ticket',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->post(route('projects.tickets.store', $project), [
|
|
'assignee_user_id' => null,
|
|
'description' => 'Created with parent.',
|
|
'parent_ticket_id' => $parentTicket->id,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_status_id' => $backlogStatus->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Child ticket',
|
|
])
|
|
->assertRedirect(route('projects.tickets.show', [$project, 2]))
|
|
->assertSessionHas('status', 'CORE-2 was created.');
|
|
|
|
$this->assertDatabaseHas('tickets', [
|
|
'project_id' => $project->id,
|
|
'ticket_key' => 'CORE-2',
|
|
'parent_ticket_id' => $parentTicket->id,
|
|
'title' => 'Child ticket',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure ticket detail payloads expose the linked parent ticket when assigned.
|
|
*/
|
|
public function test_ticket_detail_pages_include_the_linked_parent_ticket(): void
|
|
{
|
|
$viewer = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$parentTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Parent ticket',
|
|
]);
|
|
$childTicket = Ticket::factory()->create([
|
|
'parent_ticket_id' => $parentTicket->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 2,
|
|
'ticket_key' => 'CORE-2',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Child ticket',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->get(route('projects.tickets.show', [$project, $childTicket]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('projects/Ticket')
|
|
->where('ticket.parent_ticket.ticket_key', $parentTicket->ticket_key)
|
|
->where('ticket.parent_ticket.title', $parentTicket->title)
|
|
->where('childTicketTree', []),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure updating ticket details requires the project edit permission.
|
|
*/
|
|
public function test_updating_ticket_details_requires_edit_permission(): void
|
|
{
|
|
$viewer = User::factory()->create();
|
|
$project = Project::factory()->create();
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'title' => 'Updated title',
|
|
]))
|
|
->assertForbidden();
|
|
}
|
|
|
|
/**
|
|
* Ensure editing ticket details persists fixed ticket fields and custom fields and creates a worklog entry.
|
|
*/
|
|
public function test_users_with_edit_permission_can_update_ticket_details_and_custom_fields(): void
|
|
{
|
|
$editor = User::factory()->create([
|
|
'name' => 'Editor User',
|
|
]);
|
|
$author = User::factory()->create([
|
|
'name' => 'Author User',
|
|
]);
|
|
$assignee = User::factory()->create([
|
|
'name' => 'Assigned User',
|
|
]);
|
|
$reviewer = User::factory()->create([
|
|
'name' => 'Reviewer User',
|
|
]);
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$lowPriority = TicketPriority::factory()->for($project)->create([
|
|
'name' => 'Low',
|
|
'position' => 2,
|
|
]);
|
|
$highPriority = TicketPriority::factory()->for($project)->create([
|
|
'name' => 'High',
|
|
'position' => 3,
|
|
]);
|
|
$reviewerField = TicketFieldDefinition::factory()->for($project)->create([
|
|
'field_type' => 'user',
|
|
'label' => 'Reviewer',
|
|
'position' => 1,
|
|
]);
|
|
$complexityField = TicketFieldDefinition::factory()->for($project)->create([
|
|
'field_type' => 'number',
|
|
'label' => 'Complexity',
|
|
'position' => 2,
|
|
]);
|
|
|
|
$ticket = Ticket::factory()->create([
|
|
'author_user_id' => $author->id,
|
|
'description' => 'Old description',
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'story_points' => 3,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $lowPriority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Old title',
|
|
]);
|
|
TicketFieldValue::factory()->create([
|
|
'ticket_field_definition_id' => $reviewerField->id,
|
|
'ticket_id' => $ticket->id,
|
|
'value_number' => null,
|
|
'value_user_id' => $editor->id,
|
|
]);
|
|
TicketFieldValue::factory()->create([
|
|
'ticket_field_definition_id' => $complexityField->id,
|
|
'ticket_id' => $ticket->id,
|
|
'value_number' => 2,
|
|
'value_user_id' => null,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$updatedAcceptanceCriteria = [
|
|
[
|
|
'text' => 'Shows success banner',
|
|
'checked' => false,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'text' => 'Includes nested confirmations',
|
|
'checked' => false,
|
|
'indent' => 1,
|
|
],
|
|
];
|
|
|
|
$this->actingAs($editor)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
|
'acceptance_criteria' => $updatedAcceptanceCriteria,
|
|
'assignee_user_id' => $assignee->id,
|
|
'blocked_comment' => $ticket->blocked_comment,
|
|
'description' => 'Updated description',
|
|
'field_values' => [
|
|
[
|
|
'ticket_field_definition_id' => $reviewerField->id,
|
|
'value_user_id' => $reviewer->id,
|
|
],
|
|
[
|
|
'ticket_field_definition_id' => $complexityField->id,
|
|
'value_number' => 8,
|
|
],
|
|
],
|
|
'is_blocked' => $ticket->is_blocked,
|
|
'parent_ticket_id' => $ticket->parent_ticket_id,
|
|
'story_points' => 8,
|
|
'ticket_priority_id' => $highPriority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Updated title',
|
|
])
|
|
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
|
->assertSessionHas('status', 'CORE-1 was updated.');
|
|
|
|
$this->assertDatabaseHas('tickets', [
|
|
'id' => $ticket->id,
|
|
'title' => 'Updated title',
|
|
'description' => 'Updated description',
|
|
'assignee_user_id' => $assignee->id,
|
|
'story_points' => 8,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'ticket_priority_id' => $highPriority->id,
|
|
]);
|
|
|
|
$ticket->refresh()->load('acceptanceCriteria');
|
|
|
|
$this->assertEquals(
|
|
$updatedAcceptanceCriteria,
|
|
AcceptanceCriteriaChecklistMapper::fromModels($ticket->acceptanceCriteria),
|
|
);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 0,
|
|
'text' => 'Shows success banner',
|
|
'is_checked' => false,
|
|
]);
|
|
$rootCriterionId = AcceptanceCriterion::query()
|
|
->where('ticket_id', $ticket->id)
|
|
->where('text', 'Shows success banner')
|
|
->value('id');
|
|
$this->assertNotNull($rootCriterionId);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $rootCriterionId,
|
|
'position' => 0,
|
|
'text' => 'Includes nested confirmations',
|
|
'is_checked' => false,
|
|
]);
|
|
$this->assertDatabaseHas('ticket_field_values', [
|
|
'ticket_id' => $ticket->id,
|
|
'ticket_field_definition_id' => $reviewerField->id,
|
|
'value_user_id' => $reviewer->id,
|
|
]);
|
|
$this->assertDatabaseHas('ticket_field_values', [
|
|
'ticket_id' => $ticket->id,
|
|
'ticket_field_definition_id' => $complexityField->id,
|
|
'value_number' => 8.0,
|
|
]);
|
|
$this->assertDatabaseHas('ticket_worklog_entries', [
|
|
'ticket_id' => $ticket->id,
|
|
'actor_id' => $editor->id,
|
|
'entry_type' => 'updated',
|
|
'summary' => 'Updated title, description, acceptance criteria, story points, type, priority, assignee, Reviewer field, and Complexity field.',
|
|
]);
|
|
}
|
|
|
|
public function test_ticket_update_reuses_acceptance_criteria_ids_when_provided(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticketType = $this->nonParentType($project);
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $ticketType->id,
|
|
'title' => 'Acceptance criteria update test',
|
|
]);
|
|
$rootCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 0,
|
|
'text' => 'Original root item',
|
|
'is_checked' => false,
|
|
]);
|
|
$childCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $rootCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'Original child item',
|
|
'is_checked' => false,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
|
'acceptance_criteria' => [
|
|
[
|
|
'id' => $rootCriterion->id,
|
|
'text' => 'Updated root item',
|
|
'checked' => true,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'id' => $childCriterion->id,
|
|
'text' => 'Updated child item',
|
|
'checked' => true,
|
|
'indent' => 1,
|
|
],
|
|
],
|
|
'blocked_comment' => $ticket->blocked_comment,
|
|
'description' => $ticket->description,
|
|
'field_values' => [],
|
|
'is_blocked' => $ticket->is_blocked,
|
|
'parent_ticket_id' => $ticket->parent_ticket_id,
|
|
'story_points' => $ticket->story_points,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $ticketType->id,
|
|
'title' => $ticket->title,
|
|
])
|
|
->assertRedirect(route('projects.tickets.show', [$project, $ticket]));
|
|
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $rootCriterion->id,
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 0,
|
|
'text' => 'Updated root item',
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $childCriterion->id,
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $rootCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'Updated child item',
|
|
'is_checked' => true,
|
|
]);
|
|
}
|
|
|
|
public function test_ticket_update_returns_json_for_ajax_requests(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticketType = $this->nonParentType($project);
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $ticketType->id,
|
|
'title' => 'Acceptance criteria toggle test',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->withHeaders([
|
|
'Accept' => 'application/json',
|
|
'X-Requested-With' => 'XMLHttpRequest',
|
|
])
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), [
|
|
'acceptance_criteria' => [],
|
|
'blocked_comment' => $ticket->blocked_comment,
|
|
'description' => $ticket->description,
|
|
'field_values' => [],
|
|
'is_blocked' => $ticket->is_blocked,
|
|
'parent_ticket_id' => $ticket->parent_ticket_id,
|
|
'story_points' => $ticket->story_points,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $ticketType->id,
|
|
'title' => $ticket->title,
|
|
])
|
|
->assertOk()
|
|
->assertJson([
|
|
'message' => 'No ticket changes were detected.',
|
|
'updated' => false,
|
|
]);
|
|
}
|
|
|
|
public function test_ticket_update_persists_explicit_child_acceptance_criteria_toggle_states(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticketType = $this->nonParentType($project);
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $ticketType->id,
|
|
'title' => 'Acceptance criteria parent toggle test',
|
|
]);
|
|
$parentCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 0,
|
|
'text' => 'Parent item',
|
|
'is_checked' => false,
|
|
]);
|
|
$childCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $parentCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'Child item',
|
|
'is_checked' => false,
|
|
]);
|
|
$grandchildCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $childCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'Grandchild item',
|
|
'is_checked' => false,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$headers = [
|
|
'Accept' => 'application/json',
|
|
'X-Requested-With' => 'XMLHttpRequest',
|
|
];
|
|
|
|
$this->actingAs($editor)
|
|
->withHeaders($headers)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'acceptance_criteria' => [
|
|
[
|
|
'id' => $parentCriterion->id,
|
|
'text' => 'Parent item',
|
|
'checked' => true,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'id' => $childCriterion->id,
|
|
'text' => 'Child item',
|
|
'checked' => true,
|
|
'indent' => 1,
|
|
],
|
|
[
|
|
'id' => $grandchildCriterion->id,
|
|
'text' => 'Grandchild item',
|
|
'checked' => true,
|
|
'indent' => 2,
|
|
],
|
|
],
|
|
]))
|
|
->assertOk()
|
|
->assertJson([
|
|
'message' => 'CORE-1 was updated.',
|
|
'updated' => true,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $parentCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $childCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $grandchildCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
|
|
$this->actingAs($editor)
|
|
->withHeaders($headers)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket->fresh(), [
|
|
'acceptance_criteria' => [
|
|
[
|
|
'id' => $parentCriterion->id,
|
|
'text' => 'Parent item',
|
|
'checked' => false,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'id' => $childCriterion->id,
|
|
'text' => 'Child item',
|
|
'checked' => false,
|
|
'indent' => 1,
|
|
],
|
|
[
|
|
'id' => $grandchildCriterion->id,
|
|
'text' => 'Grandchild item',
|
|
'checked' => false,
|
|
'indent' => 2,
|
|
],
|
|
],
|
|
]))
|
|
->assertOk()
|
|
->assertJson([
|
|
'message' => 'CORE-1 was updated.',
|
|
'updated' => true,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $parentCriterion->id,
|
|
'is_checked' => false,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $childCriterion->id,
|
|
'is_checked' => false,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $grandchildCriterion->id,
|
|
'is_checked' => false,
|
|
]);
|
|
}
|
|
|
|
public function test_ticket_update_does_not_sync_later_indented_items_outside_the_toggled_subtree(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticketType = $this->nonParentType($project);
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $ticketType->id,
|
|
'title' => 'Acceptance criteria false child test',
|
|
]);
|
|
$loginCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 0,
|
|
'text' => 'Login',
|
|
'is_checked' => false,
|
|
]);
|
|
$stayLoggedInCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $loginCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'stay logged in button',
|
|
'is_checked' => false,
|
|
]);
|
|
$registerCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 1,
|
|
'text' => 'Register',
|
|
'is_checked' => true,
|
|
]);
|
|
$passwordResetCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => null,
|
|
'position' => 2,
|
|
'text' => 'Password reset',
|
|
'is_checked' => true,
|
|
]);
|
|
$rateLimitCriterion = AcceptanceCriterion::query()->create([
|
|
'ticket_id' => $ticket->id,
|
|
'parent_acceptance_criterion_id' => $passwordResetCriterion->id,
|
|
'position' => 0,
|
|
'text' => 'max 1x pro 10 min',
|
|
'is_checked' => false,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->withHeaders([
|
|
'Accept' => 'application/json',
|
|
'X-Requested-With' => 'XMLHttpRequest',
|
|
])
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'acceptance_criteria' => [
|
|
[
|
|
'id' => $loginCriterion->id,
|
|
'text' => 'Login',
|
|
'checked' => true,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'id' => $stayLoggedInCriterion->id,
|
|
'text' => 'stay logged in button',
|
|
'checked' => true,
|
|
'indent' => 1,
|
|
],
|
|
[
|
|
'id' => $registerCriterion->id,
|
|
'text' => 'Register',
|
|
'checked' => true,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'id' => $passwordResetCriterion->id,
|
|
'text' => 'Password reset',
|
|
'checked' => true,
|
|
'indent' => 0,
|
|
],
|
|
[
|
|
'id' => $rateLimitCriterion->id,
|
|
'text' => 'max 1x pro 10 min',
|
|
'checked' => false,
|
|
'indent' => 1,
|
|
],
|
|
],
|
|
]))
|
|
->assertOk()
|
|
->assertJson([
|
|
'message' => 'CORE-1 was updated.',
|
|
'updated' => true,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $loginCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $stayLoggedInCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $registerCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $passwordResetCriterion->id,
|
|
'is_checked' => true,
|
|
]);
|
|
$this->assertDatabaseHas('acceptance_criteria', [
|
|
'id' => $rateLimitCriterion->id,
|
|
'is_checked' => false,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure non-parent tickets cannot be assigned as a parent target.
|
|
*/
|
|
public function test_assigning_a_non_parent_ticket_as_parent_is_rejected(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$taskType = $this->nonParentType($project);
|
|
|
|
$candidateParent = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $taskType->id,
|
|
'title' => 'Task ticket',
|
|
]);
|
|
$childTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 2,
|
|
'ticket_key' => 'CORE-2',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $taskType->id,
|
|
'title' => 'Child ticket',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['edit', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->from(route('projects.tickets.show', [$project, $childTicket]))
|
|
->patch(route('projects.tickets.update', [$project, $childTicket]), $this->updatePayload($childTicket, [
|
|
'parent_ticket_id' => $candidateParent->id,
|
|
]))
|
|
->assertRedirect(route('projects.tickets.show', [$project, $childTicket]))
|
|
->assertSessionHasErrors('parent_ticket_id');
|
|
}
|
|
|
|
/**
|
|
* Ensure parent relationships can be assigned and are written to the worklog.
|
|
*/
|
|
public function test_users_with_edit_permission_can_assign_parent_tickets(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
|
|
$parentTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Parent ticket',
|
|
]);
|
|
$childTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 2,
|
|
'ticket_key' => 'CORE-2',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Child ticket',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['edit', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->patch(route('projects.tickets.update', [$project, $childTicket]), $this->updatePayload($childTicket, [
|
|
'parent_ticket_id' => $parentTicket->id,
|
|
]))
|
|
->assertRedirect(route('projects.tickets.show', [$project, $childTicket]))
|
|
->assertSessionHas('status', 'CORE-2 was updated.');
|
|
|
|
$this->assertDatabaseHas('tickets', [
|
|
'id' => $childTicket->id,
|
|
'parent_ticket_id' => $parentTicket->id,
|
|
]);
|
|
$this->assertDatabaseHas('ticket_worklog_entries', [
|
|
'ticket_id' => $childTicket->id,
|
|
'actor_id' => $editor->id,
|
|
'entry_type' => 'updated',
|
|
'summary' => 'Updated parent ticket.',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure tickets with children must remain parent-enabled.
|
|
*/
|
|
public function test_tickets_with_children_must_keep_a_parent_enabled_type(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create();
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$parentTicket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Parent ticket',
|
|
]);
|
|
Ticket::factory()->create([
|
|
'parent_ticket_id' => $parentTicket->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 2,
|
|
'ticket_key' => 'CORE-2',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Child ticket',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['edit', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->from(route('projects.tickets.show', [$project, $parentTicket]))
|
|
->patch(route('projects.tickets.update', [$project, $parentTicket]), $this->updatePayload($parentTicket, [
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
]))
|
|
->assertRedirect(route('projects.tickets.show', [$project, $parentTicket]))
|
|
->assertSessionHasErrors('ticket_type_id');
|
|
}
|
|
|
|
/**
|
|
* Ensure parent ticket detail pages show nested child trees.
|
|
*/
|
|
public function test_parent_ticket_detail_pages_show_nested_child_trees(): void
|
|
{
|
|
$viewer = User::factory()->create();
|
|
$project = Project::factory()->create([
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
|
|
$rootParent = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Root parent',
|
|
]);
|
|
$nestedParent = Ticket::factory()->create([
|
|
'parent_ticket_id' => $rootParent->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 2,
|
|
'ticket_key' => 'CORE-2',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->parentType($project)->id,
|
|
'title' => 'Nested parent',
|
|
]);
|
|
$directTask = Ticket::factory()->create([
|
|
'parent_ticket_id' => $rootParent->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 3,
|
|
'ticket_key' => 'CORE-3',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Direct task',
|
|
]);
|
|
$nestedTask = Ticket::factory()->create([
|
|
'parent_ticket_id' => $nestedParent->id,
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 4,
|
|
'ticket_key' => 'CORE-4',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'title' => 'Nested task',
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->get(route('projects.tickets.show', [$project, $rootParent]))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('projects/Ticket')
|
|
->where('childTicketTree.0.ticket_key', $nestedParent->ticket_key)
|
|
->where('childTicketTree.0.children.0.ticket_key', $nestedTask->ticket_key)
|
|
->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 = $project->ticketPriorities()->firstOrFail();
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['edit', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->from(route('projects.tickets.show', [$project, $ticket]))
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'blocked_comment' => '',
|
|
'is_blocked' => true,
|
|
]))
|
|
->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 = $project->ticketPriorities()->firstOrFail();
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'sequence_number' => 1,
|
|
'ticket_key' => 'CORE-1',
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['edit', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'blocked_comment' => 'Waiting for dependency approval.',
|
|
'is_blocked' => true,
|
|
]))
|
|
->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]), $this->updatePayload($ticket, [
|
|
'blocked_comment' => '',
|
|
'is_blocked' => false,
|
|
]))
|
|
->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(),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure non-admin users cannot change the fixed author.
|
|
*/
|
|
public function test_non_admin_users_cannot_change_the_ticket_author(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$originalAuthor = User::factory()->create();
|
|
$replacementAuthor = User::factory()->create();
|
|
$project = Project::factory()->create();
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticket = Ticket::factory()->create([
|
|
'author_user_id' => $originalAuthor->id,
|
|
'project_id' => $project->id,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
|
|
$this->actingAs($editor)
|
|
->from(route('projects.tickets.show', [$project, $ticket]))
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'author_user_id' => $replacementAuthor->id,
|
|
]))
|
|
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
|
->assertSessionHasErrors('author_user_id');
|
|
|
|
$this->assertDatabaseHas('tickets', [
|
|
'id' => $ticket->id,
|
|
'author_user_id' => $originalAuthor->id,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure project admins can change the fixed author.
|
|
*/
|
|
public function test_project_admins_can_change_the_ticket_author(): void
|
|
{
|
|
$admin = User::factory()->create();
|
|
$originalAuthor = User::factory()->create();
|
|
$replacementAuthor = User::factory()->create([
|
|
'name' => 'Replacement Author',
|
|
]);
|
|
$project = Project::factory()->create();
|
|
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
|
|
$priority = $project->ticketPriorities()->firstOrFail();
|
|
$ticket = Ticket::factory()->create([
|
|
'author_user_id' => $originalAuthor->id,
|
|
'project_id' => $project->id,
|
|
'ticket_priority_id' => $priority->id,
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
]);
|
|
|
|
$this->syncProjectPermissions($project, $admin, ['admin', 'view']);
|
|
|
|
$this->actingAs($admin)
|
|
->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
'author_user_id' => $replacementAuthor->id,
|
|
]))
|
|
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
|
->assertSessionHas('status', "{$ticket->ticket_key} was updated.");
|
|
|
|
$this->assertDatabaseHas('tickets', [
|
|
'id' => $ticket->id,
|
|
'author_user_id' => $replacementAuthor->id,
|
|
]);
|
|
$this->assertDatabaseHas('ticket_worklog_entries', [
|
|
'ticket_id' => $ticket->id,
|
|
'actor_id' => $admin->id,
|
|
'entry_type' => 'updated',
|
|
'summary' => 'Updated author.',
|
|
]);
|
|
}
|
|
|
|
public function test_read_only_users_cannot_open_or_submit_the_ticket_create_form(): void
|
|
{
|
|
$viewer = User::factory()->create();
|
|
$project = Project::factory()->create();
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
$this->syncProjectPermissions($project, $viewer, ['view']);
|
|
|
|
$this->actingAs($viewer)
|
|
->get(route('projects.tickets.create', $project))
|
|
->assertForbidden();
|
|
|
|
$this->post(route('projects.tickets.store', $project), [
|
|
'title' => 'Unauthorized ticket',
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'ticket_priority_id' => $project->ticketPriorities()->firstOrFail()->id,
|
|
'ticket_status_id' => $project->ticketStatuses()->firstOrFail()->id,
|
|
])->assertForbidden();
|
|
|
|
$this->assertDatabaseCount('tickets', 0);
|
|
}
|
|
|
|
public function test_ticket_forms_reject_metadata_from_another_project(): void
|
|
{
|
|
$editor = User::factory()->create();
|
|
$project = Project::factory()->create();
|
|
$otherProject = Project::factory()->create();
|
|
app(InitializeProjectTicketMetadata::class)->handle($project);
|
|
app(InitializeProjectTicketMetadata::class)->handle($otherProject);
|
|
$this->syncProjectPermissions($project, $editor, ['write', 'view']);
|
|
$parent = Ticket::factory()->create([
|
|
'project_id' => $otherProject->id,
|
|
'ticket_key' => 'OTHER-1',
|
|
'ticket_type_id' => $this->parentType($otherProject)->id,
|
|
'ticket_priority_id' => $otherProject->ticketPriorities()->firstOrFail()->id,
|
|
]);
|
|
$invalidMetadata = [
|
|
'parent_ticket_id' => $parent->id,
|
|
'ticket_type_id' => $this->nonParentType($otherProject)->id,
|
|
'ticket_priority_id' => $otherProject->ticketPriorities()->firstOrFail()->id,
|
|
];
|
|
|
|
$this->actingAs($editor)
|
|
->post(route('projects.tickets.store', $project), [
|
|
...$invalidMetadata,
|
|
'title' => 'Rejected creation',
|
|
'ticket_status_id' => $otherProject->ticketStatuses()->firstOrFail()->id,
|
|
])
|
|
->assertSessionHasErrors([...array_keys($invalidMetadata), 'ticket_status_id']);
|
|
|
|
$this->assertSame(0, $project->tickets()->count());
|
|
|
|
$ticket = Ticket::factory()->create([
|
|
'project_id' => $project->id,
|
|
'ticket_key' => 'LOCAL-1',
|
|
'ticket_type_id' => $this->nonParentType($project)->id,
|
|
'ticket_priority_id' => $project->ticketPriorities()->firstOrFail()->id,
|
|
'title' => 'Original title',
|
|
]);
|
|
|
|
$this->patch(route('projects.tickets.update', [$project, $ticket]), $this->updatePayload($ticket, [
|
|
...$invalidMetadata,
|
|
'title' => 'Rejected update',
|
|
]))->assertSessionHasErrors(array_keys($invalidMetadata));
|
|
|
|
$this->assertSame('Original title', $ticket->fresh()->title);
|
|
$this->assertNull($ticket->fresh()->parent_ticket_id);
|
|
}
|
|
|
|
private function nonParentType(Project $project): TicketType
|
|
{
|
|
return $project->ticketTypes()
|
|
->where('is_parent', false)
|
|
->orderBy('position')
|
|
->firstOrFail();
|
|
}
|
|
|
|
private function parentType(Project $project): TicketType
|
|
{
|
|
return $project->ticketTypes()
|
|
->where('is_parent', true)
|
|
->orderBy('position')
|
|
->firstOrFail();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function updatePayload(Ticket $ticket, array $overrides = []): array
|
|
{
|
|
return array_merge([
|
|
'acceptance_criteria' => AcceptanceCriteriaChecklistMapper::fromModels(
|
|
$ticket->acceptanceCriteria()->get(),
|
|
),
|
|
'assignee_user_id' => $ticket->assignee_user_id,
|
|
'author_user_id' => $ticket->author_user_id,
|
|
'blocked_comment' => $ticket->blocked_comment,
|
|
'description' => $ticket->description,
|
|
'field_values' => [],
|
|
'is_blocked' => $ticket->is_blocked,
|
|
'parent_ticket_id' => $ticket->parent_ticket_id,
|
|
'story_points' => $ticket->story_points,
|
|
'ticket_priority_id' => $ticket->ticket_priority_id,
|
|
'ticket_type_id' => $ticket->ticket_type_id,
|
|
'title' => $ticket->title,
|
|
], $overrides);
|
|
}
|
|
}
|