transfer all api's from v2 road items to v3
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers\V3;
|
||||
|
||||
use App\Exports\V2\RoadItems\OperatorCartableExport;
|
||||
use App\Exports\V2\RoadItems\SupervisorCartableExport;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\RoadItemsProject\StoreRequest;
|
||||
use App\Http\Requests\V3\RoadItemsProject\UpdateRequest;
|
||||
use App\Http\Requests\V3\RoadItemsProject\VerifyBySupervisorRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\CMMSMachine;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\RoadItemsProject;
|
||||
@@ -20,6 +23,7 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadItemsProjectController extends Controller
|
||||
{
|
||||
@@ -63,12 +67,12 @@ class RoadItemsProjectController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadItemsProject $road_item): JsonResponse
|
||||
public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
$status_fa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید';
|
||||
$user = auth()->user();
|
||||
|
||||
$road_item->update([
|
||||
$roadItemsProject->update([
|
||||
'status' => $request->verify,
|
||||
'status_fa' => $status_fa,
|
||||
'supervisor_id' => $user->id,
|
||||
@@ -82,15 +86,15 @@ class RoadItemsProjectController extends Controller
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function restore(RoadItemsProject $road_item): JsonResponse
|
||||
public function restore(RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
if ($road_item->status == 0) {
|
||||
if ($roadItemsProject->status == 0) {
|
||||
return response()->json([
|
||||
'message' => 'امکان بازگردانی وضعیت این فعالیت وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$road_item->update([
|
||||
$roadItemsProject->update([
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'supervisor_id' => null,
|
||||
@@ -103,22 +107,22 @@ class RoadItemsProjectController extends Controller
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function delete(RoadItemsProject $road_item): JsonResponse
|
||||
public function delete(RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
if ($road_item->files()->exists()) {
|
||||
Storage::delete('public/'. $road_item->files[0]->path);
|
||||
Storage::delete('public/'. $road_item->files[1]->path);
|
||||
$road_item->files()->delete();
|
||||
if ($roadItemsProject->files()->exists()) {
|
||||
Storage::delete('public/'. $roadItemsProject->files[0]->path);
|
||||
Storage::delete('public/'. $roadItemsProject->files[1]->path);
|
||||
$roadItemsProject->files()->delete();
|
||||
}
|
||||
auth()->user()->addActivityComplete(1151);
|
||||
|
||||
$road_item->delete();
|
||||
$roadItemsProject->delete();
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
|
||||
public function supervisorCartableReport(Request $request)
|
||||
public function supervisorCartableReport(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(new SupervisorCartableExport($request->id, $request->item, $request->status,
|
||||
@@ -171,7 +175,7 @@ class RoadItemsProjectController extends Controller
|
||||
], 400);
|
||||
}
|
||||
|
||||
$info_item = InfoItem::where('item', $request->item_id)
|
||||
$info_item = InfoItem::query()->where('item', $request->item_id)
|
||||
->where('sub_item', $request->sub_item_id)
|
||||
->firstOrFail();
|
||||
|
||||
@@ -190,6 +194,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);
|
||||
|
||||
$attributes = [
|
||||
'start_lat' => $start_coordinates[0],
|
||||
@@ -218,6 +223,8 @@ class RoadItemsProjectController extends Controller
|
||||
'edarat_name' => $user->edarate_shahri_name,
|
||||
'activity_date' => $request->activity_date,
|
||||
'activity_time' => $request->activity_time,
|
||||
'cmms_machine_id' => $cmmsMachine->id,
|
||||
'cmms_machine_code' => $cmmsMachine->machine_code,
|
||||
];
|
||||
|
||||
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
||||
@@ -240,21 +247,14 @@ class RoadItemsProjectController extends Controller
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(Request $request, RoadItemsProject $road_item)
|
||||
public function update(UpdateRequest $request, RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
$info_item = InfoItem::where('item', $road_item->item)
|
||||
->where('sub_item', $road_item->sub_item)
|
||||
$info_item = InfoItem::query()->where('item', $roadItemsProject->item)
|
||||
->where('sub_item', $roadItemsProject->sub_item)
|
||||
->firstOrFail();
|
||||
|
||||
$start_coordinates = explode(',', $request->start_point);
|
||||
@@ -270,33 +270,35 @@ class RoadItemsProjectController extends Controller
|
||||
$end_coordinates = explode(',', $request->end_point);
|
||||
}
|
||||
|
||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
||||
|
||||
if ($info_item->needs_image) {
|
||||
if ($request->has('after_image')) {
|
||||
|
||||
Storage::delete('public/'. $road_item->files[0]->path);
|
||||
Storage::delete('public/'. $roadItemsProject->files[0]->path);
|
||||
|
||||
$after = $request->file('after_image')->store('road_items_projects_new/after', 'public');
|
||||
$road_item->files[0]->update([
|
||||
$roadItemsProject->files[0]->update([
|
||||
'path' => $after
|
||||
]);
|
||||
// $road_item->files()->create(['path' => $after]);
|
||||
// $roadItemsProject->files()->create(['path' => $after]);
|
||||
$urlAfter = "/var/www/rms/public/storage/{$after}";
|
||||
\App\Helpers\Compress::resize($urlAfter);
|
||||
}
|
||||
if ($request->has('before_image')) {
|
||||
Storage::delete('public/'. $road_item->files[1]->path);
|
||||
Storage::delete('public/'. $roadItemsProject->files[1]->path);
|
||||
|
||||
$before = $request->file('before_image')->store('/road_items_projects_new/before', 'public');
|
||||
$road_item->files[1]->update([
|
||||
$roadItemsProject->files[1]->update([
|
||||
'path' => $before
|
||||
]);
|
||||
// $road_item->files()->create(['path' => $before]);
|
||||
// $roadItemsProject->files()->create(['path' => $before]);
|
||||
$urlBefore = "/var/www/rms/public/storage/{$before}";
|
||||
\App\Helpers\Compress::resize($urlBefore);
|
||||
}
|
||||
}
|
||||
|
||||
$road_item->update([
|
||||
$roadItemsProject->update([
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
@@ -304,6 +306,8 @@ class RoadItemsProjectController extends Controller
|
||||
'sub_item_data' => $request->amount,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'cmms_machine_id' => $cmmsMachine->id,
|
||||
'cmms_machine_code' => $cmmsMachine->machine_code,
|
||||
]);
|
||||
|
||||
|
||||
@@ -311,4 +315,13 @@ class RoadItemsProjectController extends Controller
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل عملیات فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(
|
||||
new OperatorCartableExport($request->id, $request->item, $request->status, $request->fromDate, $request->toDate),
|
||||
$name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,10 @@ class Kernel extends HttpKernel
|
||||
'confirmUser' => \App\Http\Middleware\ConfirmUserMiddleware::class,
|
||||
'randd' => \App\Http\Middleware\RandDRedirectMiddleware::class,
|
||||
'log.route' => \App\Http\Middleware\LogRoute::class,
|
||||
'test' => \App\Http\Middleware\CsrfLoginDev::class
|
||||
'test' => \App\Http\Middleware\CsrfLoginDev::class,
|
||||
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
|
||||
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
|
||||
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ class StoreRequest extends FormRequest
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ class UpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return !($this->road_item->user_id != auth()->user()->id || $this->road_item->status != 2);
|
||||
return true;
|
||||
// return !($this->road_item->user_id != auth()->user()->id || $this->road_item->status != 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,6 +32,7 @@ class UpdateRequest extends FormRequest
|
||||
'amount' => 'required|numeric',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ class RoadItemsProject extends Model
|
||||
'activity_date',
|
||||
'activity_time',
|
||||
'activity_date_time',
|
||||
'cmms_machine_id',
|
||||
'cmms_machine_code',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -97,6 +99,7 @@ class RoadItemsProject extends Model
|
||||
{
|
||||
try {
|
||||
$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([
|
||||
'start_lat' => $attributes['start_lat'],
|
||||
'start_lng' => $attributes['start_lng'],
|
||||
@@ -127,7 +130,8 @@ class RoadItemsProject extends Model
|
||||
'activity_time' => $attributes['activity_time'],
|
||||
'activity_date_time' => $attributes['activity_date']." ".$attributes['activity_time'],
|
||||
'is_new' => 1,
|
||||
|
||||
'cmms_machine_id' => $attributes['cmms_machine_id'],
|
||||
'cmms_machine_code' => $attributes['cmms_machine_code'],
|
||||
]);
|
||||
|
||||
// if ($info_item->needs_image) {
|
||||
|
||||
@@ -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::table('road_items_projects', function (Blueprint $table) {
|
||||
$table->foreignId('cmms_machine_id')->nullable()->constrained('cmms_machines');
|
||||
$table->string('cmms_machine_code')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('road_items_projects', function (Blueprint $table) {
|
||||
$table->dropColumn('cmms_machine_id');
|
||||
$table->dropColumn('cmms_machine_code');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -200,5 +200,6 @@ return [
|
||||
'fields.*.unit' => 'واحد فیلد',
|
||||
'fields.*.type' => 'نوع فیلد',
|
||||
'fields.*.option' => 'گزینه های فیلد',
|
||||
'cmms_machine_id' => 'کد یکتا ماشین',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -41,21 +41,20 @@ Route::prefix('profile')
|
||||
|
||||
Route::prefix('azmayesh_types')
|
||||
->name('azmayesh_types.')
|
||||
->middleware('can:azmayesh-type-management')
|
||||
->controller(AzmayeshTypeController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('/list', 'list')->name('list')->middleware('can:azmayesh-management');
|
||||
Route::get('/fields/{azmayeshType}', 'fields')->name('fields');
|
||||
Route::get('/{azmayeshType}', 'show')->name('show');
|
||||
Route::post('/store', 'store')->name('store');
|
||||
Route::post('/update/{azmayeshType}', 'update')->name('update');
|
||||
Route::post('/delete/{azmayeshType}', 'destroy')->name('delete');
|
||||
Route::get('/', 'index')->middleware('permission:azmayesh-type-management')->name('index');
|
||||
Route::get('/list', 'list')->middleware(['permission:azmayesh-type-management|azmayesh-management'])->name('list');
|
||||
Route::get('/fields/{azmayeshType}', 'fields')->middleware('permission:azmayesh-type-management')->name('fields');
|
||||
Route::get('/{azmayeshType}', 'show')->middleware('permission:azmayesh-type-management')->name('show');
|
||||
Route::post('/store', 'store')->middleware('permission:azmayesh-type-management')->name('store');
|
||||
Route::post('/update/{azmayeshType}', 'update')->middleware('permission:azmayesh-type-management')->name('update');
|
||||
Route::post('/delete/{azmayeshType}', 'destroy')->middleware('permission:azmayesh-type-management')->name('delete');
|
||||
});
|
||||
|
||||
Route::prefix('azmayesh_samples')
|
||||
->name('azmayesh_samples.')
|
||||
->middleware('can:azmayesh-management')
|
||||
->middleware('permission:azmayesh-management')
|
||||
->controller(AzmayeshSampleController::class)
|
||||
->group(function () {
|
||||
Route::get('/index/{azmayesh_id}', 'index')->name('index');
|
||||
@@ -67,7 +66,7 @@ Route::prefix('azmayesh_samples')
|
||||
|
||||
Route::prefix('azmayeshes')
|
||||
->name('azmayeshes.')
|
||||
->middleware('can:azmayesh-management')
|
||||
->middleware('permission:azmayesh-management')
|
||||
->controller(AzmayeshController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
@@ -83,23 +82,35 @@ Route::prefix('road_items')
|
||||
->name('road_items.')
|
||||
->controller(RoadItemsProjectController::class)
|
||||
->group(function () {
|
||||
|
||||
Route::get('/supervisor_index', 'supervisorIndex')
|
||||
->middleware(['can:show-road-item-supervise-cartable', 'can:show-road-item-supervise-cartable-province'])
|
||||
->middleware(['permission:show-road-item-supervise-cartable|show-road-item-supervise-cartable-province'])
|
||||
->name('supervisorIndex');
|
||||
Route::post('/verify_by_supervisor/{$road_item}', 'VerifyBySupervisor')
|
||||
|
||||
Route::post('/verify_by_supervisor/{$roadItemsProject}', 'VerifyBySupervisor')
|
||||
->name('VerifyBySupervisor');
|
||||
Route::post('/restore/{$road_item}', 'restore')
|
||||
->middleware('can:restore-road-item')
|
||||
|
||||
Route::post('/restore/{$roadItemsProject}', 'restore')
|
||||
->middleware('permission:restore-road-item')
|
||||
->name('restore');
|
||||
Route::post('/delete/{$road_item}', 'delete')
|
||||
->middleware('can:delete-road-item')
|
||||
|
||||
Route::post('/delete/{$roadItemsProject}', 'delete')
|
||||
->middleware('permission:delete-road-item')
|
||||
->name('delete');
|
||||
|
||||
Route::get('/supervisor_report', 'supervisorCartableReport')
|
||||
->name('supervisorCartableReport');
|
||||
|
||||
Route::get('/operator_index', 'operatorIndex')
|
||||
->middleware('can:create-road-item')
|
||||
->middleware('permission:create-road-item')
|
||||
->name('operatorIndex');
|
||||
|
||||
Route::post('/store', 'store')
|
||||
->middleware('can:create-road-item')
|
||||
->middleware('permission:create-road-item')
|
||||
->name('store');
|
||||
Route::post('/', 'update')->name('update');
|
||||
Route::post('/', 'destroy')->name('delete');
|
||||
|
||||
Route::post('/update/{$roadItemsProject}', 'update')->name('update');
|
||||
|
||||
Route::get('/operator_report', 'operatorCartableReport')
|
||||
->name('operatorCartableReport');
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\V3\RoadItemsProject;
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\CMMSMachine;
|
||||
use App\Models\EdarateOstani;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
@@ -336,9 +337,44 @@ class StoreTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
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' => 'cmms machine id'])
|
||||
]);
|
||||
}
|
||||
|
||||
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' => 'cmms machine id'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_province_user_is_prohibited_to_access(): void
|
||||
{
|
||||
$edarateOstani = EdarateOstani::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -356,7 +392,8 @@ class StoreTest extends TestCase
|
||||
'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)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data);
|
||||
@@ -370,6 +407,7 @@ class StoreTest extends TestCase
|
||||
public function test_user_should_have_edarate_shahri_id(): void
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -387,7 +425,8 @@ class StoreTest extends TestCase
|
||||
'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)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.store'), $data);
|
||||
@@ -402,6 +441,7 @@ class StoreTest extends TestCase
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -420,7 +460,8 @@ class StoreTest extends TestCase
|
||||
'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)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
InfoItem::factory()->create([
|
||||
@@ -441,6 +482,7 @@ class StoreTest extends TestCase
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -458,6 +500,7 @@ 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
|
||||
];
|
||||
|
||||
InfoItem::factory()->create([
|
||||
@@ -478,6 +521,7 @@ class StoreTest extends TestCase
|
||||
{
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
@@ -495,6 +539,7 @@ 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
|
||||
];
|
||||
|
||||
InfoItem::factory()->create([
|
||||
@@ -516,6 +561,7 @@ class StoreTest extends TestCase
|
||||
$city = City::factory()->create();
|
||||
$province = Province::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$cmmsMachine = CMMSMachine::factory()->create();
|
||||
|
||||
LogList::factory()->create([
|
||||
'log_unique_code' => 1154
|
||||
@@ -548,7 +594,8 @@ class StoreTest extends TestCase
|
||||
'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)
|
||||
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
|
||||
'cmms_machine_id' => $cmmsMachine->id
|
||||
];
|
||||
|
||||
$infoItem = InfoItem::factory()->create([
|
||||
@@ -577,6 +624,14 @@ class StoreTest extends TestCase
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'cmms_machine_id' => $cmmsMachine->id,
|
||||
'cmms_machine_code' => $cmmsMachine->machine_code
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('user_activity_logs', [
|
||||
'user_id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'log_unique_code' => 1154,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
158
tests/Feature/V3/RoadItemsProject/UpdateTest.php
Normal file
158
tests/Feature/V3/RoadItemsProject/UpdateTest.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?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 Illuminate\Http\UploadedFile;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
|
||||
public function test_start_point_is_required(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$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'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_amount_is_required(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]));
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'amount' => __('validation.required', ['attribute' => 'amount'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_amount_should_be_numeric(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
||||
'amount' => $this->faker->name
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'amount' => __('validation.numeric', ['attribute' => 'amount'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_before_image_should_be_image(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
||||
'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()->create();
|
||||
|
||||
$image = UploadedFile::fake()->create('image.jpg', 5096);
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
||||
'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()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
||||
'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()->create();
|
||||
|
||||
$image = UploadedFile::fake()->create('image.jpg', 5096);
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
||||
'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()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$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'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cmms_machine_id_should_already_exists_on_the_table(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$road_item = RoadItemsProject::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('v3.road_items.update', [$road_item->id]), [
|
||||
'cmms_machine_id' => $this->faker->numberBetween(10, 100)
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'cmms_machine_id' => __('validation.exists', ['attribute' => 'cmms machine id'])
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user