Add reusable project templates

This commit is contained in:
2026-05-25 01:26:08 +00:00
parent 3b17c9ee14
commit 58d2edcacd
24 changed files with 1154 additions and 88 deletions
+46
View File
@@ -6,6 +6,7 @@ use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
use App\Actions\Projects\DuplicateProjectConfiguration;
use App\Models\BoardColumn;
use App\Models\Project;
use App\Models\ProjectTemplate;
use App\Models\TicketStatus;
use App\Models\TicketType;
use App\Models\User;
@@ -55,6 +56,51 @@ class ProjectApiTest extends TestCase
$this->assertSame(1, $project->ticketStatuses()->count());
}
public function test_users_can_create_projects_from_templates_via_api(): void
{
$user = User::factory()->create();
$this->syncGlobalPermissions($user, ['create']);
$template = ProjectTemplate::factory()->create([
'name' => 'API Template',
'slug' => 'api-template',
'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' => 'Spike',
'position' => 1,
'is_parent' => false,
],
],
],
]);
$this->withApplicationKey($user)
->postJson(route('api.projects.store'), [
'key' => 'tpl1',
'name' => 'Template API Project',
'creation_mode' => 'template',
'source_template_id' => $template->id,
])
->assertCreated()
->assertJsonPath('data.key', 'TPL1')
->assertJsonPath('data.name', 'Template API Project');
$project = Project::query()->where('key', 'TPL1')->firstOrFail();
$this->assertFalse($project->show_author);
$this->assertFalse($project->show_story_points);
$this->assertSame(['Spike'], $project->ticketTypes()->pluck('name')->all());
}
public function test_users_can_duplicate_projects_via_api(): void
{
$user = User::factory()->create();