diff --git a/database/factories/FoodFactory.php b/database/factories/FoodFactory.php index 5e45f68..f117506 100644 --- a/database/factories/FoodFactory.php +++ b/database/factories/FoodFactory.php @@ -22,9 +22,11 @@ class FoodFactory extends Factory 'detail' => $this->faker->sentence(2), 'brand' => $this->faker->word, 'source' => $this->faker->url, + 'notes' => $this->faker->paragraph, 'serving_size' => $this->faker->randomFloat(2, 1/2, 5), 'serving_unit' => $this->faker->randomElement(['tsp', 'tbsp', 'cup']), 'serving_weight' => $this->faker->numberBetween(5, 500), + 'serving_unit_name' => $this->faker->word, 'calories' => $this->faker->randomFloat(2, 0, 100), 'fat' => $this->faker->randomFloat(2, 0, 10), 'cholesterol' => $this->faker->randomFloat(2, 0, 100), diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 547152f..3a35744 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -3,15 +3,15 @@ namespace Tests; use Illuminate\Contracts\Console\Kernel; +use Illuminate\Foundation\Application; trait CreatesApplication { + /** * Creates the application. - * - * @return \Illuminate\Foundation\Application */ - public function createApplication() + public function createApplication(): Application { $app = require __DIR__.'/../bootstrap/app.php'; diff --git a/tests/Feature/FoodTest.php b/tests/Feature/FoodTest.php new file mode 100644 index 0000000..d728aa4 --- /dev/null +++ b/tests/Feature/FoodTest.php @@ -0,0 +1,72 @@ +get('/foods'); + $response->assertOk(); + } + + public function testCanAddFood() + { + /** @var \App\Models\Food $food */ + $food = Food::factory()->make(); + $response = $this->followingRedirects()->post('/foods', $food->toArray()); + $response->assertOk(); + $response->assertSee("Food {$food->name} updated!"); + } + + public function testCanViewFood() + { + /** @var \App\Models\Food $food */ + $food = Food::factory()->create(); + $view_url = action([FoodController::class, 'show'], ['food' => $food]); + $response = $this->get($view_url); + $response->assertOk(); + $response->assertSee($food->name); + } + + public function testCanEditFood() + { + /** @var \App\Models\Food $food */ + $food = Food::factory()->create(); + $edit_url = action([FoodController::class, 'edit'], ['food' => $food]); + $response = $this->get($edit_url); + $response->assertOk(); + + /** @var \App\Models\Food $new_food */ + $new_food = Food::factory()->make(); + $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() + { + /** @var \App\Models\Food $food */ + $food = Food::factory()->create(); + $delete_url = action([FoodController::class, 'delete'], ['food' => $food]); + $response = $this->get($delete_url); + $response->assertOk(); + $response->assertSee("Delete {$food->name}?"); + + $destroy_url = action([FoodController::class, 'destroy'], ['food' => $food]); + $response = $this->followingRedirects()->delete($destroy_url); + $response->assertOk(); + + $view_url = action([FoodController::class, 'show'], ['food' => $food]); + $response = $this->get($view_url); + $response->assertNotFound(); + } +} diff --git a/tests/LoggedInTestCase.php b/tests/LoggedInTestCase.php new file mode 100644 index 0000000..fd900f1 --- /dev/null +++ b/tests/LoggedInTestCase.php @@ -0,0 +1,15 @@ +loginUser(); + } + +} diff --git a/tests/LogsIn.php b/tests/LogsIn.php new file mode 100644 index 0000000..dfb5601 --- /dev/null +++ b/tests/LogsIn.php @@ -0,0 +1,22 @@ +user = User::factory()->create(); + $this->post('/login', [ + 'email' => $this->user->email, + 'password' => 'password', + ]); + } +}