mirror of https://github.com/kcal-app/kcal.git
Add basic meals edit test
This commit is contained in:
parent
7d6f0ec538
commit
2e852f4df0
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\MealsController;
|
||||||
|
use Tests\LoggedInTestCase;
|
||||||
|
|
||||||
|
class MealsControllerTest extends LoggedInTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test editing meals.
|
||||||
|
*/
|
||||||
|
public function testCanEditMeals(): void
|
||||||
|
{
|
||||||
|
$edit_url = action([MealsController::class, 'edit']);
|
||||||
|
$response = $this->get($edit_url);
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$meal_data = [];
|
||||||
|
$this->user->meals->each(function (array $meal) use (&$meal_data) {
|
||||||
|
$meal_data['value'][] = $meal['value'];
|
||||||
|
$meal_data['weight'][] = $meal['weight'];
|
||||||
|
$meal_data['label'][] = "Updated {$meal['label']}";
|
||||||
|
$meal_data['enabled'][] = $meal['enabled'] ?? false;
|
||||||
|
});
|
||||||
|
$put_url = action([MealsController::class, 'update']);
|
||||||
|
$response = $this->put($put_url, ['meal' => $meal_data]);
|
||||||
|
$response->assertSessionHasNoErrors();
|
||||||
|
|
||||||
|
$this->user->refresh();
|
||||||
|
$this->user->meals->each(function (array $meal) {
|
||||||
|
$this->assertStringStartsWith('Updated', $meal['label']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue