mirror of https://github.com/kcal-app/kcal.git
Add basic Journal Entry controller tests
This commit is contained in:
parent
0e70b0d475
commit
a686e8036b
|
@ -248,20 +248,21 @@ class JournalEntryController extends Controller
|
|||
/**
|
||||
* Confirm removal of the specified resource.
|
||||
*/
|
||||
public function delete(JournalEntry $journalEntry): View
|
||||
public function delete(JournalEntry $journal_entry): View
|
||||
{
|
||||
return view('journal-entries.delete')->with('entry', $journalEntry);
|
||||
return view('journal-entries.delete')
|
||||
->with('journal_entry', $journal_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(JournalEntry $journalEntry): RedirectResponse
|
||||
public function destroy(JournalEntry $journal_entry): RedirectResponse
|
||||
{
|
||||
$journalEntry->delete();
|
||||
$journal_entry->delete();
|
||||
session()->flash('message', 'Journal entry deleted!');
|
||||
return redirect(route('journal-entries.index', [
|
||||
'date' => $journalEntry->date->toDateString()
|
||||
'date' => $journal_entry->date->toDateString()
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,25 +2,25 @@
|
|||
<x-slot name="title">Delete Entry</x-slot>
|
||||
<x-slot name="header">
|
||||
<h1 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Delete {{ $entry->summary }}?
|
||||
Delete {{ $journal_entry->summary }}?
|
||||
</h1>
|
||||
</x-slot>
|
||||
<form method="POST" action="{{ route('journal-entries.destroy', $entry) }}">
|
||||
<form method="POST" action="{{ route('journal-entries.destroy', $journal_entry) }}">
|
||||
@method('delete')
|
||||
@csrf
|
||||
<div class="text-lg">Are you sure what to delete this journal entry?</div>
|
||||
<div class="flex flex-col space-y-2 mt-4 mb-4 text-lg">
|
||||
<div>
|
||||
<span class="font-bold">Summay:</span>
|
||||
<span>{{ $entry->summary }}</span>
|
||||
<span>{{ $journal_entry->summary }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="font-bold">Date:</span>
|
||||
<span>{{ $entry->date->format('D, j M Y') }}</span>
|
||||
<span>{{ $journal_entry->date->format('D, j M Y') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="font-bold">Meal:</span>
|
||||
<span>{{ $entry->meal }}</span>
|
||||
<span>{{ $journal_entry->meal }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<x-inputs.button class="bg-red-800 hover:bg-red-700">
|
||||
|
|
|
@ -39,7 +39,7 @@ Route::get('/ingredient-picker/search', [IngredientPickerController::class, 'sea
|
|||
Route::get('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'createFromNutrients'])->middleware(['auth'])->name('journal-entries.create.from-nutrients');
|
||||
Route::post('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'storeFromNutrients'])->middleware(['auth'])->name('journal-entries.store.from-nutrients');
|
||||
Route::resource('journal-entries', JournalEntryController::class)->middleware(['auth']);
|
||||
Route::get('/journal-entries/{journalEntry}/delete', [JournalEntryController::class, 'delete'])->middleware(['auth'])->name('journal-entries.delete');
|
||||
Route::get('/journal-entries/{journal_entry}/delete', [JournalEntryController::class, 'delete'])->middleware(['auth'])->name('journal-entries.delete');
|
||||
|
||||
// Recipes.
|
||||
Route::resource('recipes', RecipeController::class)->middleware(['auth']);
|
||||
|
|
|
@ -48,7 +48,6 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
|||
$response = $this->followingRedirects()->post($store_url, $instance->toArray());
|
||||
$response->assertOk();
|
||||
$response->assertSessionHasNoErrors();
|
||||
$response->assertViewHas($this->routeKey());
|
||||
}
|
||||
|
||||
public function testCanViewInstance(): void
|
||||
|
@ -87,9 +86,7 @@ abstract class HttpControllerTestCase extends LoggedInTestCase
|
|||
$response = $this->followingRedirects()->delete($destroy_url);
|
||||
$response->assertOk();
|
||||
|
||||
$view_url = action([$this->class(), 'show'], [$this->routeKey() => $instance]);
|
||||
$response = $this->get($view_url);
|
||||
$response->assertNotFound();
|
||||
$this->assertNull($instance->fresh());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\GoalController;
|
||||
use App\Http\Controllers\JournalEntryController;
|
||||
use App\Models\Goal;
|
||||
use App\Models\JournalEntry;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class JournalEntryControllerTest extends HttpControllerTestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function class(): string
|
||||
{
|
||||
return JournalEntryController::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function factory(): Factory
|
||||
{
|
||||
return JournalEntry::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function routeKey(): string
|
||||
{
|
||||
return 'journal_entry';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function createInstance(): Model
|
||||
{
|
||||
return $this->factory()->for($this->user)->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testCanViewInstance(): void {
|
||||
$this->setName('can *not* view instance');
|
||||
// Journal entries are not independently viewable.
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testCanEditInstance(): void {
|
||||
$this->setName('can *not* edit instance');
|
||||
// Journal entries are not editable.
|
||||
}
|
||||
|
||||
public function testCanAddInstance(): void
|
||||
{
|
||||
$create_url = action([$this->class(), 'createFromNutrients']);
|
||||
$response = $this->get($create_url);
|
||||
$response->assertOk();
|
||||
$instance = $this->factory()->make();
|
||||
$store_url = action([$this->class(), 'storeFromNutrients']);
|
||||
$response = $this->followingRedirects()->post($store_url, $instance->toArray());
|
||||
$response->assertOk();
|
||||
$response->assertSessionHasNoErrors();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue