add rahdar id to road item project

This commit is contained in:
2024-12-15 10:08:49 +03:30
parent e7163490c9
commit 1b60739a14
12 changed files with 477 additions and 30 deletions

View File

@@ -0,0 +1,97 @@
<?php
namespace Tests\Feature\V3\RoadItemsProject;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class OperatorIndexTest extends TestCase
{
use RefreshDatabase, WithFaker;
/**
* A basic feature test example.
*/
public function test_user_should_have_create_road_item_permission(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->getJson(route('v3.road_items.operatorIndex'));
$response->assertForbidden();
}
public function test_operator_can_see_the_data_table(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'create-road-item'
]))
->create();
RoadItemsProject::factory(10)->create();
$response = $this->actingAs($user)->getJson(route('v3.road_items.operatorIndex', [
'size' => 10,
'start' => 0,
'sorting' => json_encode([]),
'filters' => json_encode([]),
]));
$response->assertOk();
$response->assertJsonStructure([
'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",
],
]
]);
}
}

View File

@@ -11,6 +11,7 @@ use App\Models\LogList;
use App\Models\ObservedItem;
use App\Models\Permission;
use App\Models\Province;
use App\Models\Rahdaran;
use App\Models\User;
use App\Models\UserActivityLog;
use App\Services\NominatimService;
@@ -349,7 +350,7 @@ class StoreTest extends TestCase
$response->assertUnprocessable()
->assertInvalid([
'cmms_machine_id' => __('validation.required', ['attribute' => 'cmms machine id'])
'cmms_machine_id' => __('validation.required', ['attribute' => 'کد یکتا ماشین'])
]);
}
@@ -367,7 +368,41 @@ class StoreTest extends TestCase
$response->assertUnprocessable()
->assertInvalid([
'cmms_machine_id' => __('validation.exists', ['attribute' => 'cmms machine id'])
'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'])
]);
}
@@ -375,6 +410,7 @@ class StoreTest extends TestCase
{
$edarateOstani = EdarateOstani::factory()->create();
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
$user = User::factory()
->has(Permission::factory([
@@ -393,7 +429,8 @@ class StoreTest extends TestCase
'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
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data);
@@ -408,6 +445,7 @@ class StoreTest extends TestCase
{
$city = City::factory()->create();
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
$user = User::factory()
->has(Permission::factory([
@@ -426,7 +464,8 @@ class StoreTest extends TestCase
'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
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data);
@@ -442,6 +481,7 @@ class StoreTest extends TestCase
$city = City::factory()->create();
$edarateShari = EdarateShahri::factory()->create();
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
$user = User::factory()
->has(Permission::factory([
@@ -461,7 +501,8 @@ class StoreTest extends TestCase
'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
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
InfoItem::factory()->create([
@@ -483,6 +524,7 @@ class StoreTest extends TestCase
$city = City::factory()->create();
$edarateShari = EdarateShahri::factory()->create();
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
$user = User::factory()
->has(Permission::factory([
@@ -500,7 +542,8 @@ class StoreTest extends TestCase
'amount' => $this->faker->numberBetween(1, 10),
'activity_date' => $this->faker->date(),
'activity_time' => $this->faker->date('H:i'),
'cmms_machine_id' => $cmmsMachine->id
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
InfoItem::factory()->create([
@@ -522,6 +565,7 @@ class StoreTest extends TestCase
$city = City::factory()->create();
$edarateShari = EdarateShahri::factory()->create();
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
$user = User::factory()
->has(Permission::factory([
@@ -539,7 +583,8 @@ class StoreTest extends TestCase
'amount' => $this->faker->numberBetween(1, 10),
'activity_date' => $this->faker->date(),
'activity_time' => $this->faker->date('H:i'),
'cmms_machine_id' => $cmmsMachine->id
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
InfoItem::factory()->create([
@@ -562,6 +607,7 @@ class StoreTest extends TestCase
$province = Province::factory()->create();
$edarateShari = EdarateShahri::factory()->create();
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
LogList::factory()->create([
'log_unique_code' => 1154
@@ -595,7 +641,8 @@ class StoreTest extends TestCase
'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
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
$infoItem = InfoItem::factory()->create([
@@ -625,7 +672,9 @@ class StoreTest extends TestCase
'status_fa' => 'در حال بررسی',
'edarat_id' => $user->edarate_shahri_id,
'cmms_machine_id' => $cmmsMachine->id,
'cmms_machine_code' => $cmmsMachine->machine_code
'cmms_machine_code' => $cmmsMachine->machine_code,
'rahdar_id' => $rahdar->id,
'rahdar_code' => $rahdar->code
]);
$this->assertDatabaseHas('user_activity_logs', [

View File

@@ -0,0 +1,97 @@
<?php
namespace Tests\Feature\V3\RoadItemsProject;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class SupervisorIndexTest extends TestCase
{
use RefreshDatabase, WithFaker;
/**
* A basic feature test example.
*/
public function test_user_should_have_show_road_item_supervise_cartable_permission(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->getJson(route('v3.road_items.supervisorIndex'));
$response->assertForbidden();
}
public function test_operator_can_see_the_data_table(): void
{
$user = User::factory()
->has(Permission::factory([
'name' => 'create-road-item'
]))
->create();
RoadItemsProject::factory(10)->create();
$response = $this->actingAs($user)->getJson(route('v3.road_items.operatorIndex', [
'size' => 10,
'start' => 0,
'sorting' => json_encode([]),
'filters' => json_encode([]),
]));
$response->assertOk();
$response->assertJsonStructure([
'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",
],
]
]);
}
}

View File

@@ -2,28 +2,67 @@
namespace Tests\Feature\V3\RoadItemsProject;
use App\Models\City;
use App\Models\CMMSMachine;
use App\Models\EdarateShahri;
use App\Models\InfoItem;
use App\Models\LogList;
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;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Mockery\MockInterface;
use Tests\TestCase;
class UpdateTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_road_item_should_belong_to_the_user()
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route("v3.road_items.update", [$road_item->id]));
$response->assertForbidden();
}
public function test_road_item_status_must_be_2()
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 3
]);
$response = $this->actingAs($user)->postJson(route("v3.road_items.update", [$road_item->id]));
$response->assertForbidden();
}
public function test_start_point_is_required(): void
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route("v3.road_items.update", [$road_item->id]));
dd($response);
$response->assertUnprocessable()
->assertInvalid([
'start_point' => __('validation.required', ['attribute' => 'start point'])
@@ -34,7 +73,10 @@ class UpdateTest extends TestCase
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]));
@@ -48,7 +90,10 @@ class UpdateTest extends TestCase
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'amount' => $this->faker->name
@@ -64,7 +109,10 @@ class UpdateTest extends TestCase
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'before_image' => $this->faker->name
@@ -81,7 +129,10 @@ class UpdateTest extends TestCase
$user = User::factory()->create();
$image = UploadedFile::fake()->create('image.jpg', 5096);
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'before_image' => $image
@@ -97,7 +148,10 @@ class UpdateTest extends TestCase
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'after_image' => $this->faker->randomNumber()
@@ -114,7 +168,10 @@ class UpdateTest extends TestCase
$user = User::factory()->create();
$image = UploadedFile::fake()->create('image.jpg', 5096);
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'after_image' => $image
@@ -130,13 +187,16 @@ class UpdateTest extends TestCase
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]));
$response->assertUnprocessable()
->assertInvalid([
'cmms_machine_id' => __('validation.required', ['attribute' => 'cmms machine id'])
'cmms_machine_id' => __('validation.required', ['attribute' => 'کد یکتا ماشین'])
]);
}
@@ -144,7 +204,10 @@ class UpdateTest extends TestCase
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'cmms_machine_id' => $this->faker->numberBetween(10, 100)
@@ -152,7 +215,103 @@ class UpdateTest extends TestCase
$response->assertUnprocessable()
->assertInvalid([
'cmms_machine_id' => __('validation.exists', ['attribute' => 'cmms machine id'])
'cmms_machine_id' => __('validation.exists', ['attribute' => 'کد یکتا ماشین'])
]);
}
public function test_rahdar_id_is_required(): void
{
$user = User::factory()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]));
$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()->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
'rahdar_id' => $this->faker->numberBetween(10, 100)
]);
$response->assertUnprocessable()
->assertInvalid([
'rahdar_id' => __('validation.exists', ['attribute' => 'rahdar id'])
]);
}
public function test_can_update_the_road_item_project(): void
{
$cmmsMachine = CMMSMachine::factory()->create();
$rahdar = Rahdaran::factory()->create();
LogList::factory()->create([
'log_unique_code' => 1155
]);
UserActivityLog::factory()->create();
$user = User::factory()
->has(Permission::factory([
'name' => 'create-road-item'
]))
->create();
$road_item = RoadItemsProject::factory()->create([
'user_id' => $user->id,
'status' => 2,
'item' => $this->faker->numberBetween(1, 10),
'sub_item' => $this->faker->numberBetween(1, 10),
]);
Storage::fake('public');
$data = [
'start_point' => '12,12',
'amount' => $this->faker->numberBetween(1, 10),
'cmms_machine_id' => $cmmsMachine->id,
'rahdar_id' => $rahdar->id,
];
$infoItem = InfoItem::factory()->create([
'item' => $road_item ->item,
'sub_item' => $road_item ->sub_item,
]);
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), $data);
$response->assertOk()
->assertExactJson([
'message' => __('messages.successful')
]);
$this->assertDatabaseHas('road_items_projects', [
'start_lat' => 12,
'start_lng' => 12,
'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' => 1155,
]);
}
}