diff --git a/app/Models/Note.php b/app/Models/Note.php index 0505b835b8..af3222cd0a 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -2,7 +2,9 @@ namespace App\Models; +use Database\Factories\NoteFactory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -15,6 +17,9 @@ */ class Note extends Model { + /** @use HasFactory */ + use HasFactory; + protected $table = 'note'; public $timestamps = false; diff --git a/database/factories/NoteFactory.php b/database/factories/NoteFactory.php new file mode 100644 index 0000000000..ceee3a74e2 --- /dev/null +++ b/database/factories/NoteFactory.php @@ -0,0 +1,26 @@ + + */ +class NoteFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => Str::uuid()->toString(), + 'text' => Str::uuid()->toString(), + ]; + } +} diff --git a/tests/Browser/Pages/BuildNotesPageTest.php b/tests/Browser/Pages/BuildNotesPageTest.php index 38b87e2021..13d842137e 100644 --- a/tests/Browser/Pages/BuildNotesPageTest.php +++ b/tests/Browser/Pages/BuildNotesPageTest.php @@ -64,10 +64,7 @@ public function tearDown(): void private function addNote(): Note { - $note = Note::create([ - 'name' => Str::uuid()->toString(), - 'text' => Str::uuid()->toString(), - ]); + $note = Note::factory()->create(); $this->build->notes()->attach($note); diff --git a/tests/Browser/Pages/BuildSidebarComponentTest.php b/tests/Browser/Pages/BuildSidebarComponentTest.php index aebb6df9e1..aba1e7107f 100644 --- a/tests/Browser/Pages/BuildSidebarComponentTest.php +++ b/tests/Browser/Pages/BuildSidebarComponentTest.php @@ -348,10 +348,7 @@ public function testNotesItem(): void $this->assertDisabled($browser, "/builds/{$build->id}", '@sidebar-notes'); $build->notes()->attach( - Note::create([ - 'name' => Str::uuid()->toString(), - 'text' => Str::uuid()->toString(), - ]) + Note::factory()->create() ); $this->assertNotDisabled($browser, "/builds/{$build->id}", '@sidebar-notes', "/builds/{$build->id}/notes"); diff --git a/tests/Feature/GraphQL/NoteTypeTest.php b/tests/Feature/GraphQL/NoteTypeTest.php index 02302d2f7d..a5435b1f2d 100644 --- a/tests/Feature/GraphQL/NoteTypeTest.php +++ b/tests/Feature/GraphQL/NoteTypeTest.php @@ -45,20 +45,9 @@ protected function setUp(): void $this->public_project = $this->makePublicProject(); $this->private_project = $this->makePrivateProject(); - $this->note1 = Note::create([ - 'name' => Str::uuid()->toString(), - 'text' => Str::uuid()->toString(), - ]); - - $this->note2 = Note::create([ - 'name' => Str::uuid()->toString(), - 'text' => Str::uuid()->toString(), - ]); - - $this->note3 = Note::create([ - 'name' => Str::uuid()->toString(), - 'text' => Str::uuid()->toString(), - ]); + $this->note1 = Note::factory()->create(); + $this->note2 = Note::factory()->create(); + $this->note3 = Note::factory()->create(); $this->public_project->builds()->create([ 'name' => 'build1',