From 5de41c4793604187a066e4f9dd6e1285e49a81b6 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sun, 6 Mar 2022 20:47:42 -0800 Subject: [PATCH] Add recipe duplicate test --- .../Http/Controllers/RecipeControllerTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Feature/Http/Controllers/RecipeControllerTest.php b/tests/Feature/Http/Controllers/RecipeControllerTest.php index 84db622..b2874c8 100644 --- a/tests/Feature/Http/Controllers/RecipeControllerTest.php +++ b/tests/Feature/Http/Controllers/RecipeControllerTest.php @@ -102,6 +102,25 @@ class RecipeControllerTest extends HttpControllerTestCase $response->assertSessionHasNoErrors(); } + public function testCanDuplicateInstances(): void { + $instance = $this->createInstance(); + $confirm_url = action([$this->class(), 'duplicateConfirm'], [$this->routeKey() => $instance]); + $response = $this->get($confirm_url); + $response->assertOk(); + $response->assertViewHas($this->routeKey()); + + $duplicate_url = action([$this->class(), 'duplicate'], [$this->routeKey() => $instance]); + $response = $this->followingRedirects()->post($duplicate_url, ['name' => 'Duplicated Recipe']); + $response->assertOk(); + + $recipe = Recipe::latest()->first(); + $this->assertEquals('Duplicated Recipe', $recipe->name); + $this->assertEquals($instance->tags->toArray(), $instance->tags->toArray()); + $this->assertEquals($instance->ingredientAmounts->toArray(), $instance->ingredientAmounts->toArray()); + $this->assertEquals($instance->steps->toArray(), $instance->steps->toArray()); + $this->assertEquals($instance->separators->toArray(), $instance->separators->toArray()); + } + public function testSessionKeepsOldInputOnAdd(): void { $instance = $this->createInstance(); $data = $this->createInvalidFormData($instance);