diff --git a/database/factories/RoadItemsProjectFactory.php b/database/factories/RoadItemsProjectFactory.php index b6543430..174d68a8 100644 --- a/database/factories/RoadItemsProjectFactory.php +++ b/database/factories/RoadItemsProjectFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Support\Facades\Schema; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> @@ -18,7 +19,16 @@ class RoadItemsProjectFactory extends Factory { return [ 'item' => $this->faker->numberBetween(1, 10), - 'sub_item' => $this->faker->numberBetween(1, 10), - ]; + 'sub_items' => $this->faker->title(), + 'start_lat' =>$this->faker->latitude(), + 'start_lng' =>$this->faker->longitude(), + 'is_new' => $this->faker->boolean(), + 'status' => $this->faker->randomElement([0, 1, 2]), + 'activity_date_time' =>$this->faker->dateTimeBetween('-1 year', 'now'), + 'province_id' => $this->faker->numberBetween(1, 10), + 'city_id' => $this->faker->numberBetween(1, 10), + 'user_id' =>$this->faker->numberBetween(1, 10), + 'user_name' => $this->faker->name(), + ]; } } diff --git a/tests/Feature/V3/RoadItemsProject/RestoreTest.php b/tests/Feature/V3/RoadItemsProject/RestoreTest.php new file mode 100644 index 00000000..a0688df5 --- /dev/null +++ b/tests/Feature/V3/RoadItemsProject/RestoreTest.php @@ -0,0 +1,72 @@ +create(); + $roadItem = RoadItemsProject::factory()->create(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id])); + $response->assertForbidden(); + } + public function test_user_cannot_access_authentication_restore(): void + { + $roadItem = RoadItemsProject::factory()->create(); + $response =$this->postJson(route('v3.road_items.restore', [$roadItem->id])); + $response->assertStatus(401); + + } + public function test_user_can_restore_road_item(): void + { + $user = User::factory() + ->has(Permission::factory([ + 'name' => 'restore-road-item' + ])) + ->create(); + + $logList = LogList::factory()->create([ + 'log_unique_code' => 1150, + ]); + UserActivityLog::factory()->create(); + + $roadItem = RoadItemsProject::factory()->create([ + 'status' => 1, + 'status_fa' => 'تایید شده', + 'supervisor_id' => $user->id, + 'supervisor_name' => $user->name, + 'supervisor_description' => 'تایید شده توسط تست', + ]); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id])); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + + $this->assertDatabaseHas('road_items_projects', [ + 'id' => $roadItem->id, + 'status' => 0, + 'status_fa' => 'در حال بررسی', + 'supervisor_id' => null, + 'supervisor_name' => null, + 'supervisor_description' => null, + 'supervising_time' => null, + ]); + } + +} diff --git a/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php b/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php index 13a080d4..602f4bdb 100644 --- a/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php +++ b/tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php @@ -23,6 +23,13 @@ class SupervisorIndexTest extends TestCase $response->assertForbidden(); } + public function test_user_cannot_access_authentication_to_supervisor_index(): void + { + $response = $this->getJson(route('v3.road_items.supervisorIndex')); + + $response->assertStatus(401); + } + public function test_supervisor_can_see_the_data_table(): void { @@ -47,49 +54,21 @@ class SupervisorIndexTest extends TestCase 'data' => [ '*' => [ "id", - "user_id", "start_lat", "start_lng", "end_lat", "end_lng", - "project_distance", "item", "item_fa", - "sub_item", "sub_item_fa", "sub_item_data", - "sub_items", - "sub_items_data", "created_at", - "updated_at", - "province_id", "province_fa", - "city_id", - "city_fa", - "is_new", - "parent_id", - "start_way_id", - "end_way_id", "unit_fa", - "user_name", - "created_at_fa", - "info_id", "status", "status_fa", - "edarat_id", "edarat_name", - "edarat_type", - "activity_date", - "activity_time", "activity_date_time", - "supervisor_id", - "supervisor_name", - "supervisor_description", - "supervising_time", - "cmms_machine_id", - "cmms_machine_code", - "rahdar_id", - "rahdar_code", "can_supervise", ], ] diff --git a/tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php b/tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php new file mode 100644 index 00000000..24c14c43 --- /dev/null +++ b/tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php @@ -0,0 +1,133 @@ +create(); + + $response = $this->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id])); + + $response->assertStatus(401); + } + + public function test_supervisor_without_permission_cannot_verify_road_item(): void + { + $user = User::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(false); + + $roadItem = RoadItemsProject::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id,])); + + $response->assertForbidden(); + } + public function test_validation_fails_when_required_fields_are_missing(): void + { + $user = User::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'verify' => __('validation.required', ['attribute' => 'verify']), + ]); + } + + public function test_validation_fails_when_verify_field_is_invalid(): void + { + $user = User::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]), [ + 'verify' => 5, + 'description' => $this->faker()->sentence(), + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'verify' => __('validation.in', ['attribute' => 'verify']), + ]); + } + + public function test_verify_description_must_be_string(): void + { + $user = User::factory()->create(); + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]), [ + 'description' => 12345, + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'description' => __('validation.string', ['attribute' =>"توضیحات"]), + ]); + } + + + + public function test_supervisor_can_view_road_item_data(): void + { + $user = User::factory()->create(); + + LogList::factory()->create([ + 'log_unique_code' => 1149, + ]); + UserActivityLog::factory()->create(); + + $roadItem = RoadItemsProject::factory()->create(); + + Gate::shouldReceive('allows') + ->andReturn(true); + + $description = fake()->sentence(); + $response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id,]), [ + 'verify' => 1, + 'description' =>$description, + ]); + + $response->assertOk() + ->assertJson([ + 'message' => __('messages.successful'), + ]); + $this->assertDatabaseHas('road_items_projects', [ + 'id' => $roadItem->id, + 'status' => 1, + 'status_fa' => 'تایید شده', + 'supervisor_id' => $user->id, + 'supervisor_name' => $user->name, + 'supervisor_description' =>$description, + ]); + } +}