mirror of https://github.com/kcal-app/kcal.git
Add ingredients-based journal entries test
This commit is contained in:
parent
29638c711f
commit
5c57af5951
|
|
@ -3,14 +3,16 @@
|
||||||
namespace Tests\Feature\Http\Controllers;
|
namespace Tests\Feature\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Controllers\JournalEntryController;
|
use App\Http\Controllers\JournalEntryController;
|
||||||
|
use App\Models\IngredientAmount;
|
||||||
use App\Models\JournalEntry;
|
use App\Models\JournalEntry;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
|
||||||
class JournalEntryControllerTest extends HttpControllerTestCase
|
class JournalEntryControllerTest extends HttpControllerTestCase
|
||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase, WithFaker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
|
@ -47,7 +49,8 @@ class JournalEntryControllerTest extends HttpControllerTestCase
|
||||||
/**
|
/**
|
||||||
* @doesNotPerformAssertions
|
* @doesNotPerformAssertions
|
||||||
*/
|
*/
|
||||||
public function testCanViewInstance(): void {
|
public function testCanViewInstance(): void
|
||||||
|
{
|
||||||
$this->setName('can *not* view instance');
|
$this->setName('can *not* view instance');
|
||||||
// Journal entries are not independently viewable.
|
// Journal entries are not independently viewable.
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +58,8 @@ class JournalEntryControllerTest extends HttpControllerTestCase
|
||||||
/**
|
/**
|
||||||
* @doesNotPerformAssertions
|
* @doesNotPerformAssertions
|
||||||
*/
|
*/
|
||||||
public function testCanEditInstance(): void {
|
public function testCanEditInstance(): void
|
||||||
|
{
|
||||||
$this->setName('can *not* edit instance');
|
$this->setName('can *not* edit instance');
|
||||||
// Journal entries are not editable.
|
// Journal entries are not editable.
|
||||||
}
|
}
|
||||||
|
|
@ -65,10 +69,45 @@ class JournalEntryControllerTest extends HttpControllerTestCase
|
||||||
$create_url = action([$this->class(), 'createFromNutrients']);
|
$create_url = action([$this->class(), 'createFromNutrients']);
|
||||||
$response = $this->get($create_url);
|
$response = $this->get($create_url);
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
|
|
||||||
$instance = $this->factory()->make();
|
$instance = $this->factory()->make();
|
||||||
$store_url = action([$this->class(), 'storeFromNutrients']);
|
$store_url = action([$this->class(), 'storeFromNutrients']);
|
||||||
$response = $this->post($store_url, $instance->toArray());
|
$response = $this->post($store_url, $instance->toArray());
|
||||||
$response->assertSessionHasNoErrors();
|
$response->assertSessionHasNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanAddInstanceFromIngredients(): void
|
||||||
|
{
|
||||||
|
$create_url = action([$this->class(), 'create']);
|
||||||
|
$response = $this->get($create_url);
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
// Create ingredients based on ingredient amounts.
|
||||||
|
$ingredients = [
|
||||||
|
'date' => [], 'meal' => [], 'amount' => [], 'unit' => [],
|
||||||
|
'id' => [], 'type' => [],
|
||||||
|
];
|
||||||
|
/** @var \App\Models\IngredientAmount[] $ingredient_amounts */
|
||||||
|
$ingredient_amounts = IngredientAmount::factory()
|
||||||
|
->count(10)
|
||||||
|
->make(['parent_id' => null, 'parent_type' => null]);
|
||||||
|
foreach ($ingredient_amounts as $ingredient_amount) {
|
||||||
|
$ingredients['date'][] = $this->faker->dateTimeThisMonth;
|
||||||
|
$ingredients['meal'][] = $this->faker->randomElement(JournalEntry::meals()->pluck('value')->toArray());
|
||||||
|
$ingredients['amount'][] = $ingredient_amount->amount;
|
||||||
|
$ingredients['unit'][] = $ingredient_amount->unit;
|
||||||
|
$ingredients['id'][] = $ingredient_amount->ingredient->id;
|
||||||
|
$ingredients['type'][] = $ingredient_amount->ingredient->type;
|
||||||
|
}
|
||||||
|
$data = ['ingredients' => $ingredients, 'group_entries' => true];
|
||||||
|
$store_url = action([$this->class(), 'store']);
|
||||||
|
$response = $this->post($store_url, $data);
|
||||||
|
$response->assertSessionHasNoErrors();
|
||||||
|
|
||||||
|
$data['group_entries'] = false;
|
||||||
|
$store_url = action([$this->class(), 'store']);
|
||||||
|
$response = $this->post($store_url, $data);
|
||||||
|
$response->assertSessionHasNoErrors();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue