forked from eatvio/eatvio-infra
Merge pull request 'main' (#11) from eatvio/eatvio:main into main
Reviewed-on: apoloz/eatvio#11
This commit is contained in:
@@ -128,7 +128,7 @@ class Create extends Component
|
||||
$plan = new Plan();
|
||||
|
||||
$plan->name = $this->name;
|
||||
$plan->image = $this->image->store('plans', 'public');
|
||||
$plan->image = $this->image->store('plans');
|
||||
$plan->duration = $this->duration;
|
||||
$plan->state = $this->state;
|
||||
$plan->details = $this->details;
|
||||
@@ -143,7 +143,7 @@ class Create extends Component
|
||||
$user = Auth::user();
|
||||
$user->author_of_plans()->attach($plan->id);
|
||||
|
||||
return redirect()->route('plan.show', $plan->slug);
|
||||
$this->redirectRoute('plan.show', $plan);
|
||||
}
|
||||
|
||||
public function addToDrafts()
|
||||
|
||||
@@ -171,7 +171,7 @@ class Edit extends Component
|
||||
$this->validate();
|
||||
|
||||
$this->plan->name = $this->name;
|
||||
$this->plan->image = ! is_string($this->image) ? $this->image->store('plans', 'public') : $this->image;
|
||||
$this->plan->image = ! is_string($this->image) ? $this->image->store('plans') : $this->image;
|
||||
$this->plan->duration = $this->duration;
|
||||
$this->plan->state = $this->state;
|
||||
$this->plan->details = $this->details;
|
||||
@@ -186,7 +186,7 @@ class Edit extends Component
|
||||
// $user = Auth::user();
|
||||
// $user->author_of_plans()->attach($plan->id);
|
||||
|
||||
return redirect()->route('plan.show', $this->plan->slug);
|
||||
$this->redirectRoute('plan.show', $this->plan);
|
||||
}
|
||||
|
||||
public function addToDrafts()
|
||||
|
||||
@@ -140,7 +140,7 @@ class Create extends Component
|
||||
$this->validate();
|
||||
|
||||
$recipe = new Recipe();
|
||||
$recipe->image = $this->image->store('recipe', 'public');
|
||||
$recipe->image = $this->image->store('recipe');
|
||||
$recipe->state = $this->state;
|
||||
$recipe->type = $this->type;
|
||||
$recipe->cooking_time = $this->cooking_time;
|
||||
@@ -157,7 +157,7 @@ class Create extends Component
|
||||
$user = Auth::user();
|
||||
$user->author_of_recipe()->attach($recipe->id);
|
||||
|
||||
return redirect()->route('recipe.show', $recipe->id);
|
||||
$this->redirectRoute('recipe.show', $recipe);
|
||||
}
|
||||
|
||||
private function transformSteps($steps)
|
||||
|
||||
@@ -153,7 +153,7 @@ class Edit extends Component
|
||||
|
||||
$recipe = $this->recipe;
|
||||
if (! is_string($this->image)) {
|
||||
$recipe->image = $this->image->store('recipe', 'public');
|
||||
$recipe->image = $this->image->store('recipe');
|
||||
}
|
||||
|
||||
$recipe->state = $this->state;
|
||||
@@ -167,7 +167,7 @@ class Edit extends Component
|
||||
|
||||
$recipe->save();
|
||||
|
||||
return redirect()->route('recipe.show', $recipe->id);
|
||||
$this->redirectRoute('recipe.show', $recipe);
|
||||
}
|
||||
|
||||
private function transformSteps($steps)
|
||||
|
||||
@@ -26,7 +26,7 @@ class CreateTest extends TestCase
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('plans');
|
||||
Storage::fake('tmp-for-tests');
|
||||
$this->image = UploadedFile::fake()->image('plan.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
@@ -47,10 +47,9 @@ class CreateTest extends TestCase
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
// $this->assertEquals($this->plan->count(), $count = Plan::count());
|
||||
$planCountAtStart = Plan::count();
|
||||
|
||||
Livewire::test(Create::class)
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->plan->name)
|
||||
->assertSet('name', $this->plan->name)
|
||||
->set('image', $this->image)
|
||||
@@ -74,15 +73,20 @@ class CreateTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->plan->image);
|
||||
|
||||
$lastCreatedPlan = Plan::orderBy('id', 'desc')->first();
|
||||
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan, false);
|
||||
|
||||
$testCase->assertRedirect($newPlanUrl);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image);
|
||||
|
||||
$this->assertEquals($planCountAtStart + 1, Plan::count());
|
||||
|
||||
$response = $this->actingAs($this->user)->get(route('plan.index'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
|
||||
// $this->assertEquals($count + 1, Plan::count());
|
||||
}
|
||||
|
||||
public function test_to_draft_new_plan_success(): void
|
||||
@@ -91,10 +95,7 @@ class CreateTest extends TestCase
|
||||
|
||||
$planCountAtStart = Plan::count();
|
||||
|
||||
// $planLastId = $this->plan->latest()->first()->id;
|
||||
// $expectedRedirectRoute = route('plan.show', ['plan' => $planLastId + 1]);
|
||||
|
||||
Livewire::test(Create::class)
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->plan->name)
|
||||
->assertSet('name', $this->plan->name)
|
||||
->set('image', $this->image)
|
||||
@@ -115,10 +116,17 @@ class CreateTest extends TestCase
|
||||
->set('packet3_options', $this->plan->packet3_options)
|
||||
->assertSet('packet3_options', $this->plan->packet3_options)
|
||||
->call('addToDrafts')
|
||||
->assertRedirect()
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->plan->image);
|
||||
|
||||
$lastCreatedPlan = Plan::orderBy('id', 'desc')->first();
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image);
|
||||
|
||||
$testCase->assertRedirect($newPlanUrl);
|
||||
|
||||
|
||||
$this->assertEquals($planCountAtStart + 1, Plan::count());
|
||||
}
|
||||
@@ -129,7 +137,7 @@ class CreateTest extends TestCase
|
||||
|
||||
$planCountAtStart = Plan::count();
|
||||
|
||||
Livewire::test(Create::class)
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->plan->name)
|
||||
->assertSet('name', $this->plan->name)
|
||||
->set('image', $this->image)
|
||||
@@ -153,7 +161,13 @@ class CreateTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->plan->image);
|
||||
$lastCreatedPlan = Plan::orderBy('id', 'desc')->first();
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image);
|
||||
|
||||
$testCase->assertRedirect($newPlanUrl);
|
||||
|
||||
|
||||
$this->assertEquals($planCountAtStart + 1, Plan::count());
|
||||
}
|
||||
|
||||
232
tests/Feature/Plan/EditTest.php
Normal file
232
tests/Feature/Plan/EditTest.php
Normal file
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Plan;
|
||||
|
||||
use App\Models\Plan;
|
||||
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\Plan\Edit;
|
||||
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private $image;
|
||||
|
||||
private Plan $plan;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('tmp-for-tests');
|
||||
$this->image = UploadedFile::fake()->image('plan.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->plan = Plan::factory()->create();
|
||||
}
|
||||
|
||||
public function test_show_form_edit_plan()
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('plan.edit', $this->plan));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_publish_new_plan_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedPlanBeforeToAddDatabase = Plan::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'plan' => $this->plan,
|
||||
])
|
||||
->set('name', $updatedPlanBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedPlanBeforeToAddDatabase->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $updatedPlanBeforeToAddDatabase->duration)
|
||||
->assertSet('duration', $updatedPlanBeforeToAddDatabase->duration)
|
||||
->set('state', $updatedPlanBeforeToAddDatabase->state)
|
||||
->assertSet('state', $updatedPlanBeforeToAddDatabase->state)
|
||||
->set('type', $updatedPlanBeforeToAddDatabase->type)
|
||||
->assertSet('type', $updatedPlanBeforeToAddDatabase->type)
|
||||
->set('details', $updatedPlanBeforeToAddDatabase->details)
|
||||
->assertSet('details', $updatedPlanBeforeToAddDatabase->details)
|
||||
->set('packets_count', $updatedPlanBeforeToAddDatabase->packets_count)
|
||||
->assertSet('packets_count', $updatedPlanBeforeToAddDatabase->packets_count)
|
||||
->set('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options)
|
||||
->assertSet('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options)
|
||||
->set('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options)
|
||||
->assertSet('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options)
|
||||
->set('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options)
|
||||
->assertSet('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options)
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']);
|
||||
|
||||
$updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first();
|
||||
|
||||
$newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image);
|
||||
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->name, $updatedPlanAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->duration, $updatedPlanAfterToAddDatabase->duration);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->state, $updatedPlanAfterToAddDatabase->state);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->type, $updatedPlanAfterToAddDatabase->type);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->details, $updatedPlanAfterToAddDatabase->details);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packets_count, $updatedPlanAfterToAddDatabase->packets_count);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet1_options, $updatedPlanAfterToAddDatabase->packet1_options);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet2_options, $updatedPlanAfterToAddDatabase->packet2_options);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet3_options, $updatedPlanAfterToAddDatabase->packet3_options);
|
||||
|
||||
$testCase->assertRedirect($newPlanUrl);
|
||||
|
||||
}
|
||||
|
||||
public function test_to_draft_new_plan_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedPlanBeforeToAddDatabase = Plan::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'plan' => $this->plan,
|
||||
])
|
||||
->set('name', $updatedPlanBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedPlanBeforeToAddDatabase->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $updatedPlanBeforeToAddDatabase->duration)
|
||||
->assertSet('duration', $updatedPlanBeforeToAddDatabase->duration)
|
||||
->set('state', $updatedPlanBeforeToAddDatabase->state)
|
||||
->assertSet('state', $updatedPlanBeforeToAddDatabase->state)
|
||||
->set('type', $updatedPlanBeforeToAddDatabase->type)
|
||||
->assertSet('type', $updatedPlanBeforeToAddDatabase->type)
|
||||
->set('details', $updatedPlanBeforeToAddDatabase->details)
|
||||
->assertSet('details', $updatedPlanBeforeToAddDatabase->details)
|
||||
->set('packets_count', $updatedPlanBeforeToAddDatabase->packets_count)
|
||||
->assertSet('packets_count', $updatedPlanBeforeToAddDatabase->packets_count)
|
||||
->set('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options)
|
||||
->assertSet('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options)
|
||||
->set('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options)
|
||||
->assertSet('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options)
|
||||
->set('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options)
|
||||
->assertSet('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options)
|
||||
->call('addToDrafts')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']);
|
||||
|
||||
$updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first();
|
||||
|
||||
$newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->name, $updatedPlanAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->duration, $updatedPlanAfterToAddDatabase->duration);
|
||||
self::assertEquals('draft', $updatedPlanAfterToAddDatabase->state);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->type, $updatedPlanAfterToAddDatabase->type);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->details, $updatedPlanAfterToAddDatabase->details);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packets_count, $updatedPlanAfterToAddDatabase->packets_count);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet1_options, $updatedPlanAfterToAddDatabase->packet1_options);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet2_options, $updatedPlanAfterToAddDatabase->packet2_options);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet3_options, $updatedPlanAfterToAddDatabase->packet3_options);
|
||||
|
||||
$testCase->assertRedirect($newPlanUrl);
|
||||
}
|
||||
|
||||
public function test_to_preview_new_plan_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedPlanBeforeToAddDatabase = Plan::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'plan' => $this->plan,
|
||||
])
|
||||
->set('name', $updatedPlanBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedPlanBeforeToAddDatabase->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $updatedPlanBeforeToAddDatabase->duration)
|
||||
->assertSet('duration', $updatedPlanBeforeToAddDatabase->duration)
|
||||
->set('state', $updatedPlanBeforeToAddDatabase->state)
|
||||
->assertSet('state', $updatedPlanBeforeToAddDatabase->state)
|
||||
->set('type', $updatedPlanBeforeToAddDatabase->type)
|
||||
->assertSet('type', $updatedPlanBeforeToAddDatabase->type)
|
||||
->set('details', $updatedPlanBeforeToAddDatabase->details)
|
||||
->assertSet('details', $updatedPlanBeforeToAddDatabase->details)
|
||||
->set('packets_count', $updatedPlanBeforeToAddDatabase->packets_count)
|
||||
->assertSet('packets_count', $updatedPlanBeforeToAddDatabase->packets_count)
|
||||
->set('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options)
|
||||
->assertSet('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options)
|
||||
->set('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options)
|
||||
->assertSet('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options)
|
||||
->set('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options)
|
||||
->assertSet('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options)
|
||||
->call('showPreview')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']);
|
||||
|
||||
$updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first();
|
||||
|
||||
$newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->name, $updatedPlanAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->duration, $updatedPlanAfterToAddDatabase->duration);
|
||||
self::assertEquals('unactive', $updatedPlanAfterToAddDatabase->state);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->type, $updatedPlanAfterToAddDatabase->type);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->details, $updatedPlanAfterToAddDatabase->details);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packets_count, $updatedPlanAfterToAddDatabase->packets_count);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet1_options, $updatedPlanAfterToAddDatabase->packet1_options);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet2_options, $updatedPlanAfterToAddDatabase->packet2_options);
|
||||
self::assertEquals($updatedPlanBeforeToAddDatabase->packet3_options, $updatedPlanAfterToAddDatabase->packet3_options);
|
||||
|
||||
$testCase->assertRedirect($newPlanUrl);
|
||||
}
|
||||
|
||||
public function testNothingChange(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$planUpdate = Livewire::test(Edit::class, [
|
||||
'plan' => $this->plan,
|
||||
])
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
$newPlanUrl = route('plan.show', $this->plan, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertMissing($planUpdate->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($this->plan->name, $planUpdate->name);
|
||||
self::assertEquals($this->plan->duration, $planUpdate->duration);
|
||||
self::assertEquals($this->plan->state, $planUpdate->state);
|
||||
self::assertEquals($this->plan->type, $planUpdate->type);
|
||||
self::assertEquals($this->plan->details, $planUpdate->details);
|
||||
self::assertEquals($this->plan->packets_count, $planUpdate->packets_count);
|
||||
self::assertIsArray($planUpdate->packet1_options);
|
||||
self::assertIsArray($planUpdate->packet2_options);
|
||||
self::assertIsArray($planUpdate->packet3_options);
|
||||
|
||||
$planUpdate->assertRedirect($newPlanUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
tests/Feature/Plan/IndexTest.php
Normal file
35
tests/Feature/Plan/IndexTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Plan;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private $plan;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->plan = Plan::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_index_page_success()
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('plan.index'));
|
||||
|
||||
$response
|
||||
->assertOk();
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace Tests\Feature\Plan;
|
||||
|
||||
use App\Livewire\Plan\Create;
|
||||
use App\Models\Plan;
|
||||
// use Livewire\WithFileUploads;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
// use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
@@ -18,8 +14,6 @@ class ShowTest extends TestCase
|
||||
// use RefreshDatabase;
|
||||
use RefreshDatabase;
|
||||
|
||||
private $image;
|
||||
|
||||
private $plan;
|
||||
|
||||
protected User $user;
|
||||
@@ -28,9 +22,6 @@ class ShowTest extends TestCase
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('plans');
|
||||
$this->image = UploadedFile::fake()->image('plan.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->plan = Plan::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Recipe;
|
||||
|
||||
@@ -32,7 +30,7 @@ final class CreateTest extends TestCase
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('recipes');
|
||||
Storage::fake('tmp-for-tests');
|
||||
|
||||
$this->image = UploadedFile::fake()->image('recipe.jpg');
|
||||
|
||||
@@ -55,7 +53,7 @@ final class CreateTest extends TestCase
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
@@ -75,7 +73,13 @@ final class CreateTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
$lastCreatedRecipe = Recipe::orderByDesc('id')->first();
|
||||
|
||||
$newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
|
||||
|
||||
$testCase->assertRedirect($newRecipeUrl);
|
||||
|
||||
self::assertEquals($count + 1, Recipe::count());
|
||||
}
|
||||
@@ -86,7 +90,7 @@ final class CreateTest extends TestCase
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
@@ -106,7 +110,13 @@ final class CreateTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
$lastCreatedRecipe = Recipe::orderByDesc('id')->first();
|
||||
|
||||
$newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
|
||||
|
||||
$testCase->assertRedirect($newRecipeUrl);
|
||||
|
||||
self::assertEquals($count + 1, Recipe::count());
|
||||
|
||||
@@ -119,7 +129,7 @@ final class CreateTest extends TestCase
|
||||
|
||||
self::assertEquals($this->recipe->count(), $count = Recipe::count());
|
||||
|
||||
Livewire::test(Create::class)
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('title', $this->recipe->title)
|
||||
->assertSet('title', $this->recipe->title)
|
||||
->set('image', $this->image)
|
||||
@@ -139,7 +149,13 @@ final class CreateTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
$lastCreatedRecipe = Recipe::orderByDesc('id')->first();
|
||||
|
||||
$newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
|
||||
|
||||
$testCase->assertRedirect($newRecipeUrl);
|
||||
|
||||
self::assertEquals($count + 1, Recipe::count());
|
||||
|
||||
@@ -196,4 +212,3 @@ final class CreateTest extends TestCase
|
||||
self::assertEquals($count, Recipe::count());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -21,12 +22,18 @@ final class EditTest extends TestCase
|
||||
|
||||
private Recipe $recipe;
|
||||
|
||||
private UploadedFile $image;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
|
||||
Storage::fake('tmp-for-tests');
|
||||
|
||||
$this->image = UploadedFile::fake()->image('recipe.jpg');
|
||||
|
||||
$this->recipe = Recipe::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
@@ -50,7 +57,7 @@ final class EditTest extends TestCase
|
||||
])
|
||||
->set('title', $recipe->title)
|
||||
->assertSet('title', $recipe->title)
|
||||
->set('image', $recipe->image)
|
||||
->set('image', $this->image)
|
||||
->set('state', $recipe->state)
|
||||
->assertSet('state', $recipe->state)
|
||||
->set('cooking_time', $recipe->cooking_time)
|
||||
@@ -67,17 +74,23 @@ final class EditTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
$recipeCreatedLast = Recipe::orderByDesc('id')->first();
|
||||
$newRecipeUrl = route('recipe.show', $recipeCreatedLast, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($recipeCreatedLast->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals($recipe->state, $recipeUpdate->state);
|
||||
self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($recipe->video_url, $recipeUpdate->video_url);
|
||||
|
||||
$recipeUpdate->assertRedirect($newRecipeUrl);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,17 +122,21 @@ final class EditTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
$recipeCreatedLast = Recipe::orderByDesc('id')->first();
|
||||
$newRecipeUrl = route('recipe.show', $recipeCreatedLast, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($recipeCreatedLast->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals('archived', $recipeUpdate->state);
|
||||
self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($recipe->video_url, $recipeUpdate->video_url);
|
||||
|
||||
$recipeUpdate->assertRedirect($newRecipeUrl);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,17 +168,22 @@ final class EditTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
$recipeCreatedLast = Recipe::orderByDesc('id')->first();
|
||||
$newRecipeUrl = route('recipe.show', $recipeCreatedLast, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($recipeCreatedLast->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals('archived', $recipeUpdate->state);
|
||||
self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($recipe->video_url, $recipeUpdate->video_url);
|
||||
|
||||
|
||||
$recipeUpdate->assertRedirect($newRecipeUrl);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,17 +198,21 @@ final class EditTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
$recipeCreatedLast = Recipe::orderByDesc('id')->first();
|
||||
$newRecipeUrl = route('recipe.show', $this->recipe, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertMissing($recipeCreatedLast->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($this->recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($this->recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals($this->recipe->state, $recipeUpdate->state);
|
||||
self::assertEquals($this->recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($this->recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($this->recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($this->recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($this->recipe->video_url, $recipeUpdate->video_url);
|
||||
|
||||
$recipeUpdate->assertRedirect($newRecipeUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user