Implement ticket statuses
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -22,6 +25,7 @@ class ProjectBoardSettingsControllerTest extends TestCase
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
@@ -35,6 +39,7 @@ class ProjectBoardSettingsControllerTest extends TestCase
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('projects/settings/Board')
|
||||
->where('project.id', $project->id)
|
||||
->where('backlogTicketStatuses.0.name', 'Backlog')
|
||||
->where('boardColumns.0.name', 'Todo'),
|
||||
);
|
||||
}
|
||||
@@ -76,6 +81,13 @@ class ProjectBoardSettingsControllerTest extends TestCase
|
||||
'name' => 'In Review',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('ticket_statuses', [
|
||||
'project_id' => $project->id,
|
||||
'name' => 'In Review',
|
||||
'slug' => 'in-review',
|
||||
'position' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,4 +166,103 @@ class ProjectBoardSettingsControllerTest extends TestCase
|
||||
'id' => $secondColumn->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure authorized users can manage multiple statuses for backlog and columns.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_manage_ticket_statuses(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$boardColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$defaultStatus = TicketStatus::factory()
|
||||
->for($project)
|
||||
->for($boardColumn)
|
||||
->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.settings.board.statuses.store', $project), [
|
||||
'board_column_id' => $boardColumn->id,
|
||||
'name' => 'Ready for QA',
|
||||
])
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHas('status', 'Ready for QA was added to Todo.');
|
||||
|
||||
$newStatus = TicketStatus::query()
|
||||
->where('project_id', $project->id)
|
||||
->where('name', 'Ready for QA')
|
||||
->firstOrFail();
|
||||
|
||||
$this->assertSame($boardColumn->id, $newStatus->board_column_id);
|
||||
$this->assertSame('ready-for-qa', $newStatus->slug);
|
||||
$this->assertTrue($defaultStatus->allowedTargetStatuses()->whereKey($newStatus->id)->exists());
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.settings.board.statuses.update', [$project, $newStatus]), [
|
||||
'name' => 'QA Ready',
|
||||
])
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHas('status', 'QA Ready was updated.');
|
||||
|
||||
$newStatus->refresh();
|
||||
|
||||
$this->assertSame('QA Ready', $newStatus->name);
|
||||
$this->assertSame('qa-ready', $newStatus->slug);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'ticket_status_id' => $newStatus->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('projects.settings.board.statuses.destroy', [$project, $newStatus]))
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHas('status', 'QA Ready was removed from Todo.');
|
||||
|
||||
$this->assertDatabaseMissing('ticket_statuses', [
|
||||
'id' => $newStatus->id,
|
||||
]);
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $ticket->id,
|
||||
'ticket_status_id' => $defaultStatus->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the last status in a column or backlog cannot be deleted.
|
||||
*/
|
||||
public function test_last_ticket_status_for_a_context_cannot_be_deleted(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$backlogStatus = TicketStatus::factory()
|
||||
->for($project)
|
||||
->create([
|
||||
'name' => 'Backlog',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.settings.board', $project))
|
||||
->delete(route('projects.settings.board.statuses.destroy', [$project, $backlogStatus]))
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHasErrors('ticket_status_id');
|
||||
|
||||
$this->assertDatabaseHas('ticket_statuses', [
|
||||
'id' => $backlogStatus->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user