Merge branch 'feature/Tests' into 'develop'

Feature/tests

See merge request witelgroup/rms_v2!94
This commit is contained in:
2025-04-06 07:31:21 +00:00
14 changed files with 995 additions and 583 deletions

View File

@@ -33,16 +33,14 @@ class SendRoadObservationToNikarayanCommand extends Command
$this->info("Dispatching jobs with a delay between each...");
DB::transaction(function () use (&$count) {
$delay = 0;
RoadObserved::query()
->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-13 23:59:59'])
->chunkById(50, function ($roads) use (&$delay, &$count) {
->chunkById(50, function ($roads) use (&$count) {
foreach ($roads as $road) {
$road->update(['status' => 1]);
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addSeconds($delay));
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with a {$delay} seconds delay.");
$this->info("Scheduled job for Road ID: {$road->id} {$delay}s");
$delay += 3;
SendRoadObservationToNikarayan::dispatch($road);
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled.");
$this->info("Scheduled job for Road ID: {$road->id}");
$count +=1;
}
});

View File

@@ -157,7 +157,7 @@ class SafetyAndPrivacyController extends Controller
'axis_type_name' => AxisTypes::name($request->axis_type_id),
]);
auth()->user()->addActivityComplete();
auth()->user()->addActivityComplete(1168);
});
return $this->successResponse();

View File

@@ -45,12 +45,14 @@ class SendRoadObservationToNikarayan implements ShouldQueue
);
$soapClient = new SoapClient($url);
$soapClient->UpdateInfo_RoadObservedProblems($array);
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
Log::channel('road_observation_problem')->info(json_encode($result), [$this->roadObserved->id]);
}
catch (\Exception $exception){
Log::channel('road_observation_problem')->error($exception->getMessage(), [
'roadObserved' => $this->roadObserved,
'roadObserved' => $this->roadObserved->id,
'line' => $exception->getLine(),
'file' => $exception->getFile(),
]);
}
}

View File

@@ -33,7 +33,7 @@ class NikarayanService
$soapClient = new SoapClient($url);
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
Log::channel('nikarayan')->info($result);
Log::channel('nikarayan')->info(json_encode($result));
return $result;
}

View File

@@ -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(),
];
}
}

View File

@@ -321,6 +321,7 @@ Route::prefix('road_observations')
Route::prefix('log_list')
->name('logList.')
->middleware('permission:manage-log-list')
->controller(LogListManagementController::class)
->group(function () {
Route::get('/', 'index')->name('index');
@@ -341,6 +342,7 @@ Route::prefix('safety_and_privacy')
Route::get('/sub_items', 'subItems')->name('subItems');
Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy');
Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy');
Route::post('/{safetyAndPrivacy}', 'update')->name('update')->middleware('permission:update-safety-and-privacy');
Route::get('/{safetyAndPrivacy}', 'show')->name('show');
Route::delete('/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy');
Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize');
@@ -372,6 +374,7 @@ Route::name('items.')
Route::prefix('permissions')
->name('permissions.')
->middleware('permission:manage-permissions')
->controller(PermissionManagementController::class)
->group(function () {
Route::get('/', 'index')->name('index');

View File

@@ -0,0 +1,59 @@
<?php
namespace Tests\Feature\V3\Permission;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class IndexTest extends TestCase
{
use RefreshDatabase, WithFaker;
/**
* A basic feature test example.
*/
public function test_user_should_have_manage_permission(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->getJson(route('v3.permissions.index'));
$response->assertForbidden();
}
public function test_all_permissions_returned_successfully(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->getJson(route('v3.permissions.index', [
'start' => 0,
'size' => 10,
'filters' => json_encode([]),
'sorting' => json_encode([]),
]));
$response->assertOk();
$response->assertJsonStructure([
'data' => [
'*' => [
'id',
'name',
'name_fa',
'type',
'type_fa',
'description',
],
],
"meta" => [
"totalRowCount"
]
]);
}
}

View File

@@ -0,0 +1,297 @@
<?php
namespace Tests\Feature\V3\Permission;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class StoreTest extends TestCase
{
use RefreshDatabase, WithFaker;
/**
* A basic feature test example.
*/
public function test_user_should_have_manage_permission(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertForbidden();
}
public function test_name_attribute_is_required(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertUnprocessable()
->assertInvalid([
'name' => __('validation.required', ['attribute' => 'نام'])
]);
}
public function test_name_attribute_should_be_string(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'name' => $this->faker->numberBetween(1, 10)
]);
$response->assertUnprocessable()
->assertInvalid([
'name' => __('validation.string', ['attribute' => 'نام'])
]);
}
public function test_name_attribute_should_be_unique(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$permission = Permission::factory()->create([
'name' => $this->faker->name()
]);
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'name' => $permission->name,
]);
$response->assertUnprocessable()
->assertInvalid([
'name' => __('validation.unique', ['attribute' => 'نام'])
]);
}
public function test_name_fa_attribute_is_required(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertUnprocessable()
->assertInvalid([
'name_fa' => __('validation.required', ['attribute' => 'name fa'])
]);
}
public function test_name_fa_attribute_should_be_string(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'name_fa' => $this->faker->numberBetween(1, 10)
]);
$response->assertUnprocessable()
->assertInvalid([
'name_fa' => __('validation.string', ['attribute' => 'name fa'])
]);
}
public function test_description_attribute_should_be_string(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'description' => $this->faker->numberBetween(1, 10)
]);
$response->assertUnprocessable()
->assertInvalid([
'description' => __('validation.string', ['attribute' => 'توضیحات'])
]);
}
public function test_type_attribute_is_required(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertUnprocessable()
->assertInvalid([
'type' => __('validation.required', ['attribute' => 'type'])
]);
}
public function test_type_attribute_should_be_string(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'type' => $this->faker->numberBetween(1, 10)
]);
$response->assertUnprocessable()
->assertInvalid([
'type' => __('validation.string', ['attribute' => 'type'])
]);
}
public function test_type_fa_attribute_is_required(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertUnprocessable()
->assertInvalid([
'type_fa' => __('validation.required', ['attribute' => 'type fa'])
]);
}
public function test_type_fa_attribute_should_be_string(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'type_fa' => $this->faker->numberBetween(1, 10)
]);
$response->assertUnprocessable()
->assertInvalid([
'type_fa' => __('validation.string', ['attribute' => 'type fa'])
]);
}
public function test_need_province_attribute_is_required(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertUnprocessable()
->assertInvalid([
'need_province' => __('validation.required', ['attribute' => 'need province'])
]);
}
public function test_need_province_attribute_should_be_1_or_0(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'need_province' => $this->faker->numberBetween(3, 9),
]);
$response->assertUnprocessable()
->assertInvalid([
'need_province' => __('validation.in', ['attribute' => 'need province'])
]);
}
public function test_need_edare_shahri_attribute_is_required(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
$response->assertUnprocessable()
->assertInvalid([
'need_edare_shahri' => __('validation.required', ['attribute' => 'need edare shahri'])
]);
}
public function test_need_edare_shahri_attribute_should_be_1_or_0(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
'need_edare_shahri' => $this->faker->numberBetween(3, 9),
]);
$response->assertUnprocessable()
->assertInvalid([
'need_edare_shahri' => __('validation.in', ['attribute' => 'need edare shahri'])
]);
}
public function test_user_can_create_a_permission()
{
$user = User::factory()
->has(Permission::factory([
'name' => 'manage-permissions'
]))
->create();
$inputData = [
'name' => $this->faker->name(),
'name_fa' => $this->faker->name(),
'description' => $this->faker->lexify(),
'type' => $this->faker->name(),
'type_fa' => $this->faker->name(),
'need_province' => $this->faker->numberBetween(0, 1),
'need_edare_shahri' => $this->faker->numberBetween(0, 1),
];
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), $inputData);
$response->assertOk()
->assertExactJson([
'message' => __('messages.successful'),
]);
$this->assertDatabaseHas('permissions', $inputData);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Tests\Feature\V3\RoadItemsProject;
use App\Models\LogList;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use App\Models\UserActivityLog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class DeleteTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_user_should_have_show_road_item_supervise_delete_permission(): void
{
$user = User::factory()->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,
]);
}
}

View File

@@ -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()

View File

@@ -0,0 +1,72 @@
<?php
namespace Tests\Feature\V3\RoadItemsProject;
use App\Models\LogList;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use App\Models\UserActivityLog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use function Ramsey\Uuid\v3;
class RestoreTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_user_should_have_show_road_item_supervise_restore_permission(): void
{
$user = User::factory()->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,
]);
}
}

View File

@@ -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,
]);
}
}

View File

@@ -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",
],
]

View File

@@ -0,0 +1,133 @@
<?php
namespace Tests\Feature\V3\RoadItemsProject;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\UserActivityLog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Mockery;
use App\Models\LogList;
use Illuminate\Support\Facades\Schema;
class VerifyBySupervisor extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_user_cannot_access_authentication_to_verify_by_supervisor(): void
{
$roadItem = RoadItemsProject::factory()->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,
]);
}
}