125 lines
3.3 KiB
PHP
125 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Models;
|
|
|
|
use App\Models\BoardColumn;
|
|
use App\Models\Project;
|
|
use Database\Seeders\BoardColumnSeeder;
|
|
use Database\Seeders\ProjectSeeder;
|
|
use Database\Seeders\ProjectTicketMetadataSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ProjectTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* Ensure project keys are always stored in uppercase.
|
|
*/
|
|
public function test_project_keys_are_stored_in_uppercase(): void
|
|
{
|
|
$project = Project::factory()->create([
|
|
'key' => 'core',
|
|
]);
|
|
|
|
$this->assertSame('CORE', $project->fresh()->key);
|
|
}
|
|
|
|
/**
|
|
* Ensure the project seeder creates the expected starter projects.
|
|
*/
|
|
public function test_project_seeder_creates_projects(): void
|
|
{
|
|
$this->seed(ProjectSeeder::class);
|
|
|
|
$this->assertDatabaseHas('projects', [
|
|
'name' => 'Core Platform',
|
|
'key' => 'CORE',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('projects', [
|
|
'name' => 'Authentication',
|
|
'key' => 'AUTH',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('projects', [
|
|
'name' => 'Operations',
|
|
'key' => 'OPS',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure projects expose their board columns in the configured order.
|
|
*/
|
|
public function test_projects_have_an_ordered_board_columns_relationship(): void
|
|
{
|
|
$project = Project::factory()->create();
|
|
|
|
BoardColumn::factory()->for($project)->create([
|
|
'name' => 'Done',
|
|
'position' => 3,
|
|
]);
|
|
BoardColumn::factory()->for($project)->create([
|
|
'name' => 'Todo',
|
|
'position' => 1,
|
|
]);
|
|
BoardColumn::factory()->for($project)->create([
|
|
'name' => 'In Progress',
|
|
'position' => 2,
|
|
]);
|
|
|
|
$this->assertSame(
|
|
['Todo', 'In Progress', 'Done'],
|
|
$project->fresh()->boardColumns->pluck('name')->all(),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure the default database seeding can include project board columns.
|
|
*/
|
|
public function test_board_column_seeder_adds_columns_to_seeded_projects(): void
|
|
{
|
|
$this->seed([
|
|
ProjectSeeder::class,
|
|
BoardColumnSeeder::class,
|
|
]);
|
|
|
|
$coreProject = Project::query()->where('key', 'CORE')->firstOrFail();
|
|
|
|
$this->assertDatabaseHas('board_columns', [
|
|
'project_id' => $coreProject->id,
|
|
'name' => 'Todo',
|
|
'position' => 1,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Ensure projects expose ticket metadata relationships after seeding.
|
|
*/
|
|
public function test_projects_expose_ticket_metadata_relationships(): void
|
|
{
|
|
$this->seed([
|
|
ProjectSeeder::class,
|
|
ProjectTicketMetadataSeeder::class,
|
|
]);
|
|
|
|
$coreProject = Project::query()->where('key', 'CORE')->firstOrFail();
|
|
|
|
$this->assertSame(
|
|
['Task', 'Parent', 'Bug'],
|
|
$coreProject->ticketTypes->pluck('name')->all(),
|
|
);
|
|
|
|
$this->assertSame(
|
|
['Low', 'Medium', 'High'],
|
|
$coreProject->ticketPriorities->pluck('name')->all(),
|
|
);
|
|
|
|
$this->assertSame(
|
|
['Assignee', 'Story Points'],
|
|
$coreProject->ticketFieldDefinitions->pluck('label')->all(),
|
|
);
|
|
}
|
|
}
|