diff --git a/database/factories/GoalFactory.php b/database/factories/GoalFactory.php index 5875b25..78c51c8 100644 --- a/database/factories/GoalFactory.php +++ b/database/factories/GoalFactory.php @@ -32,7 +32,7 @@ class GoalFactory extends Factory 'frequency' => $this->faker->randomElement(Goal::$frequencyOptions)['value'], 'name' => $this->faker->randomElement(Goal::getNameOptions())['value'], 'goal' => $this->faker->numberBetween(0, 2000), - 'user' => $user, + 'user_id' => $user->id, ]; } } diff --git a/resources/views/goals/delete.blade.php b/resources/views/goals/delete.blade.php index 07bb70b..0138ba1 100644 --- a/resources/views/goals/delete.blade.php +++ b/resources/views/goals/delete.blade.php @@ -2,7 +2,7 @@ Delete Goal

- Delete {{ $goal->goal }} goal? + Delete {{ $goal->summary }} goal?

diff --git a/tests/Feature/FoodTest.php b/tests/Feature/FoodTest.php index 8e8e5ea..d634d20 100644 --- a/tests/Feature/FoodTest.php +++ b/tests/Feature/FoodTest.php @@ -13,7 +13,8 @@ class FoodTest extends LoggedInTestCase public function testCanLoadFoodIndex(): void { - $response = $this->get('/foods'); + $index_url = action([FoodController::class, 'index']); + $response = $this->get($index_url); $response->assertOk(); } diff --git a/tests/Feature/GoalTest.php b/tests/Feature/GoalTest.php new file mode 100644 index 0000000..cd7fc94 --- /dev/null +++ b/tests/Feature/GoalTest.php @@ -0,0 +1,78 @@ +get($index_url); + $response->assertOk(); + } + + public function testCanAddGoal(): void + { + $create_url = action([GoalController::class, 'create']); + $response = $this->get($create_url); + $response->assertOk(); + + /** @var \App\Models\Goal $goal */ + $goal = Goal::factory()->make(); + $store_url = action([GoalController::class, 'store']); + $response = $this->followingRedirects()->post($store_url, $goal->toArray()); + $response->assertOk(); + $response->assertSee('Goal updated!'); + } + + public function testCanViewGoal(): void + { + /** @var \App\Models\Goal $goal */ + $goal = Goal::factory()->create(); + $view_url = action([GoalController::class, 'show'], ['goal' => $goal]); + $response = $this->get($view_url); + $response->assertOk(); + $response->assertSee($goal->summary); + } + + public function testCanEditGoal(): void + { + /** @var \App\Models\Goal $goal */ + $goal = Goal::factory()->create(); + $edit_url = action([GoalController::class, 'edit'], ['goal' => $goal]); + $response = $this->get($edit_url); + $response->assertOk(); + + /** @var \App\Models\Goal $new_food */ + $new_food = Goal::factory()->make(['tags' => []]); + $put_url = action([GoalController::class, 'update'], ['goal' => $goal]); + $response = $this->followingRedirects()->put($put_url, $new_food->toArray()); + $response->assertOk(); + $response->assertSee('Goal updated!'); + } + + public function testCanDeleteGoal(): void + { + /** @var \App\Models\Goal $goal */ + $goal = Goal::factory()->create(); + $delete_url = action([GoalController::class, 'delete'], ['goal' => $goal]); + $response = $this->get($delete_url); + $response->assertOk(); + $response->assertSee("Delete {$goal->summary} goal?"); + + $destroy_url = action([GoalController::class, 'destroy'], ['goal' => $goal]); + $response = $this->followingRedirects()->delete($destroy_url); + $response->assertOk(); + + $view_url = action([GoalController::class, 'show'], ['goal' => $goal]); + $response = $this->get($view_url); + $response->assertNotFound(); + } +}