mirror of https://github.com/kcal-app/kcal.git
Add Goal tests
This commit is contained in:
parent
a6c978981d
commit
38ca26291f
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<x-slot name="title">Delete Goal</x-slot>
|
||||
<x-slot name="header">
|
||||
<h1 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Delete {{ $goal->goal }} goal?
|
||||
Delete {{ $goal->summary }} goal?
|
||||
</h1>
|
||||
</x-slot>
|
||||
<form method="POST" action="{{ route('goals.destroy', $goal) }}">
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Controllers\GoalController;
|
||||
use App\Models\Goal;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\LoggedInTestCase;
|
||||
|
||||
class GoalTest extends LoggedInTestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function testCanLoadGoalIndex(): void
|
||||
{
|
||||
$index_url = action([GoalController::class, 'index']);
|
||||
$response = $this->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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue