forked from eatvio/eatvio-infra
210 lines
8.9 KiB
PHP
210 lines
8.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Product_Nutritional;
|
|
|
|
use App\Livewire\ProductNutritional\Create;
|
|
use App\Models\ProductNutritionalValue;
|
|
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 Illuminate\Http\Testing\File;
|
|
use App\Models\ProductGroup;
|
|
|
|
class CreateTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private File $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_group = ProductGroup::inRandomOrder()->first();
|
|
}
|
|
|
|
public function test_show_form_create_product(): void
|
|
{
|
|
$response = $this
|
|
->actingAs($this->user)
|
|
->get(route('product_nutritional_value.create'));
|
|
|
|
$response->assertSuccessful();
|
|
}
|
|
|
|
public function test_publish_new_product_success(): void
|
|
{
|
|
$this->actingAs($this->user);
|
|
|
|
$productCountAtStart = ProductNutritionalValue::count();
|
|
|
|
$testCase = Livewire::test(Create::class)
|
|
->set('name', $this->product->name)
|
|
->assertSet('name', $this->product->name)
|
|
->set('product_group', $this->product_group->id)
|
|
->assertSet('product_group', $this->product_group->id)
|
|
->set('image', $this->image)
|
|
->set('description', $this->product->description)
|
|
->assertSet('description', $this->product->description)
|
|
->set('formulations', $this->product->formulations)
|
|
->assertSet('formulations', $this->product->formulations)
|
|
->set('energy_on_100gr', $this->product->energy_on_100gr)
|
|
->assertSet('energy_on_100gr', $this->product->energy_on_100gr)
|
|
->set('proteins_on_100gr', $this->product->proteins_on_100gr)
|
|
->assertSet('proteins_on_100gr', $this->product->proteins_on_100gr)
|
|
->set('fats_on_100gr', $this->product->fats_on_100gr)
|
|
->assertSet('fats_on_100gr', $this->product->fats_on_100gr)
|
|
->set('carbohydrates_on_100gr', $this->product->carbohydrates_on_100gr)
|
|
->assertSet('carbohydrates_on_100gr', $this->product->carbohydrates_on_100gr)
|
|
->set('portion_mass_gr', $this->product->portion_mass_gr)
|
|
->assertSet('portion_mass_gr', $this->product->portion_mass_gr)
|
|
->set('energy_on_portion', $this->product->energy_on_portion)
|
|
->assertSet('energy_on_portion', $this->product->energy_on_portion)
|
|
->set('proteins_on_portion', $this->product->proteins_on_portion)
|
|
->assertSet('proteins_on_portion', $this->product->proteins_on_portion)
|
|
->set('fats_on_portion', $this->product->fats_on_portion)
|
|
->assertSet('fats_on_portion', $this->product->fats_on_portion)
|
|
->set('carbohydrates_on_portion', $this->product->carbohydrates_on_portion)
|
|
->assertSet('carbohydrates_on_portion', $this->product->carbohydrates_on_portion)
|
|
->call('save')
|
|
->assertSuccessful();
|
|
// ->assertHasNoErrors([]);
|
|
|
|
|
|
$this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count());
|
|
|
|
$lastCreatedProductNutritionalValue = ProductNutritionalValue::orderByDesc('id')->first();
|
|
|
|
$newProductNutritionalValueUrl = route('product_nutritional_value.index');
|
|
|
|
$testCase->assertRedirect($newProductNutritionalValueUrl);
|
|
|
|
Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image);
|
|
|
|
$response = $this->actingAs($this->user)->get(route('product_nutritional_value.index'));
|
|
|
|
$response->assertSuccessful();
|
|
}
|
|
}
|
|
|
|
// public function test_to_draft_new_product_success(): void
|
|
// {
|
|
// $this->actingAs($this->user);
|
|
//
|
|
// $productCountAtStart = ProductNutritionalValue::count();
|
|
//
|
|
// $testCase = Livewire::test(Create::class)
|
|
// ->set('name', $this->product->name)
|
|
// ->assertSet('name', $this->product->name)
|
|
// ->set('image', $this->image)
|
|
// ->set('duration', $this->product->duration)
|
|
// ->assertSet('duration', $this->product->duration)
|
|
// ->set('state', $this->product->state)
|
|
// ->assertSet('state', $this->product->state)
|
|
// ->set('type', $this->product->type)
|
|
// ->assertSet('type', $this->product->type)
|
|
// ->set('details', $this->product->details)
|
|
// ->assertSet('details', $this->product->details)
|
|
// ->set('packets_count', $this->product->packets_count)
|
|
// ->assertSet('packets_count', $this->product->packets_count)
|
|
// ->set('packet1_options', $this->product->packet1_options)
|
|
// ->assertSet('packet1_options', $this->product->packet1_options)
|
|
// ->set('packet2_options', $this->product->packet2_options)
|
|
// ->assertSet('packet2_options', $this->product->packet2_options)
|
|
// ->set('packet3_options', $this->product->packet3_options)
|
|
// ->assertSet('packet3_options', $this->product->packet3_options)
|
|
// ->call('addToDrafts')
|
|
// ->assertSuccessful()
|
|
// ->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
|
//
|
|
//
|
|
// $lastCreatedProductNutritionalValue = product::orderBy('id', 'desc')->first();
|
|
// $newProductNutritionalValueUrl = route('product.show', $lastCreatedproduct, false);
|
|
//
|
|
// Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image);
|
|
//
|
|
// $testCase->assertRedirect($newProductNutritionalValueUrl);
|
|
//
|
|
//
|
|
// $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count());
|
|
// }
|
|
//
|
|
// public function test_to_preview_new_product_success(): void
|
|
// {
|
|
// $this->actingAs($this->user);
|
|
//
|
|
// $productCountAtStart = ProductNutritionalValue::count();
|
|
//
|
|
//
|
|
// $testCase = Livewire::test(Create::class)
|
|
// ->set('name', $this->product->name)
|
|
// ->assertSet('name', $this->product->name)
|
|
// ->set('image', $this->image)
|
|
// ->set('duration', $this->product->duration)
|
|
// ->assertSet('duration', $this->product->duration)
|
|
// ->set('state', $this->product->state)
|
|
// ->assertSet('state', $this->product->state)
|
|
// ->set('type', $this->product->type)
|
|
// ->assertSet('type', $this->product->type)
|
|
// ->set('details', $this->product->details)
|
|
// ->assertSet('details', $this->product->details)
|
|
// ->set('packets_count', $this->product->packets_count)
|
|
// ->assertSet('packets_count', $this->product->packets_count)
|
|
// ->set('packet1_options', $this->product->packet1_options)
|
|
// ->assertSet('packet1_options', $this->product->packet1_options)
|
|
// ->set('packet2_options', $this->product->packet2_options)
|
|
// ->assertSet('packet2_options', $this->product->packet2_options)
|
|
// ->set('packet3_options', $this->product->packet3_options)
|
|
// ->assertSet('packet3_options', $this->product->packet3_options)
|
|
// ->call('showPreview')
|
|
// ->assertSuccessful()
|
|
// ->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
|
//
|
|
// $lastCreatedProductNutritionalValue = product::orderBy('id', 'desc')->first();
|
|
// $newProductNutritionalValueUrl = route('product.show', $lastCreatedproduct, false);
|
|
//
|
|
// Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image);
|
|
//
|
|
// $testCase->assertRedirect($newProductNutritionalValueUrl);
|
|
//
|
|
//
|
|
// $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count());
|
|
// }
|
|
//
|
|
// public function test_set_empty_data(): void
|
|
// {
|
|
// $this->actingAs($this->user);
|
|
//
|
|
// $productCountAtStart = ProductNutritionalValue::count();
|
|
//
|
|
// Livewire::test(Create::class)
|
|
// ->set('name', null)
|
|
// ->set('image', null)
|
|
// ->set('duration', null)
|
|
// ->set('state', null)
|
|
// ->set('type', null)
|
|
// ->set('details', null)
|
|
// ->set('packets_count', null)
|
|
// ->set('packet1_options', null)
|
|
// ->set('packet2_options', null)
|
|
// ->set('packet3_options', null)
|
|
// ->call('publish')
|
|
// ->assertHasErrors(['name', 'image', 'details']);
|
|
//
|
|
// $this->assertEquals($productCountAtStart, ProductNutritionalValue::count());
|
|
// }
|
|
// }
|