Implement ticket creation and backlog
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketPriority;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Ticket>
|
||||
*/
|
||||
class TicketFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'acceptance_criteria' => fake()->paragraph(),
|
||||
'board_column_id' => null,
|
||||
'description' => fake()->paragraphs(2, true),
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'TEST-1',
|
||||
'title' => fake()->sentence(4),
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterMaking(function (Ticket $ticket): void {
|
||||
if ($ticket->project_id !== null && $ticket->ticket_type_id !== null && $ticket->ticket_priority_id !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$project = Project::factory()->create([
|
||||
'key' => fake()->unique()->lexify('????'),
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$ticket->project_id = $project->id;
|
||||
$ticket->ticket_type_id = $project->ticketTypes()->firstOrFail()->id;
|
||||
$ticket->ticket_priority_id = $priority->id;
|
||||
$ticket->sequence_number = 1;
|
||||
$ticket->ticket_key = "{$project->key}-1";
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user