From e3f5f0a2e6dfb74dcdb5e10f053770316027d75b Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sun, 28 Mar 2021 21:09:45 -0700 Subject: [PATCH] Test Food tags and empty nutrients --- database/factories/FoodFactory.php | 1 + tests/Feature/FoodTest.php | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/database/factories/FoodFactory.php b/database/factories/FoodFactory.php index f117506..3a3f6c6 100644 --- a/database/factories/FoodFactory.php +++ b/database/factories/FoodFactory.php @@ -33,6 +33,7 @@ class FoodFactory extends Factory 'sodium' => $this->faker->randomFloat(2, 0, 500), 'carbohydrates' => $this->faker->randomFloat(2, 0, 20), 'protein' => $this->faker->randomFloat(2, 0, 20), + 'tags' => $this->faker->words, ]; } diff --git a/tests/Feature/FoodTest.php b/tests/Feature/FoodTest.php index 2c8fdb9..8e8e5ea 100644 --- a/tests/Feature/FoodTest.php +++ b/tests/Feature/FoodTest.php @@ -11,13 +11,13 @@ class FoodTest extends LoggedInTestCase { use RefreshDatabase; - public function testCanLoadFoodIndex() + public function testCanLoadFoodIndex(): void { $response = $this->get('/foods'); $response->assertOk(); } - public function testCanAddFood() + public function testCanAddFood(): void { $create_url = action([FoodController::class, 'create']); $response = $this->get($create_url); @@ -31,7 +31,24 @@ class FoodTest extends LoggedInTestCase $response->assertSee("Food {$food->name} updated!"); } - public function testCanViewFood() + public function testCanAddFoodWithoutNutrients(): void + { + /** @var \App\Models\Food $food */ + $food = Food::factory()->make([ + 'calories' => NULL, + 'fat' => NULL, + 'cholesterol' => NULL, + 'sodium' => NULL, + 'carbohydrates' => NULL, + 'protein' => NULL, + ]); + $store_url = action([FoodController::class, 'store']); + $response = $this->followingRedirects()->post($store_url, $food->toArray()); + $response->assertOk(); + $response->assertSee("Food {$food->name} updated!"); + } + + public function testCanViewFood(): void { /** @var \App\Models\Food $food */ $food = Food::factory()->create(); @@ -41,7 +58,7 @@ class FoodTest extends LoggedInTestCase $response->assertSee($food->name); } - public function testCanEditFood() + public function testCanEditFood(): void { /** @var \App\Models\Food $food */ $food = Food::factory()->create(); @@ -50,14 +67,14 @@ class FoodTest extends LoggedInTestCase $response->assertOk(); /** @var \App\Models\Food $new_food */ - $new_food = Food::factory()->make(); + $new_food = Food::factory()->make(['tags' => []]); $put_url = action([FoodController::class, 'update'], ['food' => $food]); $response = $this->followingRedirects()->put($put_url, $new_food->toArray()); $response->assertOk(); $response->assertSee("Food {$new_food->name} updated!"); } - public function testCanDeleteFood() + public function testCanDeleteFood(): void { /** @var \App\Models\Food $food */ $food = Food::factory()->create();