From f295034f4f6967b33e9888dc4503409749eeba88 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Sun, 30 Mar 2025 13:47:39 +0330 Subject: [PATCH] create test for three item in roaditem project --- .../V3/RoadItemsProject/DeleteTest.php | 57 ++ .../V3/RoadItemsProject/OperatorIndexTest.php | 8 + .../Feature/V3/RoadItemsProject/StoreTest.php | 878 +++++++----------- 3 files changed, 401 insertions(+), 542 deletions(-) create mode 100644 tests/Feature/V3/RoadItemsProject/DeleteTest.php diff --git a/tests/Feature/V3/RoadItemsProject/DeleteTest.php b/tests/Feature/V3/RoadItemsProject/DeleteTest.php new file mode 100644 index 00000000..09fb4ae8 --- /dev/null +++ b/tests/Feature/V3/RoadItemsProject/DeleteTest.php @@ -0,0 +1,57 @@ +create(); + $roadItem = RoadItemsProject::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.delete', [$roadItem->id])); + $response->assertForbidden(); + } + + public function test_user_cannot_access_authentication_delete(): void + { + $roadItem = RoadItemsProject::factory()->create(); + $response =$this->postJson(route('v3.road_items.delete', [$roadItem->id])); + $response->assertStatus(401); + + } + + public function test_user_can_delete_road_item(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'delete-road-item' + ])) + ->create(); + + $logList = LogList::factory()->create([ + 'log_unique_code' => 1151, + ]); + UserActivityLog::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.delete', [$roadItem->id])); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + $this->assertDatabaseMissing('road_items_projects', [ + 'id' => $roadItem->id, + ]); + } +} diff --git a/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php b/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php index b7e9a765..27888ae7 100644 --- a/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php +++ b/tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php @@ -24,6 +24,14 @@ class OperatorIndexTest extends TestCase $response->assertForbidden(); } + public function test_user_cannot_access_authentication_to_operator_index(): void + { + $response = $this->getJson(route('v3.road_items.operatorIndex')); + + $response->assertStatus(401); + } + + public function test_operator_can_see_the_data_table(): void { $user = User::factory() diff --git a/tests/Feature/V3/RoadItemsProject/StoreTest.php b/tests/Feature/V3/RoadItemsProject/StoreTest.php index ee141ece..7a44821a 100644 --- a/tests/Feature/V3/RoadItemsProject/StoreTest.php +++ b/tests/Feature/V3/RoadItemsProject/StoreTest.php @@ -12,6 +12,7 @@ use App\Models\ObservedItem; use App\Models\Permission; use App\Models\Province; use App\Models\Rahdaran; +use App\Models\RoadItemsProject; use App\Models\User; use App\Models\UserActivityLog; use App\Services\NominatimService; @@ -22,6 +23,8 @@ use Illuminate\Support\Facades\Storage; use Mockery\MockInterface; use Symfony\Component\Finder\Exception\AccessDeniedException; use Tests\TestCase; +use Illuminate\Support\Str; + class StoreTest extends TestCase { @@ -37,104 +40,56 @@ class StoreTest extends TestCase $response->assertForbidden(); } + public function test_user_cannot_access_authentication_store(): void + { +// $roadItem = RoadItemsProject::factory()->create(); + $response =$this->postJson(route('v3.road_items.store')); + $response->assertStatus(401); - public function test_start_point_is_required(): void + } + + public function test_required_fields(): void { $user = User::factory() ->has(Permission::factory([ 'name' => 'create-road-item' ])) ->create(); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); $response->assertUnprocessable() ->assertInvalid([ - 'start_point' => __('validation.required', ['attribute' => 'start point']) + 'start_point' => __('validation.required', ['attribute' => 'start point']), + 'item_id' => __('validation.required', ['attribute' => 'item id']), + 'sub_item_id' => __('validation.required', ['attribute' => 'sub item id']), + 'amount' => __('validation.required', ['attribute' => 'amount']), + 'activity_date' => __('validation.required', ['attribute' => 'تاریخ فعالیت']), + 'activity_time' => __('validation.required', ['attribute' => 'ساعت فعالیت']), + 'machines_id' => __('validation.required', ['attribute' => 'machines id']), + 'rahdaran_id' => __('validation.required', ['attribute' => 'rahdaran id']), ]); } - public function test_item_id_is_required(): void + public function test_integer_fields(): void { $user = User::factory() ->has(Permission::factory([ 'name' => 'create-road-item' ])) ->create(); + $data = [ + 'item_id' => $this->faker->name, + 'sub_item_id' => $this->faker->name, + 'observed_item_id' => $this->faker->name, + ]; - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); + $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); $response->assertUnprocessable() ->assertInvalid([ - 'item_id' => __('validation.required', ['attribute' => 'item id']) - ]); - } - - public function test_item_id_should_be_integer(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'item_id' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'item_id' => __('validation.integer', ['attribute' => 'item id']) - ]); - } - - public function test_sub_item_id_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'sub_item_id' => __('validation.required', ['attribute' => 'sub item id']) - ]); - } - - public function test_sub_item_id_should_be_integer(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'sub_item_id' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'sub_item_id' => __('validation.integer', ['attribute' => 'sub item id']) - ]); - } - - public function test_amount_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'amount' => __('validation.required', ['attribute' => 'amount']) + 'item_id' => __('validation.integer', ['attribute' => 'item id']), + 'sub_item_id' => __('validation.integer', ['attribute' => 'sub item id']), + 'observed_item_id' => __('validation.integer', ['attribute' => 'observed item id']), ]); } @@ -156,7 +111,7 @@ class StoreTest extends TestCase ]); } - public function test_observed_item_id_should_be_integer(): void + public function test_exists_fields(): void { $user = User::factory() ->has(Permission::factory([ @@ -164,523 +119,362 @@ class StoreTest extends TestCase ])) ->create(); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'observed_item_id' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'observed_item_id' => __('validation.integer', ['attribute' => 'observed item id']) - ]); - } - - public function test_observed_item_id_should_be_existed_in_db(): void - { - $observedItem = ObservedItem::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'observed_item_id' => $this->faker->numberBetween(10, 20) - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'observed_item_id' => __('validation.exists', ['attribute' => 'observed item id']) - ]); - } - - public function test_activity_date_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_date' => __('validation.required', ['attribute' => 'تاریخ فعالیت']) - ]); - } - - public function test_activity_date_should_match_the_format(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'activity_date' => $this->faker->date('d-m-Y-H-i-s') - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_date' => __('validation.date_format', ['attribute' => 'تاریخ فعالیت', 'format' => 'Y-m-d']) - ]); - } - - public function test_activity_time_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_time' => __('validation.required', ['attribute' => 'ساعت فعالیت']) - ]); - } - - public function test_activity_time_should_match_the_format(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'activity_time' => $this->faker->date('d-m-Y-H-i-s') - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'activity_time' => __('validation.date_format', ['attribute' => 'ساعت فعالیت', 'format' => 'H:i']) - ]); - } - - public function test_before_image_should_be_image(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'before_image' => $this->faker->name - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'before_image' => __('validation.image', ['attribute' => 'before image']) - ]); - } - - public function test_before_image_should_be_less_than_4096kb(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $image = UploadedFile::fake()->create('image.jpg', 5096); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'before_image' => $image - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'before_image' => __('validation.max.file', ['attribute' => 'before image', 'max' => 4096]) - ]); - } - - public function test_after_image_should_be_image(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'after_image' => $this->faker->randomNumber() - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'after_image' => __('validation.image', ['attribute' => 'after image']) - ]); - } - - public function test_after_image_should_be_less_than_4096kb(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $image = UploadedFile::fake()->create('image.jpg', 5096); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'after_image' => $image - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'after_image' => __('validation.max.file', ['attribute' => 'after image', 'max' => 4096]) - ]); - } - - public function test_cmms_machine_id_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'cmms_machine_id' => __('validation.required', ['attribute' => 'کد یکتا ماشین']) - ]); - } - - public function test_cmms_machine_id_should_already_exists_on_the_table(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'cmms_machine_id' => $this->faker->numberBetween(10, 100) - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'cmms_machine_id' => __('validation.exists', ['attribute' => 'کد یکتا ماشین']) - ]); - } - - public function test_rahdar_id_is_required(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store')); - - $response->assertUnprocessable() - ->assertInvalid([ - 'rahdar_id' => __('validation.required', ['attribute' => 'rahdar id']) - ]); - } - - public function test_rahdar_id_should_already_exists_on_the_table(): void - { - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create(); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), [ - 'rahdar_id' => $this->faker->numberBetween(10, 100) - ]); - - $response->assertUnprocessable() - ->assertInvalid([ - 'rahdar_id' => __('validation.exists', ['attribute' => 'rahdar id']) - ]); - } - - public function test_province_user_is_prohibited_to_access(): void - { - $edarateOstani = EdarateOstani::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'edarate_ostani_id' => $edarateOstani->id - ]); - $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'machines_id' => [$this->faker->numberBetween(10000, 99999)], + 'rahdaran_id' => [$this->faker->numberBetween(10000, 99999)], + 'observed_item_id' => $this->faker->numberBetween(10000, 99999), ]; $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - $response->assertStatus(400) - ->assertExactJson([ - 'message' => 'امکان ثبت فعالیت برای ادارات استانی و ستادی وجود ندارد!' + $response->assertUnprocessable() + ->assertInvalid([ + 'machines_id.0', + 'rahdaran_id.0', + 'observed_item_id', ]); } - public function test_user_should_have_edarate_shahri_id(): void + public function test_image_fields(): void { - $city = City::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - $user = User::factory() ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id - ]); + 'name' => 'create-road-item'])) + ->create(); $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'before_image' =>$this->faker->name, + 'after_image' =>$this->faker->name, ]; $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - $response->assertStatus(400) - ->assertExactJson([ - 'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!' - ]); - } - - public function test_end_point_required_when_info_item_needs_end_point(): void - { - $city = City::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id, - 'edarate_shahri_id' => $edarateShari->id - ]); - - $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, - ]; - - InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_end_point' => 1 - ]); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - $response->assertUnprocessable() ->assertInvalid([ - 'end_point' => __('validation.required', ['attribute' => 'end_point']) + 'before_image' => __('validation.image', ['attribute' => 'before image']), + 'after_image' => __('validation.image', ['attribute' => 'after image']), ]); } - public function test_before_image_required_when_info_item_needs_image(): void + public function test_image_should_be_less_than_4096kb(): void { - $city = City::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - $user = User::factory() ->has(Permission::factory([ 'name' => 'create-road-item' ])) - ->create([ - 'city_id' => $city->id, - 'edarate_shahri_id' => $edarateShari->id - ]); + ->create(); $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'before_image' => UploadedFile::fake()->create('image.jpg', 5096), + 'after_image' => UploadedFile::fake()->create('image.jpg', 5096), ]; - InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_image' => 1 - ]); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); $response->assertUnprocessable() ->assertInvalid([ - 'before_image' => __('validation.required', ['attribute' => 'before_image']) + 'before_image' => __('validation.max.file', ['attribute' => 'before image', 'max' => 4096]), + 'after_image' => __('validation.max.file', ['attribute' => 'after image', 'max' => 4096]), ]); } - public function test_after_image_required_when_info_item_needs_image(): void + public function test_date_format_fields(): void { - $city = City::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - $user = User::factory() ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id, - 'edarate_shahri_id' => $edarateShari->id - ]); + 'name' => 'create-road-item'])) + ->create(); $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, + 'activity_date' => $this->faker->date('d-m-Y-H-i-s'), + 'activity_time'=> $this->faker->date('d-m-Y-H-i-s'), ]; - InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_image' => 1 - ]); - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); $response->assertUnprocessable() ->assertInvalid([ - 'after_image' => __('validation.required', ['attribute' => 'after_image']) + 'activity_date' => __('validation.date_format', ['attribute' => 'تاریخ فعالیت', 'format' => 'Y-m-d']), + 'activity_time' => __('validation.date_format', ['attribute' => 'ساعت فعالیت', 'format' => 'H:i']), ]); } +// +// public function test_province_user_is_prohibited_to_access(): void +// { +// $edarateOstani = EdarateOstani::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'edarate_ostani_id' => $edarateOstani->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertStatus(400) +// ->assertExactJson([ +// 'message' => 'امکان ثبت فعالیت برای ادارات استانی و ستادی وجود ندارد!' +// ]); +// } +// +// public function test_user_should_have_edarate_shahri_id(): void +// { +// $city = City::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertStatus(400) +// ->assertExactJson([ +// 'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!' +// ]); +// } +// +// public function test_end_point_required_when_info_item_needs_end_point(): void +// { +// $city = City::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_end_point' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertUnprocessable() +// ->assertInvalid([ +// 'end_point' => __('validation.required', ['attribute' => 'end_point']) +// ]); +// } +// +// public function test_before_image_required_when_info_item_needs_image(): void +// { +// $city = City::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_image' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertUnprocessable() +// ->assertInvalid([ +// 'before_image' => __('validation.required', ['attribute' => 'before_image']) +// ]); +// } +// +// public function test_after_image_required_when_info_item_needs_image(): void +// { +// $city = City::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_image' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertUnprocessable() +// ->assertInvalid([ +// 'after_image' => __('validation.required', ['attribute' => 'after_image']) +// ]); +// } +// +// public function test_can_store_a_new_road_item_project(): void +// { +// $city = City::factory()->create(); +// $province = Province::factory()->create(); +// $edarateShari = EdarateShahri::factory()->create(); +// $cmmsMachine = CMMSMachine::factory()->create(); +// $rahdar = Rahdaran::factory()->create(); +// +// LogList::factory()->create([ +// 'log_unique_code' => 1154 +// ]); +// UserActivityLog::factory()->create(); +// +// $user = User::factory() +// ->has(Permission::factory([ +// 'name' => 'create-road-item' +// ])) +// ->create([ +// 'city_id' => $city->id, +// 'province_id' => $province->id, +// 'edarate_shahri_id' => $edarateShari->id +// ]); +// +// Storage::fake('public'); +// +// $this->mock(NominatimService::class, function (MockInterface $mock) { +// $mock->shouldReceive('get_way_id_from_nominatim') +// ->once() +// ->andReturn(0); +// }); +// +// $data = [ +// 'start_point' => '12,12', +// 'item_id' => $this->faker->numberBetween(1, 10), +// 'sub_item_id' => $this->faker->numberBetween(1, 10), +// 'amount' => $this->faker->numberBetween(1, 10), +// 'activity_date' => $this->faker->date(), +// 'activity_time' => $this->faker->date('H:i'), +// 'before_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'after_image' => UploadedFile::fake()->create('image.jpg', 10), +// 'cmms_machine_id' => $cmmsMachine->id, +// 'rahdar_id' => $rahdar->id, +// ]; +// +// $infoItem = InfoItem::factory()->create([ +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'needs_image' => 1 +// ]); +// +// $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); +// +// $response->assertOk() +// ->assertExactJson([ +// 'message' => __('messages.successful') +// ]); +// +// $this->assertDatabaseHas('road_items_projects', [ +// 'start_lat' => 12, +// 'start_lng' => 12, +// 'item' => $data['item_id'], +// 'sub_item' => $data['sub_item_id'], +// 'province_id' => $province->id, +// 'city_id' => $city->id, +// 'user_name' => $user->name, +// 'start_way_id' => 0, +// 'info_id' => $infoItem->id, +// 'status' => 0, +// 'status_fa' => 'در حال بررسی', +// 'edarat_id' => $user->edarate_shahri_id, +// 'cmms_machine_id' => $cmmsMachine->id, +// 'cmms_machine_code' => $cmmsMachine->machine_code, +// 'rahdar_id' => $rahdar->id, +// 'rahdar_code' => $rahdar->code +// ]); +// +// $this->assertDatabaseHas('user_activity_logs', [ +// 'user_id' => $user->id, +// 'username' => $user->username, +// 'log_unique_code' => 1154, +// ]); +// - public function test_can_store_a_new_road_item_project(): void - { - $city = City::factory()->create(); - $province = Province::factory()->create(); - $edarateShari = EdarateShahri::factory()->create(); - $cmmsMachine = CMMSMachine::factory()->create(); - $rahdar = Rahdaran::factory()->create(); - - LogList::factory()->create([ - 'log_unique_code' => 1154 - ]); - UserActivityLog::factory()->create(); - - $user = User::factory() - ->has(Permission::factory([ - 'name' => 'create-road-item' - ])) - ->create([ - 'city_id' => $city->id, - 'province_id' => $province->id, - 'edarate_shahri_id' => $edarateShari->id - ]); - - Storage::fake('public'); - - $this->mock(NominatimService::class, function (MockInterface $mock) { - $mock->shouldReceive('get_way_id_from_nominatim') - ->once() - ->andReturn(0); - }); - - $data = [ - 'start_point' => '12,12', - 'item_id' => $this->faker->numberBetween(1, 10), - 'sub_item_id' => $this->faker->numberBetween(1, 10), - 'amount' => $this->faker->numberBetween(1, 10), - 'activity_date' => $this->faker->date(), - 'activity_time' => $this->faker->date('H:i'), - 'before_image' => UploadedFile::fake()->create('image.jpg', 10), - 'after_image' => UploadedFile::fake()->create('image.jpg', 10), - 'cmms_machine_id' => $cmmsMachine->id, - 'rahdar_id' => $rahdar->id, - ]; - - $infoItem = InfoItem::factory()->create([ - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'needs_image' => 1 - ]); - - $response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data); - - $response->assertOk() - ->assertExactJson([ - 'message' => __('messages.successful') - ]); - - $this->assertDatabaseHas('road_items_projects', [ - 'start_lat' => 12, - 'start_lng' => 12, - 'item' => $data['item_id'], - 'sub_item' => $data['sub_item_id'], - 'province_id' => $province->id, - 'city_id' => $city->id, - 'user_name' => $user->name, - 'start_way_id' => 0, - 'info_id' => $infoItem->id, - 'status' => 0, - 'status_fa' => 'در حال بررسی', - 'edarat_id' => $user->edarate_shahri_id, - 'cmms_machine_id' => $cmmsMachine->id, - 'cmms_machine_code' => $cmmsMachine->machine_code, - 'rahdar_id' => $rahdar->id, - 'rahdar_code' => $rahdar->code - ]); - - $this->assertDatabaseHas('user_activity_logs', [ - 'user_id' => $user->id, - 'username' => $user->username, - 'log_unique_code' => 1154, - ]); - } }