Fix KAN-3 project template flows

This commit is contained in:
2026-09-08 10:25:52 +00:00
parent db8855a056
commit fed6a282a4
13 changed files with 143 additions and 91 deletions
+8 -4
View File
@@ -2,8 +2,8 @@
namespace Tests\Feature\Api;
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
use App\Actions\Projects\DuplicateProjectConfiguration;
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
use App\Models\BoardColumn;
use App\Models\Project;
use App\Models\ProjectTemplate;
@@ -102,15 +102,19 @@ class ProjectApiTest extends TestCase
$project->refresh();
$this->assertNotSame($template->id, $project->project_template_id);
$this->assertDatabaseHas('project_templates', [
'id' => $project->project_template_id,
$this->assertSame($template->id, $project->project_template_id);
$this->assertDatabaseMissing('project_templates', [
'project_id' => $project->id,
'is_published' => false,
]);
$this->assertFalse($project->show_author);
$this->assertFalse($project->show_story_points);
$this->assertSame(['Spike'], $project->ticketTypes()->pluck('name')->all());
$this->assertDatabaseHas('ticket_types', [
'project_id' => $project->id,
'project_template_id' => $template->id,
'name' => 'Spike',
]);
}
public function test_project_api_exposes_template_context_and_overrides(): void
@@ -285,9 +285,8 @@ class ProjectControllerTest extends TestCase
$project->refresh();
$this->assertNotSame($template->id, $project->project_template_id);
$this->assertDatabaseHas('project_templates', [
'id' => $project->project_template_id,
$this->assertSame($template->id, $project->project_template_id);
$this->assertDatabaseMissing('project_templates', [
'project_id' => $project->id,
'is_published' => false,
]);
@@ -295,6 +294,7 @@ class ProjectControllerTest extends TestCase
$this->assertSame(false, $project->show_story_points);
$this->assertDatabaseHas('ticket_types', [
'project_id' => $project->id,
'project_template_id' => $template->id,
'name' => 'Bug',
'position' => 1,
'is_parent' => false,
@@ -661,6 +661,11 @@ class ProjectControllerTest extends TestCase
$this->assertTrue($project->show_author);
$this->assertTrue($project->show_story_points);
$this->assertSame(['Incident', 'Maintenance'], $project->ticketTypes()->pluck('name')->all());
$this->assertDatabaseHas('ticket_types', [
'project_id' => $project->id,
'project_template_id' => $newTemplate->id,
'name' => 'Incident',
]);
}
public function test_project_admins_can_reset_projects_to_their_current_template_baseline(): void
@@ -711,6 +716,11 @@ class ProjectControllerTest extends TestCase
$this->assertTrue($project->show_author);
$this->assertTrue($project->show_story_points);
$this->assertSame(['Bug', 'Feature'], $project->ticketTypes()->pluck('name')->all());
$this->assertDatabaseHas('ticket_types', [
'project_id' => $project->id,
'project_template_id' => $template->id,
'name' => 'Bug',
]);
}
public function test_project_template_switch_requires_exact_project_key_confirmation(): void
@@ -192,15 +192,32 @@ class ProjectTemplateControllerTest extends TestCase
'show_author' => false,
'show_story_points' => false,
]);
TicketType::factory()->create([
'project_id' => $sourceProject->id,
'name' => 'Feature',
'position' => 1,
'is_parent' => false,
]);
$template = ProjectTemplate::factory()->create([
'name' => 'Platform Template',
'slug' => 'platform-template',
'copy_areas' => [DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS],
'copy_areas' => [
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
],
'configuration_snapshot' => [
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS => [
'show_author' => false,
'show_story_points' => false,
],
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
[
'name' => 'Bug',
'position' => 1,
'is_parent' => false,
],
],
],
'source_project_id' => $sourceProject->id,
]);
@@ -214,6 +231,18 @@ class ProjectTemplateControllerTest extends TestCase
'show_author' => true,
'show_story_points' => false,
]);
TicketType::factory()->create([
'project_id' => $inheritingProject->id,
'name' => 'Bug',
'position' => 1,
'is_parent' => false,
]);
TicketType::factory()->create([
'project_id' => $overriddenProject->id,
'name' => 'Custom',
'position' => 1,
'is_parent' => false,
]);
$sourceProject->forceFill([
'show_author' => true,
@@ -226,7 +255,10 @@ class ProjectTemplateControllerTest extends TestCase
->patch(route('project-templates.update', $template), [
'name' => 'Platform Template v2',
'slug' => 'should-not-change',
'copy_areas' => [DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS],
'copy_areas' => [
DuplicateProjectConfiguration::COPY_PROJECT_SETTINGS,
DuplicateProjectConfiguration::COPY_TICKET_TYPES,
],
'confirm_linked_projects_update' => true,
])
->assertRedirect('/project-templates');
@@ -242,12 +274,26 @@ class ProjectTemplateControllerTest extends TestCase
'show_author' => true,
'show_story_points' => true,
],
DuplicateProjectConfiguration::COPY_TICKET_TYPES => [
[
'name' => 'Feature',
'position' => 1,
'is_parent' => false,
],
],
], $template->configuration_snapshot);
$this->assertTrue($inheritingProject->show_author);
$this->assertTrue($inheritingProject->show_story_points);
$this->assertSame(['Feature'], $inheritingProject->ticketTypes()->pluck('name')->all());
$this->assertDatabaseHas('ticket_types', [
'project_id' => $inheritingProject->id,
'project_template_id' => $template->id,
'name' => 'Feature',
]);
$this->assertTrue($overriddenProject->show_author);
$this->assertFalse($overriddenProject->show_story_points);
$this->assertSame(['Custom'], $overriddenProject->ticketTypes()->pluck('name')->all());
}
}