Merge branch 'feature/AddRahdarIdToRoadItems' into 'develop'
add rahdar id to road item project See merge request witelgroup/rms_v2!44
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Http\Traits\ApiResponse;
|
||||
use App\Models\CMMSMachine;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\Rahdaran;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Services\NominatimService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -195,6 +196,7 @@ class RoadItemsProjectController extends Controller
|
||||
$start_coordinates = explode(',', $request->start_point);
|
||||
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
||||
$rahdar = Rahdaran::query()->find($request->rahdar_id);
|
||||
|
||||
$attributes = [
|
||||
'start_lat' => $start_coordinates[0],
|
||||
@@ -225,6 +227,8 @@ class RoadItemsProjectController extends Controller
|
||||
'activity_time' => $request->activity_time,
|
||||
'cmms_machine_id' => $cmmsMachine->id,
|
||||
'cmms_machine_code' => $cmmsMachine->machine_code,
|
||||
'rahdar_id' => $rahdar->id,
|
||||
'rahdar_code' => $rahdar->code,
|
||||
];
|
||||
|
||||
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
||||
@@ -271,6 +275,7 @@ class RoadItemsProjectController extends Controller
|
||||
}
|
||||
|
||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
||||
$rahdar = Rahdaran::query()->find($request->rahdar_id);
|
||||
|
||||
if ($info_item->needs_image) {
|
||||
if ($request->has('after_image')) {
|
||||
@@ -308,6 +313,8 @@ class RoadItemsProjectController extends Controller
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'cmms_machine_id' => $cmmsMachine->id,
|
||||
'cmms_machine_code' => $cmmsMachine->machine_code,
|
||||
'rahdar_id' => $rahdar->id,
|
||||
'rahdar_code' => $rahdar->code,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class StoreRequest extends FormRequest
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
||||
'rahdar_id' => 'required|exists:rahdaran,id',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ class UpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return !($this->road_item->user_id != auth()->user()->id || $this->road_item->status != 2);
|
||||
return !($this->roadItemsProject->user_id != auth()->user()->id || $this->roadItemsProject->status != 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,6 +32,7 @@ class UpdateRequest extends FormRequest
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
||||
'rahdar_id' => 'required|exists:rahdaran,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ class RoadItemsProject extends Model
|
||||
'activity_date_time',
|
||||
'cmms_machine_id',
|
||||
'cmms_machine_code',
|
||||
'rahdar_id',
|
||||
'rahdar_code',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -132,6 +134,8 @@ class RoadItemsProject extends Model
|
||||
'is_new' => 1,
|
||||
'cmms_machine_id' => $attributes['cmms_machine_id'],
|
||||
'cmms_machine_code' => $attributes['cmms_machine_code'],
|
||||
'rahdar_id' => $attributes['rahdar_id'],
|
||||
'rahdar_code' => $attributes['rahdar_code'],
|
||||
]);
|
||||
|
||||
// if ($info_item->needs_image) {
|
||||
|
||||
@@ -17,7 +17,8 @@ class RahdaranFactory extends Factory
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
'name' => fake()->name,
|
||||
'code' => fake()->numerify,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('road_items_projects', function (Blueprint $table) {
|
||||
$table->foreignId('rahdar_id')->nullable()->constrained('rahdaran');
|
||||
$table->string('rahdar_code')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('road_items_projects', function (Blueprint $table) {
|
||||
$table->dropForeign(['rahdar_id']);
|
||||
$table->dropColumn('rahdar_id');
|
||||
$table->dropColumn('rahdar_code');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Rahdaran;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -12,6 +13,6 @@ class RahdaranSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
Rahdaran::factory(5)->create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,14 +87,14 @@ Route::prefix('road_items')
|
||||
->middleware(['permission:show-road-item-supervise-cartable|show-road-item-supervise-cartable-province'])
|
||||
->name('supervisorIndex');
|
||||
|
||||
Route::post('/verify_by_supervisor/{$roadItemsProject}', 'VerifyBySupervisor')
|
||||
Route::post('/verify_by_supervisor/{roadItemsProject}', 'VerifyBySupervisor')
|
||||
->name('VerifyBySupervisor');
|
||||
|
||||
Route::post('/restore/{$roadItemsProject}', 'restore')
|
||||
Route::post('/restore/{roadItemsProject}', 'restore')
|
||||
->middleware('permission:restore-road-item')
|
||||
->name('restore');
|
||||
|
||||
Route::post('/delete/{$roadItemsProject}', 'delete')
|
||||
Route::post('/delete/{roadItemsProject}', 'delete')
|
||||
->middleware('permission:delete-road-item')
|
||||
->name('delete');
|
||||
|
||||
@@ -109,7 +109,7 @@ Route::prefix('road_items')
|
||||
->middleware('permission:create-road-item')
|
||||
->name('store');
|
||||
|
||||
Route::post('/update/{$roadItemsProject}', 'update')->name('update');
|
||||
Route::post('/update/{roadItemsProject}', 'update')->name('update');
|
||||
|
||||
Route::get('/operator_report', 'operatorCartableReport')
|
||||
->name('operatorCartableReport');
|
||||
|
||||
97
tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php
Normal file
97
tests/Feature/V3/RoadItemsProject/OperatorIndexTest.php
Normal 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",
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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', [
|
||||
|
||||
97
tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php
Normal file
97
tests/Feature/V3/RoadItemsProject/SupervisorIndexTest.php
Normal 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",
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user