Implement ticket statuses
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -33,10 +34,14 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
$priority = $project->ticketPriorities()->firstOrFail();
|
||||
$backlogStatus = $project->ticketStatuses()
|
||||
->whereNull('board_column_id')
|
||||
->firstOrFail();
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'ticket_key' => 'AUTH-1',
|
||||
'sequence_number' => 1,
|
||||
@@ -50,7 +55,7 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('projects/Backlog')
|
||||
->where('boardColumns.0.name', 'Todo')
|
||||
->where('backlogTicketStatuses.0.name', 'Backlog')
|
||||
->where('canEditTickets', false)
|
||||
->where('project.id', $project->id)
|
||||
->where('tickets.0.ticket_key', $ticket->ticket_key)
|
||||
@@ -69,6 +74,9 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = $project->ticketPriorities()->firstOrFail();
|
||||
$backlogStatus = $project->ticketStatuses()
|
||||
->whereNull('board_column_id')
|
||||
->firstOrFail();
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['view']);
|
||||
|
||||
@@ -79,6 +87,7 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
'acceptance_criteria' => 'Criteria',
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
])
|
||||
->assertForbidden();
|
||||
}
|
||||
@@ -100,6 +109,9 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
'name' => 'High',
|
||||
'position' => 2,
|
||||
]);
|
||||
$backlogStatus = $project->ticketStatuses()
|
||||
->whereNull('board_column_id')
|
||||
->firstOrFail();
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['create', 'view']);
|
||||
|
||||
@@ -111,6 +123,7 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
'story_points' => 3,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
];
|
||||
|
||||
$this->actingAs($user)
|
||||
@@ -129,8 +142,8 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
'title' => 'Same title',
|
||||
'assignee_user_id' => $assignee->id,
|
||||
'author_user_id' => $user->id,
|
||||
'board_column_id' => null,
|
||||
'story_points' => 3,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
@@ -139,8 +152,8 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
'title' => 'Same title',
|
||||
'assignee_user_id' => $assignee->id,
|
||||
'author_user_id' => $user->id,
|
||||
'board_column_id' => null,
|
||||
'story_points' => 3,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseCount('ticket_worklog_entries', 2);
|
||||
@@ -149,4 +162,44 @@ class ProjectBacklogControllerTest extends TestCase
|
||||
'summary' => 'Ticket was created in Backlog.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure ticket creation only accepts backlog statuses.
|
||||
*/
|
||||
public function test_creating_tickets_rejects_board_column_statuses(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$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, $user, ['create', 'view']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.backlog.index', $project))
|
||||
->post(route('projects.backlog.store', $project), [
|
||||
'title' => 'New ticket',
|
||||
'description' => 'Description',
|
||||
'acceptance_criteria' => 'Criteria',
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'ticket_priority_id' => $project->ticketPriorities()->firstOrFail()->id,
|
||||
'ticket_status_id' => $boardStatus->id,
|
||||
])
|
||||
->assertRedirect(route('projects.backlog.index', $project))
|
||||
->assertSessionHasErrors('ticket_status_id');
|
||||
|
||||
$this->assertDatabaseCount('tickets', 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user