Merge branch 'feature/V3Tests' into 'develop'
Feature/v3 tests See merge request witelgroup/rms_v2!46
This commit is contained in:
@@ -317,7 +317,7 @@ class RoadItemsProjectController extends Controller
|
|||||||
|
|
||||||
$road_item = RoadItemsProject::store(Auth::user(), $attributes, $before_image, $after_image, $request->observed_item_id);
|
$road_item = RoadItemsProject::store(Auth::user(), $attributes, $before_image, $after_image, $request->observed_item_id);
|
||||||
|
|
||||||
if ($road_item == -1) {
|
if ($road_item === -1) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||||
], 400);
|
], 400);
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ class RoadPatrolProjectController extends Controller
|
|||||||
|
|
||||||
$road_item = RoadItemsProject::store(auth()->user(), $attributes, $before_image, $after_image, $observed_item->id);
|
$road_item = RoadItemsProject::store(auth()->user(), $attributes, $before_image, $after_image, $observed_item->id);
|
||||||
|
|
||||||
if ($road_item == -1) {
|
if ($road_item === -1) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||||
], 400);
|
], 400);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class CMMSMachinesController extends Controller
|
|||||||
|
|
||||||
public function list(): JsonResponse
|
public function list(): JsonResponse
|
||||||
{
|
{
|
||||||
$machinesList = CMMSMachine::query()->get(['machine_code']);
|
$machinesList = CMMSMachine::query()->get(['machine_code', 'id']);
|
||||||
|
|
||||||
return $this->successResponse($machinesList);
|
return $this->successResponse($machinesList);
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ class CMMSMachinesController extends Controller
|
|||||||
{
|
{
|
||||||
$matchedSearchedMachines = CMMSMachine::query()
|
$matchedSearchedMachines = CMMSMachine::query()
|
||||||
->where('machine_code', 'LIKE', "%{$request->machine_code}%")
|
->where('machine_code', 'LIKE', "%{$request->machine_code}%")
|
||||||
->get();
|
->get(['machine_code', 'id']);
|
||||||
|
|
||||||
return $this->successResponse($matchedSearchedMachines);
|
return $this->successResponse($matchedSearchedMachines);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ class RoadItemsProjectController extends Controller
|
|||||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
||||||
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
||||||
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
||||||
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time'
|
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time',
|
||||||
|
'cmms_machine_id', 'cmms_machine_code'
|
||||||
);
|
);
|
||||||
|
|
||||||
$allowedFilters = $columns;
|
$allowedFilters = $columns;
|
||||||
@@ -49,14 +50,14 @@ class RoadItemsProjectController extends Controller
|
|||||||
$query = null;
|
$query = null;
|
||||||
|
|
||||||
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
||||||
$query = RoadItemsProject::query()->where('is_new', 1)->with('files');
|
$query = RoadItemsProject::query()->where('is_new', 1)->with('files', 'rahdaran:id,name,code');
|
||||||
}
|
}
|
||||||
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
|
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
|
||||||
if (is_null($user->province_id)) {
|
if (is_null($user->province_id)) {
|
||||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||||
}
|
}
|
||||||
$query = RoadItemsProject::query()->where('is_new', 1)
|
$query = RoadItemsProject::query()->where('is_new', 1)
|
||||||
->with('files')->where('province_id', auth()->user()->province_id);
|
->with('files', 'rahdaran:id,name,code')->where('province_id', auth()->user()->province_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = DataTableFacade::run(
|
$data = DataTableFacade::run(
|
||||||
@@ -65,6 +66,15 @@ class RoadItemsProjectController extends Controller
|
|||||||
allowedFilters: $allowedFilters,
|
allowedFilters: $allowedFilters,
|
||||||
allowedSortings: $allowedSortings);
|
allowedSortings: $allowedSortings);
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($data['data'] as $road_item) {
|
||||||
|
if (Gate::allows('gate-supervise-road-item', $road_item)) {
|
||||||
|
$road_item['can_supervise'] = 1;
|
||||||
|
} else {
|
||||||
|
$road_item['can_supervise'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,13 +147,14 @@ class RoadItemsProjectController extends Controller
|
|||||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
||||||
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
||||||
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
||||||
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time'
|
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time',
|
||||||
|
'cmms_machine_id', 'cmms_machine_code'
|
||||||
);
|
);
|
||||||
|
|
||||||
$allowedFilters = $columns;
|
$allowedFilters = $columns;
|
||||||
$allowedSortings = $columns;
|
$allowedSortings = $columns;
|
||||||
|
|
||||||
$query = RoadItemsProject::with('files')
|
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code'])
|
||||||
->where('is_new', 1)
|
->where('is_new', 1)
|
||||||
->where('user_id', auth()->user()->id);
|
->where('user_id', auth()->user()->id);
|
||||||
|
|
||||||
@@ -196,7 +207,6 @@ class RoadItemsProjectController extends Controller
|
|||||||
$start_coordinates = explode(',', $request->start_point);
|
$start_coordinates = explode(',', $request->start_point);
|
||||||
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
||||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
||||||
$rahdar = Rahdaran::query()->find($request->rahdar_id);
|
|
||||||
|
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'start_lat' => $start_coordinates[0],
|
'start_lat' => $start_coordinates[0],
|
||||||
@@ -227,8 +237,6 @@ class RoadItemsProjectController extends Controller
|
|||||||
'activity_time' => $request->activity_time,
|
'activity_time' => $request->activity_time,
|
||||||
'cmms_machine_id' => $cmmsMachine->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,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
||||||
@@ -241,11 +249,14 @@ class RoadItemsProjectController extends Controller
|
|||||||
|
|
||||||
$road_item = RoadItemsProject::store($user, $attributes, $before_image, $after_image, $request->observed_item_id);
|
$road_item = RoadItemsProject::store($user, $attributes, $before_image, $after_image, $request->observed_item_id);
|
||||||
|
|
||||||
if ($road_item == -1) {
|
if ($road_item === -1) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$road_item->rahdaran()->attach($request->rahdaran_id);
|
||||||
|
|
||||||
auth()->user()->addActivityComplete(1154);
|
auth()->user()->addActivityComplete(1154);
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
@@ -275,7 +286,6 @@ class RoadItemsProjectController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
||||||
$rahdar = Rahdaran::query()->find($request->rahdar_id);
|
|
||||||
|
|
||||||
if ($info_item->needs_image) {
|
if ($info_item->needs_image) {
|
||||||
if ($request->has('after_image')) {
|
if ($request->has('after_image')) {
|
||||||
@@ -313,10 +323,10 @@ class RoadItemsProjectController extends Controller
|
|||||||
'status_fa' => 'در حال بررسی',
|
'status_fa' => 'در حال بررسی',
|
||||||
'cmms_machine_id' => $cmmsMachine->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,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$roadItemsProject->rahdaran()->sync($request->rahdaran_id);
|
||||||
|
|
||||||
|
|
||||||
auth()->user()->addActivityComplete(1155);
|
auth()->user()->addActivityComplete(1155);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ class StoreRequest extends FormRequest
|
|||||||
'before_image' => 'image|max:4096',
|
'before_image' => 'image|max:4096',
|
||||||
'after_image' => 'image|max:4096',
|
'after_image' => 'image|max:4096',
|
||||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
||||||
'rahdar_id' => 'required|exists:rahdaran,id',
|
'rahdaran_id' => 'required|array',
|
||||||
|
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ class UpdateRequest extends FormRequest
|
|||||||
'before_image' => 'image|max:4096',
|
'before_image' => 'image|max:4096',
|
||||||
'after_image' => 'image|max:4096',
|
'after_image' => 'image|max:4096',
|
||||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
||||||
'rahdar_id' => 'required|exists:rahdaran,id',
|
'rahdaran_id' => 'required|array',
|
||||||
|
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class VerifyBySupervisorRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return Gate::allows('gate-supervise-road-item', $this->road_item);
|
return Gate::allows('gate-supervise-road-item', $this->roadItemsProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
|
||||||
class Rahdaran extends Model
|
class Rahdaran extends Model
|
||||||
{
|
{
|
||||||
@@ -11,4 +12,10 @@ class Rahdaran extends Model
|
|||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
protected $table = 'rahdaran';
|
protected $table = 'rahdaran';
|
||||||
|
protected $hidden = ['pivot'];
|
||||||
|
|
||||||
|
public function roadItemsProject(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(RoadItemsProject::class,'rahdaran_road_items_project');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
|
||||||
class RoadItemsProject extends Model
|
class RoadItemsProject extends Model
|
||||||
{
|
{
|
||||||
@@ -55,8 +56,6 @@ class RoadItemsProject extends Model
|
|||||||
'activity_date_time',
|
'activity_date_time',
|
||||||
'cmms_machine_id',
|
'cmms_machine_id',
|
||||||
'cmms_machine_code',
|
'cmms_machine_code',
|
||||||
'rahdar_id',
|
|
||||||
'rahdar_code',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,7 +100,6 @@ class RoadItemsProject extends Model
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$road_item = \DB::transaction(function () use ($user, $attributes, $before_image, $after_image, $observed_item_id) {
|
$road_item = \DB::transaction(function () use ($user, $attributes, $before_image, $after_image, $observed_item_id) {
|
||||||
// dd($attributes['cmms_machine_id'],$attributes['cmms_machine_code']);
|
|
||||||
$road_item = $user->roadItemsProjects()->create([
|
$road_item = $user->roadItemsProjects()->create([
|
||||||
'start_lat' => $attributes['start_lat'],
|
'start_lat' => $attributes['start_lat'],
|
||||||
'start_lng' => $attributes['start_lng'],
|
'start_lng' => $attributes['start_lng'],
|
||||||
@@ -132,10 +130,8 @@ class RoadItemsProject extends Model
|
|||||||
'activity_time' => $attributes['activity_time'],
|
'activity_time' => $attributes['activity_time'],
|
||||||
'activity_date_time' => $attributes['activity_date']." ".$attributes['activity_time'],
|
'activity_date_time' => $attributes['activity_date']." ".$attributes['activity_time'],
|
||||||
'is_new' => 1,
|
'is_new' => 1,
|
||||||
'cmms_machine_id' => $attributes['cmms_machine_id'],
|
'cmms_machine_id' => $attributes['cmms_machine_id'] ?? null,
|
||||||
'cmms_machine_code' => $attributes['cmms_machine_code'],
|
'cmms_machine_code' => $attributes['cmms_machine_code'] ?? null,
|
||||||
'rahdar_id' => $attributes['rahdar_id'],
|
|
||||||
'rahdar_code' => $attributes['rahdar_code'],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// if ($info_item->needs_image) {
|
// if ($info_item->needs_image) {
|
||||||
@@ -165,7 +161,7 @@ class RoadItemsProject extends Model
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return $road_item;
|
||||||
});
|
});
|
||||||
|
|
||||||
return $road_item;
|
return $road_item;
|
||||||
@@ -173,4 +169,9 @@ class RoadItemsProject extends Model
|
|||||||
throw $th;
|
throw $th;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rahdaran(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Rahdaran::class,'rahdaran_road_items_project');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
<?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');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?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::create('rahdaran_road_items_project', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('rahdaran_id')->constrained('rahdaran')->onDelete('cascade');
|
||||||
|
$table->unsignedBigInteger('road_items_project_id');
|
||||||
|
$table->foreign('road_items_project_id')->references('id')->on('road_items_projects')->onDelete('cascade');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('rahdaran_road_items_project');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -118,7 +118,7 @@ Route::prefix('road_items')
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('cmms_machines')
|
Route::prefix('cmms_machines')
|
||||||
->name('cmms_machines')
|
->name('cmms_machines.')
|
||||||
->controller(CMMSMachinesController::class)
|
->controller(CMMSMachinesController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/list', 'list')->name('list');
|
Route::get('/list', 'list')->name('list');
|
||||||
@@ -126,7 +126,7 @@ Route::prefix('cmms_machines')
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('rahdaran')
|
Route::prefix('rahdaran')
|
||||||
->name('rahdaran')
|
->name('rahdaran.')
|
||||||
->controller(RahdaranController::class)
|
->controller(RahdaranController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/list', 'list')->name('list');
|
Route::get('/list', 'list')->name('list');
|
||||||
|
|||||||
36
tests/Feature/V3/CMMSMachine/ListTest.php
Normal file
36
tests/Feature/V3/CMMSMachine/ListTest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\CMMSMachine;
|
||||||
|
|
||||||
|
use App\Models\CMMSMachine;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ListTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_machine_code_list_return_successfully(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
CMMSMachine::factory(5)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.cmms_machines.list'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
"machine_code",
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
tests/Feature/V3/CMMSMachine/SearchTest.php
Normal file
35
tests/Feature/V3/CMMSMachine/SearchTest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\CMMSMachine;
|
||||||
|
|
||||||
|
use App\Models\CMMSMachine;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SearchTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_can_search_through_machine_codes(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$machine = CMMSMachine::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.cmms_machines.search', [$machine->machine_code]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
"machine_code",
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
tests/Feature/V3/Rahdaran/ListTest.php
Normal file
36
tests/Feature/V3/Rahdaran/ListTest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Rahdaran;
|
||||||
|
|
||||||
|
use App\Models\Rahdaran;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ListTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_machine_code_list_return_successfully(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
Rahdaran::factory(5)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.rahdaran.list'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
"name",
|
||||||
|
"code",
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
tests/Feature/V3/Rahdaran/SearchTest.php
Normal file
36
tests/Feature/V3/Rahdaran/SearchTest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Rahdaran;
|
||||||
|
|
||||||
|
use App\Models\Rahdaran;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SearchTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_can_search_through_rahdaran_codes(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$rahdar = Rahdaran::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.cmms_machines.search', [$rahdar->code]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
"name",
|
||||||
|
"code",
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,17 +24,17 @@ class SupervisorIndexTest extends TestCase
|
|||||||
$response->assertForbidden();
|
$response->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_operator_can_see_the_data_table(): void
|
public function test_supervisor_can_see_the_data_table(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()
|
$user = User::factory()
|
||||||
->has(Permission::factory([
|
->has(Permission::factory([
|
||||||
'name' => 'create-road-item'
|
'name' => 'show-road-item-supervise-cartable'
|
||||||
]))
|
]))
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
RoadItemsProject::factory(10)->create();
|
RoadItemsProject::factory(10)->create();
|
||||||
|
|
||||||
$response = $this->actingAs($user)->getJson(route('v3.road_items.operatorIndex', [
|
$response = $this->actingAs($user)->getJson(route('v3.road_items.supervisorIndex', [
|
||||||
'size' => 10,
|
'size' => 10,
|
||||||
'start' => 0,
|
'start' => 0,
|
||||||
'sorting' => json_encode([]),
|
'sorting' => json_encode([]),
|
||||||
@@ -90,6 +90,7 @@ class SupervisorIndexTest extends TestCase
|
|||||||
"cmms_machine_code",
|
"cmms_machine_code",
|
||||||
"rahdar_id",
|
"rahdar_id",
|
||||||
"rahdar_code",
|
"rahdar_code",
|
||||||
|
"can_supervise",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user