From 36f73abcfe5d0c1e6cae8333cbaaabfe768cb8bf Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 4 Dec 2024 17:41:16 +0000 Subject: [PATCH] Add test. --- tests/Actions/DuplicateModelTest.php | 23 +++++++++++++++++++ .../database/factories/PostFactory.php | 1 + 2 files changed, 24 insertions(+) diff --git a/tests/Actions/DuplicateModelTest.php b/tests/Actions/DuplicateModelTest.php index d3c6d6d9..3dfd23d4 100644 --- a/tests/Actions/DuplicateModelTest.php +++ b/tests/Actions/DuplicateModelTest.php @@ -156,6 +156,29 @@ public function it_duplicates_models() $duplicate = Post::query()->whereNot('id', $post->id)->first(); + $this->assertEquals('Hello World (Duplicate)', $duplicate->title); + $this->assertNotNull($duplicate->start_date); + $this->assertFalse($duplicate->published()); + } + + #[Test] + public function only_duplicates_fields_where_duplication_is_enabled() + { + $blueprint = Blueprint::find('runway::post'); + $blueprint->ensureFieldHasConfig('start_date', ['duplicate' => false]); + + Blueprint::shouldReceive('find') + ->with('runway::post') + ->andReturn($blueprint); + + $post = Post::factory()->create(['title' => 'Hello World', 'start_date' => now()]); + + (new DuplicateModel)->run(collect([$post]), []); + + $duplicate = Post::query()->whereNot('id', $post->id)->first(); + + $this->assertEquals('Hello World (Duplicate)', $duplicate->title); + $this->assertNull($duplicate->start_date); $this->assertFalse($duplicate->published()); } } diff --git a/tests/__fixtures__/database/factories/PostFactory.php b/tests/__fixtures__/database/factories/PostFactory.php index a6441dd0..9a0d1a2f 100644 --- a/tests/__fixtures__/database/factories/PostFactory.php +++ b/tests/__fixtures__/database/factories/PostFactory.php @@ -28,6 +28,7 @@ public function definition() 'slug' => Str::slug($title), 'body' => implode(' ', $this->faker->paragraphs(10)), 'author_id' => Author::factory()->create()->id, + 'start_date' => now(), 'published' => true, 'mutated_value' => 'Foo', ];