forked from eatvio/eatvio-infra
added create recipe test
This commit is contained in:
200
tests/Feature/Recipe/CreateTest.php
Normal file
200
tests/Feature/Recipe/CreateTest.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Recipe;
|
||||
|
||||
use App\Livewire\Recipe\Create;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CreateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
private Recipe $recipe;
|
||||
|
||||
private $image;
|
||||
|
||||
private $steps;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('recipes');
|
||||
|
||||
$this->image = UploadedFile::fake()->image('recipe.jpg');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->recipe = Recipe::factory()->make();
|
||||
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
}
|
||||
|
||||
public function testShowFormCreateRecipe(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('recipe.create'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function testPublishNewRecipeSuccess(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
->set('state', $this->recipe->state)
|
||||
->assertSet('state', $this->recipe->state)
|
||||
->set('cooking_time', $this->recipe->cooking_time)
|
||||
->assertSet('cooking_time', $this->recipe->cooking_time)
|
||||
->set('ingredients', $this->recipe->ingredients)
|
||||
->assertSet('ingredients', $this->recipe->ingredients)
|
||||
->set('type', $this->recipe->type)
|
||||
->assertSet('type', $this->recipe->type)
|
||||
->set('description', $this->recipe->description)
|
||||
->assertSet('description', $this->recipe->description)
|
||||
->set('video_url', $this->recipe->video_url)
|
||||
->assertSet('video_url', $this->recipe->video_url)
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
self::assertEquals($count + 1, Recipe::count());
|
||||
}
|
||||
|
||||
public function testToDraftNewRecipeSuccess(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
->set('state', $this->recipe->state)
|
||||
->assertSet('state', $this->recipe->state)
|
||||
->set('cooking_time', $this->recipe->cooking_time)
|
||||
->assertSet('cooking_time', $this->recipe->cooking_time)
|
||||
->set('ingredients', $this->recipe->ingredients)
|
||||
->assertSet('ingredients', $this->recipe->ingredients)
|
||||
->set('type', $this->recipe->type)
|
||||
->assertSet('type', $this->recipe->type)
|
||||
->set('description', $this->recipe->description)
|
||||
->assertSet('description', $this->recipe->description)
|
||||
->set('video_url', $this->recipe->video_url)
|
||||
->assertSet('video_url', $this->recipe->video_url)
|
||||
->call('draft')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
self::assertEquals($count + 1, Recipe::count());
|
||||
|
||||
self::assertEquals(Recipe::find($count + 1)->state, 'archived');
|
||||
}
|
||||
|
||||
public function testToPreviewNewRecipeSuccess(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
->set('state', $this->recipe->state)
|
||||
->assertSet('state', $this->recipe->state)
|
||||
->set('cooking_time', $this->recipe->cooking_time)
|
||||
->assertSet('cooking_time', $this->recipe->cooking_time)
|
||||
->set('ingredients', $this->recipe->ingredients)
|
||||
->assertSet('ingredients', $this->recipe->ingredients)
|
||||
->set('type', $this->recipe->type)
|
||||
->assertSet('type', $this->recipe->type)
|
||||
->set('description', $this->recipe->description)
|
||||
->assertSet('description', $this->recipe->description)
|
||||
->set('video_url', $this->recipe->video_url)
|
||||
->assertSet('video_url', $this->recipe->video_url)
|
||||
->call('preview')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
self::assertEquals($count + 1, Recipe::count());
|
||||
|
||||
self::assertEquals(Recipe::find($count + 1)->state, 'archived');
|
||||
}
|
||||
|
||||
public function testSetEmptyData(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', null)
|
||||
->set('state', null)
|
||||
->set('cooking_time', null)
|
||||
->set('type', null)
|
||||
->set('description', null)
|
||||
->call('publish')
|
||||
->assertHasErrors(['image', 'state', 'type', 'description']);
|
||||
|
||||
// doesnt to add to database
|
||||
self::assertEquals($count, Recipe::count());
|
||||
}
|
||||
|
||||
public function testIncorrectVideoUrl(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
->set('state', $this->recipe->state)
|
||||
->assertSet('state', $this->recipe->state)
|
||||
->set('cooking_time', $this->recipe->cooking_time)
|
||||
->assertSet('cooking_time', $this->recipe->cooking_time)
|
||||
->set('ingredients', $this->recipe->ingredients)
|
||||
->assertSet('ingredients', $this->recipe->ingredients)
|
||||
->set('type', $this->recipe->type)
|
||||
->assertSet('type', $this->recipe->type)
|
||||
->set('description', $this->recipe->description)
|
||||
->assertSet('description', $this->recipe->description)
|
||||
->set('video_url', 'video_url')
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasErrors(['video_url']);
|
||||
|
||||
// doesnt to add to database
|
||||
self::assertEquals($count, Recipe::count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user