forked from eatvio/eatvio-infra
106 lines
4.7 KiB
PHP
106 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Product_Nutritional;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
use App\Livewire\ProductNutritional\Edit;
|
|
use App\Models\ProductNutritionalValue;
|
|
use App\Models\ProductGroup;
|
|
|
|
class EditTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private UploadedFile $image;
|
|
|
|
private ProductNutritionalValue $product;
|
|
private ProductGroup $product_group;
|
|
|
|
protected User $user;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->refreshApplicationWithLocale('en');
|
|
|
|
Storage::fake('tmp-for-tests');
|
|
|
|
$this->image = UploadedFile::fake()->image('product.png');
|
|
|
|
$this->user = User::factory()->create(['is_consultant' => true]);
|
|
|
|
$this->product = ProductNutritionalValue::factory()->make();
|
|
$this->product->product_group()->associate($product_group = ProductGroup::inRandomOrder()->first());
|
|
$this->product->saveOrFail();
|
|
|
|
$this->product_group = $product_group;
|
|
}
|
|
|
|
public function test_show_form_edit_product(): void
|
|
{
|
|
$response = $this
|
|
->actingAs($this->user)
|
|
->get(route('product_nutritional_value.edit', $this->product));
|
|
|
|
$response->assertSuccessful();
|
|
}
|
|
|
|
public function test_publish_new_product_success(): void
|
|
{
|
|
$this->actingAs($this->user);
|
|
|
|
$updatedProductBeforeToAddDatabase = ProductNutritionalValue::factory()->make();
|
|
|
|
$testCase = Livewire::test(Edit::class, [
|
|
'product' => $this->product,
|
|
])
|
|
->set('name', $updatedProductBeforeToAddDatabase->name)
|
|
->assertSet('name', $updatedProductBeforeToAddDatabase->name)
|
|
->set('product_group', $this->product_group->id)
|
|
->assertSet('product_group', $this->product_group->id)
|
|
->set('image', $this->image)
|
|
->set('description', $updatedProductBeforeToAddDatabase->description)
|
|
->assertSet('description', $updatedProductBeforeToAddDatabase->description)
|
|
->set('formulations', $updatedProductBeforeToAddDatabase->formulations)
|
|
->assertSet('formulations', $updatedProductBeforeToAddDatabase->formulations)
|
|
->set('energy_on_100gr', $updatedProductBeforeToAddDatabase->energy_on_100gr)
|
|
->assertSet('energy_on_100gr', $updatedProductBeforeToAddDatabase->energy_on_100gr)
|
|
->set('proteins_on_100gr', $updatedProductBeforeToAddDatabase->proteins_on_100gr)
|
|
->assertSet('proteins_on_100gr', $updatedProductBeforeToAddDatabase->proteins_on_100gr)
|
|
->set('fats_on_100gr', $updatedProductBeforeToAddDatabase->fats_on_100gr)
|
|
->assertSet('fats_on_100gr', $updatedProductBeforeToAddDatabase->fats_on_100gr)
|
|
->set('carbohydrates_on_100gr', $updatedProductBeforeToAddDatabase->carbohydrates_on_100gr)
|
|
->assertSet('carbohydrates_on_100gr', $updatedProductBeforeToAddDatabase->carbohydrates_on_100gr)
|
|
->set('portion_mass_gr', $updatedProductBeforeToAddDatabase->portion_mass_gr)
|
|
->assertSet('portion_mass_gr', $updatedProductBeforeToAddDatabase->portion_mass_gr)
|
|
->set('energy_on_portion', $updatedProductBeforeToAddDatabase->energy_on_portion)
|
|
->assertSet('energy_on_portion', $updatedProductBeforeToAddDatabase->energy_on_portion)
|
|
->set('proteins_on_portion', $updatedProductBeforeToAddDatabase->proteins_on_portion)
|
|
->assertSet('proteins_on_portion', $updatedProductBeforeToAddDatabase->proteins_on_portion)
|
|
->set('fats_on_portion', $updatedProductBeforeToAddDatabase->fats_on_portion)
|
|
->assertSet('fats_on_portion', $updatedProductBeforeToAddDatabase->fats_on_portion)
|
|
->set('carbohydrates_on_portion', $updatedProductBeforeToAddDatabase->carbohydrates_on_portion)
|
|
->assertSet('carbohydrates_on_portion', $updatedProductBeforeToAddDatabase->carbohydrates_on_portion)
|
|
->call('save')
|
|
->assertSuccessful();
|
|
|
|
$updatedProductAfterToAddDatabase = ProductNutritionalValue::orderByDesc('id')->first();
|
|
|
|
$newproductUrl = route('product_nutritional_value.index');
|
|
|
|
Storage::disk('tmp-for-tests')->assertExists($updatedProductAfterToAddDatabase->image);
|
|
|
|
|
|
// check data after update recipe
|
|
self::assertEquals($updatedProductBeforeToAddDatabase->name, $updatedProductAfterToAddDatabase->name);
|
|
self::assertEquals($updatedProductBeforeToAddDatabase->description, $updatedProductAfterToAddDatabase->description);
|
|
self::assertEquals($updatedProductBeforeToAddDatabase->formulations, $updatedProductAfterToAddDatabase->formulations);
|
|
|
|
$testCase->assertRedirect($newproductUrl);
|
|
}
|
|
}
|