From 52b29346e3b2eefe2ff367f92d7f209d8d9d522a Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Fri, 8 Dec 2023 13:25:02 +0300 Subject: [PATCH] update plan create test --- database/factories/PlanFactory.php | 8 ++++-- tests/Feature/Plan/CreateTest.php | 41 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php index 697e274..9220ba6 100755 --- a/database/factories/PlanFactory.php +++ b/database/factories/PlanFactory.php @@ -1,6 +1,8 @@ $this->faker->text(), ]; + Storage::fake('plans'); + return [ 'name' => $this->faker->foodName(), - // 'image' => $this->faker->image('application/storage/fake_images', 640, 480, null, false), - 'image' => storage_path('public/img/Photo_C.png'), + // 'image' => UploadedFile::fake()->image('plans/Photo_C.png'), + 'image' => UploadedFile::fake()->image('plan.png'), 'duration' => $this->faker->randomElement([7, 14,21]), 'state' => $this->faker->randomElement(['active', 'draft', 'archived']), 'type' => $typeBody, diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index 928accc..b4609b4 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -1,7 +1,9 @@ get('/plan/create'); $response - ->assertOk(); + ->assertStatus(302) + ->assertRedirect('https://dev2.eatvio.com/ru'); } public function test_publish_new_plan_success(): void { $plan = Plan::factory()->make(); - $user = User::factory()->create(); + $user = User::factory()->create(['is_consultant' => true]); + + $count = $plan->count(); + $this->actingAs($user); Livewire::test(Create::class) ->set('name', $plan->name) + ->assertSet('name', $plan->name) ->set('image', $plan->image) ->set('duration', $plan->duration) ->set('state', $plan->state) @@ -45,18 +52,24 @@ class CreateTest extends TestCase ->set('packet2_options', $plan->packet2_options) ->set('packet3_options', $plan->packet3_options) ->call('publish') - ->assertRedirect('/plan/'. $plan->id); - } + // ->assertFileDownloaded('plan.png'); + ->assertStatus(200) + ->assertRedirect('plan/'.$plan->count()); + + $this->assertEquals($plan->count(), $count + 1); + } +// public function test_to_draft_new_plan_success(): void { $plan = Plan::factory()->make(); $user = User::factory()->create(); - +// $this->actingAs($user); - +// Livewire::test(Create::class) ->set('name', $plan->name) + ->assertSet('name', $plan->name) ->set('image', $plan->image) ->set('duration', $plan->duration) ->set('state', $plan->state) @@ -67,18 +80,20 @@ class CreateTest extends TestCase ->set('packet2_options', $plan->packet2_options) ->set('packet3_options', $plan->packet3_options) ->call('addToDrafts') - ->assertRedirect('/plan/'. $plan->id); + ->assertStatus(200) + ->assertRedirect('plan/'.$plan->count()); } - +// public function test_to_preview_new_plan_success(): void { $plan = Plan::factory()->make(); $user = User::factory()->create(); - +// $this->actingAs($user); - +// Livewire::test(Create::class) ->set('name', $plan->name) + ->assertSet('name', $plan->name) ->set('image', $plan->image) ->set('duration', $plan->duration) ->set('state', $plan->state) @@ -89,6 +104,10 @@ class CreateTest extends TestCase ->set('packet2_options', $plan->packet2_options) ->set('packet3_options', $plan->packet3_options) ->call('addToDrafts') - ->assertRedirect('/plan/'. $plan->id); + ->assertStatus(200) + ->assertRedirect('plan/'.$plan->count()); + + + // ->assertRedirect('/plan/'. $plan->id); } }