Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/Models/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Models;

use App\Enums\TargetType;
use Database\Factories\TargetFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand All @@ -19,6 +21,9 @@
*/
class Target extends Model
{
/** @use HasFactory<TargetFactory> */
use HasFactory;

protected $table = 'targets';

public $timestamps = false;
Expand Down
27 changes: 27 additions & 0 deletions database/factories/TargetFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Database\Factories;

use App\Enums\TargetType;
use App\Models\Target;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
* @extends Factory<Target>
*/
class TargetFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => Str::uuid()->toString(),
'type' => TargetType::UNKNOWN,
];
}
}
7 changes: 2 additions & 5 deletions tests/Browser/Pages/BuildSidebarComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests\Browser\Pages;

use App\Enums\BuildCommandType;
use App\Enums\TargetType;
use App\Models\Build;
use App\Models\BuildUpdate;
use App\Models\CoverageFile;
Expand All @@ -12,6 +11,7 @@
use App\Models\Project;
use App\Models\Site;
use App\Models\SiteInformation;
use App\Models\Target;
use App\Models\UploadFile;
use App\Models\User;
use App\Services\SiteService;
Expand Down Expand Up @@ -393,10 +393,7 @@ public function testTargetsItem(): void
$this->browse(function (Browser $browser) use ($build): void {
$this->assertDisabled($browser, "/builds/{$build->id}", '@sidebar-targets');

$build->targets()->create([
'name' => Str::uuid()->toString(),
'type' => TargetType::UNKNOWN,
]);
Target::factory()->for($build)->create();

$this->assertNotDisabled($browser, "/builds/{$build->id}", '@sidebar-targets', "/builds/{$build->id}/targets");
});
Expand Down
8 changes: 2 additions & 6 deletions tests/Browser/Pages/BuildTargetsPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function tearDown(): void

private function addTarget(TargetType $type = TargetType::UNKNOWN): Target
{
return $this->build->targets()->create([
'name' => Str::uuid()->toString(),
return Target::factory()->for($this->build)->create([
'type' => $type,
]);
}
Expand Down Expand Up @@ -125,10 +124,7 @@ public function testFilters(): void

public function testTargetTablePagination(): void
{
$targets = collect();
for ($i = 0; $i < 120; $i++) {
$targets[] = $this->addTarget();
}
$targets = Target::factory()->count(120)->for($this->build)->create();

$targets = $targets->sortByDesc('name');

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/GraphQL/BuildTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Feature\GraphQL;

use App\Enums\BuildCommandType;
use App\Enums\TargetType;
use App\Models\Build;
use App\Models\BuildCommand;
use App\Models\CoverageFile;
Expand Down Expand Up @@ -319,9 +320,8 @@ public function testTargetRelationship(): void
]);

/** @var Target $target */
$target = $build->targets()->create([
'name' => Str::uuid()->toString(),
'type' => 'EXECUTABLE',
$target = Target::factory()->for($build)->create([
'type' => TargetType::EXECUTABLE,
]);

$this->graphQL('
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/GraphQL/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Tests\Feature\GraphQL;

use App\Enums\TargetType;
use App\Models\Build;
use App\Models\Project;
use App\Models\Site;
use App\Models\Target;
use App\Models\Test;
use App\Models\TestOutput;
use App\Models\User;
Expand Down Expand Up @@ -982,22 +982,22 @@ public function testFilterByRelationshipsOfRelationships(): void
{
$build1uuid = Str::uuid()->toString();
$target1name = Str::uuid()->toString();
$this->projects['public1']->builds()->create([
$build1 = $this->projects['public1']->builds()->create([
'name' => 'build1',
'uuid' => $build1uuid,
])->targets()->create([
]);
Target::factory()->for($build1)->create([
'name' => $target1name,
'type' => TargetType::UNKNOWN,
]);

$build2uuid = Str::uuid()->toString();
$target2name = Str::uuid()->toString();
$this->projects['public2']->builds()->create([
$build2 = $this->projects['public2']->builds()->create([
'name' => 'build1',
'uuid' => $build2uuid,
])->targets()->create([
]);
Target::factory()->for($build2)->create([
'name' => $target2name,
'type' => TargetType::UNKNOWN,
]);

$this->actingAs($this->users['admin'])->graphQL('
Expand Down
7 changes: 2 additions & 5 deletions tests/Feature/GraphQL/LabelTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Tests\Feature\GraphQL;

use App\Enums\TargetType;
use App\Models\Label;
use App\Models\Project;
use App\Models\Target;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Str;
use Tests\TestCase;
Expand Down Expand Up @@ -142,10 +142,7 @@ public function testTargetRelationship(): void
'uuid' => Str::uuid()->toString(),
]);

$target = $build->targets()->create([
'name' => Str::uuid()->toString(),
'type' => TargetType::UNKNOWN,
]);
$target = Target::factory()->for($build)->create();

$this->labels['label1'] = $target->labels()->save(Label::factory()->make());

Expand Down
47 changes: 17 additions & 30 deletions tests/Feature/GraphQL/TargetTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,18 @@ public function testTypeEnumValues(): void
]);

// Create one target of each type
$targets = [];
foreach (TargetType::cases() as $target_type) {
$targets[] = [
'name' => Str::uuid()->toString(),
'type' => $target_type,
];
}
$build->targets()->createMany($targets);
$targets = Target::factory()
->count(count(TargetType::cases()))
->sequence(...array_map(fn (TargetType $type) => ['type' => $type], TargetType::cases()))
->for($build)
->create();

$target_node_list = [];
foreach ($targets as $target) {
$target_node_list[] = [
'node' => [
'name' => $target['name'],
'type' => $target['type']->name,
'name' => $target->name,
'type' => $target->type->name,
],
];
}
Expand Down Expand Up @@ -99,16 +96,10 @@ public function testFilterByName(): void
'uuid' => Str::uuid()->toString(),
]);

$build->targets()->createMany([
[
'name' => 'name1',
'type' => TargetType::UNKNOWN,
],
[
'name' => 'name2',
'type' => TargetType::UNKNOWN,
],
]);
Target::factory()->count(2)->sequence(
['name' => 'name1'],
['name' => 'name2'],
)->for($build)->create();

$this->graphQL('
query build($id: ID) {
Expand Down Expand Up @@ -170,14 +161,11 @@ public function testFilterByType(string $type): void
]);

// Create one target of each type
$targets = [];
foreach (TargetType::cases() as $target_type) {
$targets[] = [
'name' => Str::uuid()->toString(),
'type' => $target_type,
];
}
$build->targets()->createMany($targets);
Target::factory()
->count(count(TargetType::cases()))
->sequence(...array_map(fn (TargetType $type) => ['type' => $type], TargetType::cases()))
->for($build)
->create();

$this->graphQL('
query build($id: ID, $type: TargetType) {
Expand Down Expand Up @@ -226,9 +214,8 @@ public function testBuildCommandRelationship(): void
]);

/** @var Target $target */
$target = $build->targets()->create([
$target = Target::factory()->for($build)->create([
'name' => 'name1',
'type' => TargetType::UNKNOWN,
]);

/** @var BuildCommand $command */
Expand Down