Merge branch 'develop' into 'main'
merge Develop into Main See merge request witelgroup/rms_v2!33
This commit is contained in:
39
README.md
39
README.md
@@ -1,7 +1,11 @@
|
|||||||
|
|
||||||
# RMS (road management system)
|
# RMS (road management system)
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Dependencies](#dependencies)
|
||||||
|
|
||||||
|
<a name="dependencies"></a>
|
||||||
## Dependencies
|
## Dependencies
|
||||||
<details>
|
<details>
|
||||||
<summary>Server</summary>
|
<summary>Server</summary>
|
||||||
@@ -23,7 +27,9 @@
|
|||||||
<!-- GETTING STARTED -->
|
<!-- GETTING STARTED -->
|
||||||
## Prod Prerequisites
|
## Prod Prerequisites
|
||||||
apply bellow changes in order to set up the project on prod
|
apply bellow changes in order to set up the project on prod
|
||||||
### Database configuration
|
|
||||||
|
<img src="https://skillicons.dev/icons?i=dynamodb" width="50" style="vertical-align: middle;"/>**Database Configuration**</span>
|
||||||
|
|
||||||
optimize MariaDB configuration through this path
|
optimize MariaDB configuration through this path
|
||||||
```sh
|
```sh
|
||||||
/etc/mysql/mariadb.conf.d/50-server.cnf
|
/etc/mysql/mariadb.conf.d/50-server.cnf
|
||||||
@@ -50,10 +56,27 @@ avoid any timeout response
|
|||||||
```sh
|
```sh
|
||||||
/etc/nginx/sites_available/exmapl.com
|
/etc/nginx/sites_available/exmapl.com
|
||||||
```
|
```
|
||||||
| Variable | Value | Condtion | Context |
|
| Variable | Value | Condtion | Context |
|
||||||
|:---------------------------------:|:--------:|:------------------------------------------------------------------:|:-----------------------:|
|
|:---------------------:|:-----:|:------------:|:------------------------:|
|
||||||
| proxy_connect_timeout | `120` | no condition | `http, server, location`|
|
| proxy_connect_timeout | `120` | no condition | `http, server, location` |
|
||||||
| proxy_send_timeout | `120` | no condition | `http, server, location`|
|
| proxy_send_timeout | `120` | no condition | `http, server, location` |
|
||||||
| proxy_read_timeout | `120` | no condition | `http, server, location`|
|
| proxy_read_timeout | `120` | no condition | `http, server, location` |
|
||||||
| send_timeout | `120` | no condition | `http, server, location`|
|
| send_timeout | `120` | no condition | `http, server, location` |
|
||||||
| fastcgi_read_timeout | `300` | no condition | `location` |
|
| fastcgi_read_timeout | `300` | no condition | `location` |
|
||||||
|
| client_max_body_size | `10M` | no condition | `http` |
|
||||||
|
|
||||||
|
<img src="https://skillicons.dev/icons?i=php" width="50" style="vertical-align: middle;"/> **Configuration**</span>
|
||||||
|
|
||||||
|
change php.ini through this path
|
||||||
|
|
||||||
|
```sh
|
||||||
|
/etc/php/8.1/fpm/php.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
set this values
|
||||||
|
|
||||||
|
| Variable | Value | Condtion | Context |
|
||||||
|
|:-------------------:|:------:|:------------:|:-------------:|
|
||||||
|
| post_max_size | `24M` | no condition | fpm : php.ini |
|
||||||
|
| upload_max_filesize | `8M` | no condition | fpm : php.ini |
|
||||||
|
| max_exec_time | `120s` | no condition | fpm : php.ini |
|
||||||
125
app/Http/Controllers/V3/Azmayesh/AzmayeshController.php
Normal file
125
app/Http/Controllers/V3/Azmayesh/AzmayeshController.php
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Traits\ApiResponse;
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Province;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Requests\V3\Azmayesh\StoreRequest;
|
||||||
|
use App\Http\Requests\V3\Azmayesh\UpdateRequest;
|
||||||
|
|
||||||
|
class AzmayeshController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$columns = array(
|
||||||
|
'id',
|
||||||
|
'request_date',
|
||||||
|
'report_date',
|
||||||
|
'request_number',
|
||||||
|
'employer',
|
||||||
|
'contractor',
|
||||||
|
'work_number',
|
||||||
|
'consultant',
|
||||||
|
'applicant',
|
||||||
|
);
|
||||||
|
|
||||||
|
$allowedFilters = $columns;
|
||||||
|
$allowedSortings = $columns;
|
||||||
|
|
||||||
|
$query = Azmayesh::query();
|
||||||
|
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
$query,
|
||||||
|
$request,
|
||||||
|
allowedFilters: $allowedFilters,
|
||||||
|
allowedSortings: $allowedSortings);
|
||||||
|
|
||||||
|
return response()->json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*/
|
||||||
|
public function store(StoreRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id);
|
||||||
|
$province = Province::query()->findOrFail($request->province_id);
|
||||||
|
|
||||||
|
Azmayesh::query()->create([
|
||||||
|
'lat' => $request->lat,
|
||||||
|
'lng' => $request->lng,
|
||||||
|
'azmayesh_type_id' => $azmayeshType->id,
|
||||||
|
'azmayesh_type_name' => $azmayeshType->name,
|
||||||
|
'request_date' => $request->request_date,
|
||||||
|
'report_date' => $request->report_date,
|
||||||
|
'request_number' => $request->request_number ?? '-',
|
||||||
|
'employer' => $request->employer ?? '-',
|
||||||
|
'contractor' => $request->contractor ?? '-',
|
||||||
|
'work_number' => $request->work_number ?? '-',
|
||||||
|
'project_name' => $request->project_name,
|
||||||
|
'consultant' => $request->consultant ?? '-',
|
||||||
|
'applicant' => $request->applicant ?? '-',
|
||||||
|
'province_id' => $province->id,
|
||||||
|
'province_name' => $province->name_fa,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function show(Azmayesh $azmayesh): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($azmayesh->load('azmayeshSamples'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, Azmayesh $azmayesh): JsonResponse
|
||||||
|
{
|
||||||
|
$province = Province::query()->findOrFail($request->province_id);
|
||||||
|
$azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id);
|
||||||
|
|
||||||
|
$azmayesh->update([
|
||||||
|
'lat' => $request->lat,
|
||||||
|
'lng' => $request->lng,
|
||||||
|
'azmayesh_type_id' => $azmayeshType->id,
|
||||||
|
'azmayesh_type_name' => $azmayeshType->name,
|
||||||
|
'request_date' => $request->request_date,
|
||||||
|
'report_date' => $request->report_date,
|
||||||
|
'request_number' => $request->request_number ?? '-',
|
||||||
|
'employer' => $request->employer ?? '-',
|
||||||
|
'contractor' => $request->contractor ?? '-',
|
||||||
|
'work_number' => $request->work_number ?? '-',
|
||||||
|
'project_name' => $request->project_name,
|
||||||
|
'consultant' => $request->consultant ?? '-',
|
||||||
|
'applicant' => $request->applicant ?? '-',
|
||||||
|
'province_id' => $province->id,
|
||||||
|
'province_name' => $province->name_fa,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(Azmayesh $azmayesh): JsonResponse
|
||||||
|
{
|
||||||
|
$azmayesh->delete();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Traits\ApiResponse;
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\AzmayeshSample;
|
||||||
|
use App\Models\Province;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Requests\V3\AzmayeshSample\StoreRequest;
|
||||||
|
use App\Http\Requests\V3\AzmayeshSample\UpdateRequest;
|
||||||
|
|
||||||
|
class AzmayeshSampleController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index(Request $request, string $azmayesh_id): JsonResponse
|
||||||
|
{
|
||||||
|
$columns = array(
|
||||||
|
'id',
|
||||||
|
);
|
||||||
|
|
||||||
|
$allowedFilters = $columns;
|
||||||
|
$allowedSortings = $columns;
|
||||||
|
|
||||||
|
$query = AzmayeshSample::query()->where('azmayesh_id', '=', $azmayesh_id);
|
||||||
|
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
$query,
|
||||||
|
$request,
|
||||||
|
allowedFilters: $allowedFilters,
|
||||||
|
allowedSortings: $allowedSortings);
|
||||||
|
|
||||||
|
return response()->json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*/
|
||||||
|
public function store(StoreRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id);
|
||||||
|
|
||||||
|
AzmayeshSample::query()->create([
|
||||||
|
'azmayesh_id' => $azmayesh->id,
|
||||||
|
'azmayesh_project_name' => $azmayesh->project_name,
|
||||||
|
'data' => $request->data,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function show(AzmayeshSample $azmayeshSample): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($azmayeshSample);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, AzmayeshSample $azmayeshSample): JsonResponse
|
||||||
|
{
|
||||||
|
$azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id);
|
||||||
|
|
||||||
|
$azmayeshSample->update([
|
||||||
|
'azmayesh_id' => $azmayesh->id,
|
||||||
|
'azmayesh_project_name' => $azmayesh->project_name,
|
||||||
|
'data' => $request->data,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(AzmayeshSample $azmayeshSample): JsonResponse
|
||||||
|
{
|
||||||
|
$azmayeshSample->delete();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
116
app/Http/Controllers/V3/Azmayesh/AzmayeshTypeController.php
Normal file
116
app/Http/Controllers/V3/Azmayesh/AzmayeshTypeController.php
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\V3\AzmayeshType\StoreRequest;
|
||||||
|
use App\Http\Requests\V3\AzmayeshType\UpdateRequest;
|
||||||
|
use App\Http\Traits\ApiResponse;
|
||||||
|
use App\Models\AzmayeshField;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AzmayeshTypeController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$columns = array(
|
||||||
|
'id', 'name'
|
||||||
|
);
|
||||||
|
|
||||||
|
$allowedFilters = $columns;
|
||||||
|
$allowedSortings = $columns;
|
||||||
|
|
||||||
|
$query = AzmayeshType::query();
|
||||||
|
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
$query,
|
||||||
|
$request,
|
||||||
|
allowedFilters: $allowedFilters,
|
||||||
|
allowedSortings: $allowedSortings);
|
||||||
|
|
||||||
|
return response()->json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): JsonResponse
|
||||||
|
{
|
||||||
|
$allTypes = AzmayeshType::all();
|
||||||
|
|
||||||
|
return $this->successResponse($allTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(AzmayeshType $azmayeshType): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($azmayeshType->azmayeshFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request)
|
||||||
|
{
|
||||||
|
$azmayeshType = AzmayeshType::query()->create([
|
||||||
|
'name' => $request->name
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fieldsID = [];
|
||||||
|
|
||||||
|
foreach ($request->fields as $field)
|
||||||
|
{
|
||||||
|
$azmayeshField = AzmayeshField::query()->firstOrCreate($field, $field);
|
||||||
|
$fieldsID[] = $azmayeshField->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$azmayeshType->azmayeshFields()->attach($fieldsID);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function show(AzmayeshType $azmayeshType): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($azmayeshType->load(['azmayeshFields']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, AzmayeshType $azmayeshType): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request, $azmayeshType)
|
||||||
|
{
|
||||||
|
$azmayeshType->update([
|
||||||
|
'name' => $request->name
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fieldsID = [];
|
||||||
|
|
||||||
|
foreach ($request->fields as $field)
|
||||||
|
{
|
||||||
|
$azmayeshField = AzmayeshField::query()->updateOrCreate($field, $field);
|
||||||
|
$fieldsID[] = $azmayeshField->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$azmayeshType->azmayeshFields()->sync($fieldsID);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(AzmayeshType $azmayeshType): JsonResponse
|
||||||
|
{
|
||||||
|
$azmayeshType->delete();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
40
app/Http/Requests/V3/Azmayesh/StoreRequest.php
Normal file
40
app/Http/Requests/V3/Azmayesh/StoreRequest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\Azmayesh;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'lat' => 'required|string',
|
||||||
|
'lng' => 'required|string',
|
||||||
|
'azmayesh_type_id' => 'required|exists:azmayesh_types,id',
|
||||||
|
'request_date' => 'date',
|
||||||
|
'report_date' => 'date',
|
||||||
|
'request_number' => 'string',
|
||||||
|
'employer' => 'string',
|
||||||
|
'contractor' => 'string',
|
||||||
|
'work_number' => 'string',
|
||||||
|
'project_name' => 'required|string',
|
||||||
|
'consultant' => 'string',
|
||||||
|
'applicant' => 'string',
|
||||||
|
'province_id' => 'required|exists:provinces,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
40
app/Http/Requests/V3/Azmayesh/UpdateRequest.php
Normal file
40
app/Http/Requests/V3/Azmayesh/UpdateRequest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\Azmayesh;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'lat' => 'required|string',
|
||||||
|
'lng' => 'required|string',
|
||||||
|
'azmayesh_type_id' => 'required|exists:azmayesh_types,id',
|
||||||
|
'request_date' => 'date',
|
||||||
|
'report_date' => 'date',
|
||||||
|
'request_number' => 'string',
|
||||||
|
'employer' => 'string',
|
||||||
|
'contractor' => 'string',
|
||||||
|
'work_number' => 'string',
|
||||||
|
'project_name' => 'required|string',
|
||||||
|
'consultant' => 'string',
|
||||||
|
'applicant' => 'string',
|
||||||
|
'province_id' => 'required|exists:provinces,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Http/Requests/V3/AzmayeshSample/StoreRequest.php
Normal file
29
app/Http/Requests/V3/AzmayeshSample/StoreRequest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\AzmayeshSample;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'azmayesh_id' => 'required|exists:azmayeshes,id',
|
||||||
|
'data' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Http/Requests/V3/AzmayeshSample/UpdateRequest.php
Normal file
29
app/Http/Requests/V3/AzmayeshSample/UpdateRequest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\AzmayeshSample;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'azmayesh_id' => 'required|exists:azmayeshes,id',
|
||||||
|
'data' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Http/Requests/V3/AzmayeshType/StoreRequest.php
Normal file
33
app/Http/Requests/V3/AzmayeshType/StoreRequest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|string',
|
||||||
|
'fields' => 'required|array',
|
||||||
|
'fields.*.name' => 'required|string',
|
||||||
|
'fields.*.unit' => 'string',
|
||||||
|
'fields.*.type' => 'required|string',
|
||||||
|
'fields.*.option' => 'string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Http/Requests/V3/AzmayeshType/UpdateRequest.php
Normal file
33
app/Http/Requests/V3/AzmayeshType/UpdateRequest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|string',
|
||||||
|
'fields' => 'required|array',
|
||||||
|
'fields.*.name' => 'required|string',
|
||||||
|
'fields.*.unit' => 'string',
|
||||||
|
'fields.*.type' => 'required|string',
|
||||||
|
'fields.*.option' => 'string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Models/Azmayesh.php
Normal file
24
app/Models/Azmayesh.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class Azmayesh extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
public function azmayeshSamples(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(AzmayeshSample::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRouteKeyName(): string
|
||||||
|
{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/Models/AzmayeshField.php
Normal file
28
app/Models/AzmayeshField.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
|
||||||
|
class AzmayeshField extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
protected $hidden = ['pivot'];
|
||||||
|
|
||||||
|
protected function option(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn ($value) => json_decode($value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function azmayeshTypes(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(AzmayeshType::class, 'azmayesh_field_azmayesh_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
13
app/Models/AzmayeshSample.php
Normal file
13
app/Models/AzmayeshSample.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class AzmayeshSample extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
26
app/Models/AzmayeshType.php
Normal file
26
app/Models/AzmayeshType.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class AzmayeshType extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
protected $hidden = ['pivot'];
|
||||||
|
|
||||||
|
public function azmayeshes(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Azmayesh::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function azmayeshFields(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(AzmayeshField::class,'azmayesh_field_azmayesh_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
43
database/factories/AzmayeshFactory.php
Normal file
43
database/factories/AzmayeshFactory.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Province;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Azmayesh>
|
||||||
|
*/
|
||||||
|
class AzmayeshFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'lat' => $this->faker->numerify,
|
||||||
|
'lng' => $this->faker->numerify,
|
||||||
|
'azmayesh_type_id' => AzmayeshType::factory(),
|
||||||
|
'azmayesh_type_name' => function (array $attributes) {
|
||||||
|
return AzmayeshType::query()->find($attributes['azmayesh_type_id'])->name;
|
||||||
|
},
|
||||||
|
'province_id' => Province::factory(),
|
||||||
|
'province_name' => function (array $attributes) {
|
||||||
|
return Province::query()->find($attributes['province_id'])->name_fa;
|
||||||
|
},
|
||||||
|
'request_date' => $this->faker->date,
|
||||||
|
'report_date' => $this->faker->date,
|
||||||
|
'request_number' => $this->faker->numerify,
|
||||||
|
'employer' => $this->faker->name,
|
||||||
|
'contractor' => $this->faker->name,
|
||||||
|
'work_number' => $this->faker->numerify,
|
||||||
|
'project_name' => $this->faker->name,
|
||||||
|
'consultant' => $this->faker->name,
|
||||||
|
'applicant' => $this->faker->name,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
25
database/factories/AzmayeshFieldFactory.php
Normal file
25
database/factories/AzmayeshFieldFactory.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AzmayeshField>
|
||||||
|
*/
|
||||||
|
class AzmayeshFieldFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
'type' => $this->faker->name,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
28
database/factories/AzmayeshSampleFactory.php
Normal file
28
database/factories/AzmayeshSampleFactory.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AzmayeshSample>
|
||||||
|
*/
|
||||||
|
class AzmayeshSampleFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'azmayesh_id' => Azmayesh::factory(),
|
||||||
|
'azmayesh_project_name' => function (array $attributes) {
|
||||||
|
return Azmayesh::query()->find($attributes['azmayesh_id'])->project_name;
|
||||||
|
},
|
||||||
|
'data' => json_encode(['test']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
23
database/factories/AzmayeshTypeFactory.php
Normal file
23
database/factories/AzmayeshTypeFactory.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AzmayeshType>
|
||||||
|
*/
|
||||||
|
class AzmayeshTypeFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->name
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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::create('azmayesh_fields', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('unit')->nullable();
|
||||||
|
$table->string('type');
|
||||||
|
$table->json('option')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('azmayesh_fields');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?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('azmayesh_types', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('azmayesh_types');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?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('azmayeshes', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types');
|
||||||
|
$table->string('azmayesh_type_name');
|
||||||
|
$table->string('lat');
|
||||||
|
$table->string('lng');
|
||||||
|
$table->unsignedTinyInteger('province_id');
|
||||||
|
$table->foreign('province_id')->references('id')->on('provinces');
|
||||||
|
$table->string('province_name');
|
||||||
|
$table->date('request_date')->nullable();
|
||||||
|
$table->date('report_date')->nullable();
|
||||||
|
$table->string('request_number');
|
||||||
|
$table->string('employer');
|
||||||
|
$table->string('contractor');
|
||||||
|
$table->string('work_number');
|
||||||
|
$table->string('project_name');
|
||||||
|
$table->string('consultant');
|
||||||
|
$table->string('applicant');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('azmayeshes');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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('azmayesh_samples', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('azmayesh_id')->constrained('azmayeshes')->cascadeOnDelete();
|
||||||
|
$table->string('azmayesh_project_name');
|
||||||
|
$table->json('data');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('azmayesh_samples');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?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('azmayesh_field_azmayesh_type', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields')->cascadeOnDelete();
|
||||||
|
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types')->cascadeOnDelete();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('azmayesh_field_azmayesh_type');
|
||||||
|
}
|
||||||
|
};
|
||||||
118
database/seeders/AzmayeshFieldSeeder.php
Normal file
118
database/seeders/AzmayeshFieldSeeder.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AzmayeshFieldSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
DB::table('azmayesh_fields')->insert([
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'name' => 'طول',
|
||||||
|
'unit' => 'cm',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'عرض',
|
||||||
|
'unit' => 'cm',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'name' => 'تاریخ آزمایش',
|
||||||
|
'unit' => '-',
|
||||||
|
'type' => 'date',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 4,
|
||||||
|
'name' => 'وضعیت سینی',
|
||||||
|
'unit' => '-',
|
||||||
|
'type' => 'select',
|
||||||
|
'option' => json_encode(['طولی', 'عرضی']),
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 5,
|
||||||
|
'name' => 'ضخامت',
|
||||||
|
'unit' => 'cm',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 6,
|
||||||
|
'name' => 'نوع لایه',
|
||||||
|
'unit' => '-',
|
||||||
|
'type' => 'select',
|
||||||
|
'option' => json_encode(['اساس']),
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 7,
|
||||||
|
'name' => 'مشخصات تراکم نسبی',
|
||||||
|
'unit' => 'percent',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 8,
|
||||||
|
'name' => 'نیروی تصحیح شده',
|
||||||
|
'unit' => 'kg',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 9,
|
||||||
|
'name' => 'مقاومت فشاری آزمونه',
|
||||||
|
'unit' => 'kg/cm2',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 10,
|
||||||
|
'name' => 'مقاومت فشاری آزمونه استوانه ای متناظر',
|
||||||
|
'unit' => 'kg/cm2',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 11,
|
||||||
|
'name' => 'مقاومت فشاری آزمونه استوانه ای متناظر',
|
||||||
|
'unit' => 'kg/cm2',
|
||||||
|
'type' => 'input',
|
||||||
|
'option' => null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
database/seeders/AzmayeshSampleSeeder.php
Normal file
30
database/seeders/AzmayeshSampleSeeder.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AzmayeshSampleSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
DB::table('azmayesh_samples')->insert([
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'azmayesh_id' => 1,
|
||||||
|
'azmayesh_project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه',
|
||||||
|
'data' => json_encode([
|
||||||
|
1 => 'test'
|
||||||
|
]),
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
139
database/seeders/AzmayeshSeeder.php
Normal file
139
database/seeders/AzmayeshSeeder.php
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AzmayeshSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
DB::table('azmayeshes')->insert([
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'lat' => '36.2816000000',
|
||||||
|
'lng' => '50.0153000000',
|
||||||
|
'azmayesh_type_id' => 1,
|
||||||
|
'azmayesh_type_name' => 'تعیین مقاومت فشاری بتن',
|
||||||
|
'province_id' => 20,
|
||||||
|
'province_name' => 'قزوین',
|
||||||
|
'request_date' => '1403-02-12',
|
||||||
|
'report_date' => '1403-02-12',
|
||||||
|
'request_number' => '-',
|
||||||
|
'employer' => 'شهرداری شریفیه',
|
||||||
|
'contractor' => 'شرکت طرح گستر رواق',
|
||||||
|
'work_number' => '020040035',
|
||||||
|
'project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه',
|
||||||
|
'consultant' => '-',
|
||||||
|
'applicant' => 'شهرداری شریفیه',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 2,
|
||||||
|
'lat' => '36.2816000000',
|
||||||
|
'lng' => '50.0153000000',
|
||||||
|
'azmayesh_type_id' => 4,
|
||||||
|
'azmayesh_type_name' => 'تعیین تراکم نسبی',
|
||||||
|
'province_id' => 20,
|
||||||
|
'province_name' => 'قزوین',
|
||||||
|
'request_date' => '1403-01-15',
|
||||||
|
'report_date' => '1403-07-07',
|
||||||
|
'request_number' => '-',
|
||||||
|
'employer' => 'شهرداری الوند',
|
||||||
|
'contractor' => '-',
|
||||||
|
'work_number' => '020040001',
|
||||||
|
'project_name' => 'کنترل کیفی پروژه های اجرایی شهرداری الوند',
|
||||||
|
'consultant' => '-',
|
||||||
|
'applicant' => 'شهرداری الوند',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'lat' => '36.2816000000',
|
||||||
|
'lng' => '50.0153000000',
|
||||||
|
'azmayesh_type_id' => 3,
|
||||||
|
'azmayesh_type_name' => 'مقدار قیر پاشیده شده',
|
||||||
|
'province_id' => 20,
|
||||||
|
'province_name' => 'قزوین',
|
||||||
|
'request_date' => '1403-07-04',
|
||||||
|
'report_date' => '1403-07-05',
|
||||||
|
'request_number' => '-',
|
||||||
|
'employer' => 'بنیاد مسکن استان قزوین',
|
||||||
|
'contractor' => 'امور اجرایی و ماشین آلات عمرانی بنیاد مسکن',
|
||||||
|
'work_number' => '-',
|
||||||
|
'project_name' => 'کنترل کیفی پروژه های روستای ولدآباد',
|
||||||
|
'consultant' => '-',
|
||||||
|
'applicant' => 'بنیاد مسکن استان قزوین',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 4,
|
||||||
|
'lat' => '36.2816000000',
|
||||||
|
'lng' => '50.0153000000',
|
||||||
|
'azmayesh_type_id' => 1,
|
||||||
|
'azmayesh_type_name' => 'تعیین مقاومت فشاری بتن',
|
||||||
|
'province_id' => 20,
|
||||||
|
'province_name' => 'قزوین',
|
||||||
|
'request_date' => '1403-06-15',
|
||||||
|
'report_date' => null,
|
||||||
|
'request_number' => '15/28296',
|
||||||
|
'employer' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین',
|
||||||
|
'contractor' => 'شرکت تاژه صنعت سنگسر',
|
||||||
|
'work_number' => '010060027',
|
||||||
|
'project_name' => 'نیوجرسی مفصلی جهت ایمن سازی آزادراه های قزوین-کرج و قزوین-زنجان',
|
||||||
|
'consultant' => '-',
|
||||||
|
'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 5,
|
||||||
|
'lat' => '36.2816000000',
|
||||||
|
'lng' => '50.0153000000',
|
||||||
|
'azmayesh_type_id' => 2,
|
||||||
|
'azmayesh_type_name' => 'دانه بندی و نتایج آزمایش های آسفالت گرم',
|
||||||
|
'province_id' => 20,
|
||||||
|
'province_name' => 'قزوین',
|
||||||
|
'request_date' => '1403-06-27',
|
||||||
|
'report_date' => '1403-07-07',
|
||||||
|
'request_number' => 'راهداری-مجتمع آقای کلانی',
|
||||||
|
'employer' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین',
|
||||||
|
'contractor' => 'شرکت آرتان راهسازان البرز قزوین',
|
||||||
|
'work_number' => '010100005',
|
||||||
|
'project_name' => 'احداث راه های دسترسی مجتمع خدمات رفاهی حوزه آبیک-مجتمع آقای کلانی',
|
||||||
|
'consultant' => '-',
|
||||||
|
'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 6,
|
||||||
|
'lat' => '36.2816000000',
|
||||||
|
'lng' => '50.0153000000',
|
||||||
|
'azmayesh_type_id' => 5,
|
||||||
|
'azmayesh_type_name' => 'دانه بندی و نتایج آزمایش های مصالح سنگی',
|
||||||
|
'province_id' => 20,
|
||||||
|
'province_name' => 'قزوین',
|
||||||
|
'request_date' => '1403-03-20',
|
||||||
|
'report_date' => '1403-07-09',
|
||||||
|
'request_number' => '1400/4361-ص',
|
||||||
|
'employer' => 'شرکت سهامی عام کارخانجات قند قزوین',
|
||||||
|
'contractor' => '-',
|
||||||
|
'work_number' => '070020123',
|
||||||
|
'project_name' => 'آماده سازی محوطه دپوی سیلو کارخانه قند قزوین',
|
||||||
|
'consultant' => '-',
|
||||||
|
'applicant' => 'شرکت سهامی عام کارخانجات قند قزوین',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
database/seeders/AzmayeshTypeSeeder.php
Normal file
49
database/seeders/AzmayeshTypeSeeder.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AzmayeshTypeSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
DB::table('azmayesh_types')->insert([
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'name' => 'تعیین مقاومت فشاری بتن',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'دانه بندی و نتایج آزمایش های آسفالت گرم',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'name' => 'مقدار قیر پاشیده شده',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 4,
|
||||||
|
'name' => 'تعیین تراکم نسبی',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 5,
|
||||||
|
'name' => 'دانه بندی و نتایج آزمایش های مصالح سنگی',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -179,6 +179,26 @@ return [
|
|||||||
'new_password' => 'رمز عبور جدید',
|
'new_password' => 'رمز عبور جدید',
|
||||||
'degree' => 'مدرک تحصیلی',
|
'degree' => 'مدرک تحصیلی',
|
||||||
'major' => 'شغل',
|
'major' => 'شغل',
|
||||||
'avatar' => 'آواتار'
|
'avatar' => 'آواتار',
|
||||||
|
'lat' => 'طول جغرافیایی',
|
||||||
|
'lng' => 'عرض جغرافیایی',
|
||||||
|
'azmayesh_type_id' => 'نوع آزمایش',
|
||||||
|
'request_date' => 'تاریخ درخواست',
|
||||||
|
'report_date' => 'تاریخ گزارش',
|
||||||
|
'request_number' => 'شماره درخواست',
|
||||||
|
'employer' => 'کارفرما',
|
||||||
|
'contractor' => 'پیمانکار',
|
||||||
|
'work_number' => 'شماره کار',
|
||||||
|
'project_name' => 'نام پروژه',
|
||||||
|
'consultant' => 'مشاور',
|
||||||
|
'applicant' => 'متقاضی',
|
||||||
|
'province_id' => 'استان',
|
||||||
|
'azmayesh_id' => 'آزمایش',
|
||||||
|
'data' => 'داده',
|
||||||
|
'fields' => 'فیلد ها',
|
||||||
|
'fields.*.name' => 'نام فیلد',
|
||||||
|
'fields.*.unit' => 'واحد فیلد',
|
||||||
|
'fields.*.type' => 'نوع فیلد',
|
||||||
|
'fields.*.option' => 'گزینه های فیلد',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\V3\Azmayesh\AzmayeshController;
|
||||||
|
use App\Http\Controllers\V3\Azmayesh\AzmayeshSampleController;
|
||||||
|
use App\Http\Controllers\V3\Azmayesh\AzmayeshTypeController;
|
||||||
use App\Http\Controllers\V3\Harim\DivarkeshiController;
|
use App\Http\Controllers\V3\Harim\DivarkeshiController;
|
||||||
use App\Http\Controllers\V3\ProfileController;
|
use App\Http\Controllers\V3\ProfileController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@@ -32,3 +35,41 @@ Route::prefix('profile')
|
|||||||
Route::post('edit', 'edit')->name('edit');
|
Route::post('edit', 'edit')->name('edit');
|
||||||
Route::post('change_password', 'changePassword')->name('changePassword');
|
Route::post('change_password', 'changePassword')->name('changePassword');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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');
|
||||||
|
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::prefix('azmayesh_samples')
|
||||||
|
->name('azmayesh_samples.')
|
||||||
|
->middleware('can:azmayesh-management')
|
||||||
|
->controller(AzmayeshSampleController::class)
|
||||||
|
->group(function () {
|
||||||
|
Route::get('/index/{azmayesh_id}', 'index')->name('index');
|
||||||
|
Route::get('/{azmayeshSample}', 'show')->name('show');
|
||||||
|
Route::post('/store', 'store')->name('store');
|
||||||
|
Route::post('/update/{azmayeshSample}', 'update')->name('update');
|
||||||
|
Route::post('/delete/{azmayeshSample}', 'destroy')->name('delete');
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::prefix('azmayeshes')
|
||||||
|
->name('azmayeshes.')
|
||||||
|
->middleware('can:azmayesh-management')
|
||||||
|
->controller(AzmayeshController::class)
|
||||||
|
->group(function () {
|
||||||
|
Route::get('/', 'index')->name('index');
|
||||||
|
Route::get('/{azmayesh}', 'show')->name('show');
|
||||||
|
Route::post('/store', 'store')->name('store');
|
||||||
|
Route::post('/update/{azmayesh}', 'update')->name('update');
|
||||||
|
Route::post('/delete/{azmayesh}', 'destroy')->name('delete');
|
||||||
|
});
|
||||||
|
|||||||
@@ -519,3 +519,4 @@ INSERT INTO edarate_shahri (name_fa,province_id,created_at,updated_at) VALUES
|
|||||||
INSERT INTO edarate_shahri (name_fa,province_id,created_at,updated_at) VALUES
|
INSERT INTO edarate_shahri (name_fa,province_id,created_at,updated_at) VALUES
|
||||||
('اداره خمام',28,'2023-06-17 08:43:14','2023-06-17 08:43:14'),
|
('اداره خمام',28,'2023-06-17 08:43:14','2023-06-17 08:43:14'),
|
||||||
('اداره اصلاندوز',3,'2023-08-15 09:33:55','2023-08-15 09:33:55');
|
('اداره اصلاندوز',3,'2023-08-15 09:33:55','2023-08-15 09:33:55');
|
||||||
|
('اداره گالیکش',27,'2024-11-16 14:33:55','2024-11-16 14:33:55');
|
||||||
|
|||||||
@@ -133,3 +133,5 @@ INSERT INTO permissions (name,guard_name,name_fa,description,created_at,updated_
|
|||||||
('show-receipt','web','نمایش خسارت (کشوری)','نمایش خسارات کشوری',NULL,NULL,NULL,NULL,'receipt','خسارات وارد بر ابنیه فنی راه',0,0),
|
('show-receipt','web','نمایش خسارت (کشوری)','نمایش خسارات کشوری',NULL,NULL,NULL,NULL,'receipt','خسارات وارد بر ابنیه فنی راه',0,0),
|
||||||
('show-receipt-province','web','نمایش خسارت (استانی)','نمایش خسارات استانی',NULL,NULL,NULL,NULL,'receipt','خسارات وارد بر ابنیه فنی راه',1,0),
|
('show-receipt-province','web','نمایش خسارت (استانی)','نمایش خسارات استانی',NULL,NULL,NULL,NULL,'receipt','خسارات وارد بر ابنیه فنی راه',1,0),
|
||||||
('supervise-road-item-by-edareostani','web','نظارت بر ثبت فعالیت روزانه و جاری(ادارات استانی)',NULL,'2023-07-09 09:48:35','2023-07-09 09:48:37',NULL,NULL,'road-item','فعالیت روزانه',0,0);
|
('supervise-road-item-by-edareostani','web','نظارت بر ثبت فعالیت روزانه و جاری(ادارات استانی)',NULL,'2023-07-09 09:48:35','2023-07-09 09:48:37',NULL,NULL,'road-item','فعالیت روزانه',0,0);
|
||||||
|
('azmayesh-management','web','مدیریت آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0);
|
||||||
|
('azmayesh-type-management','web','مدیریت نوع آزمایشات',NULL,'2024-11-18 09:48:35','2024-11-18 09:48:35',NULL,NULL,'azmayesh','آزمایشات',0,0);
|
||||||
|
|||||||
60
tests/Feature/V3/Azmayesh/DeleteTest.php
Normal file
60
tests/Feature/V3/Azmayesh/DeleteTest.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DeleteTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.delete', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_delete_azmayesh(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.delete', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('azmayeshes', [
|
||||||
|
'lat' => $azmayesh->lat,
|
||||||
|
'lng' => $azmayesh->lng,
|
||||||
|
'azmayesh_type_id' => $azmayesh->azmayesh_type_id,
|
||||||
|
'azmayesh_type_name' => $azmayesh->azmayesh_type_name,
|
||||||
|
'request_date' => $azmayesh->request_date,
|
||||||
|
'report_date' => $azmayesh->report_date,
|
||||||
|
'request_number' => $azmayesh->request_number,
|
||||||
|
'employer' => $azmayesh->employer,
|
||||||
|
'contractor' => $azmayesh->contractor,
|
||||||
|
'work_number' => $azmayesh->work_number,
|
||||||
|
'project_name' => $azmayesh->project_name,
|
||||||
|
'consultant' => $azmayesh->consultant,
|
||||||
|
'applicant' => $azmayesh->applicant,
|
||||||
|
'province_id' => $azmayesh->province_id,
|
||||||
|
'province_name' => $azmayesh->province_name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
74
tests/Feature/V3/Azmayesh/IndexTest.php
Normal file
74
tests/Feature/V3/Azmayesh/IndexTest.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class IndexTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayeshes.index', [
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_all_azmayeshes_returned_successfully(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Azmayesh::factory(5)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayeshes.index', [
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
'id',
|
||||||
|
'lat',
|
||||||
|
'lng',
|
||||||
|
'request_date',
|
||||||
|
'report_date',
|
||||||
|
'request_number',
|
||||||
|
'employer',
|
||||||
|
'contractor',
|
||||||
|
'work_number',
|
||||||
|
'consultant',
|
||||||
|
'applicant',
|
||||||
|
'project_name',
|
||||||
|
'province_id',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
"meta" => [
|
||||||
|
"totalRowCount"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
391
tests/Feature/V3/Azmayesh/StoreTest.php
Normal file
391
tests/Feature/V3/Azmayesh/StoreTest.php
Normal file
@@ -0,0 +1,391 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\Province;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class StoreTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lat_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lat' => __('validation.required', ['attribute' => 'طول جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lat_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'lat' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lat' => __('validation.string', ['attribute' => 'طول جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lng_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lng' => __('validation.required', ['attribute' => 'عرض جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lng_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'lng' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lng' => __('validation.string', ['attribute' => 'عرض جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_type_id_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_type_id' => __('validation.required', ['attribute' => 'نوع آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_type_id_attribute_should_exist_on_azmayesh_types_table(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'azmayesh_type_id' => $this->faker->numberBetween(10, 100)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_type_id' => __('validation.exists', ['attribute' => 'نوع آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_request_date_attribute_should_be_date_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'request_date' => $this->faker->lexify
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'request_date' => __('validation.date', ['attribute' => 'تاریخ درخواست'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_report_date_attribute_should_be_date_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'report_date' => $this->faker->lexify
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'report_date' => __('validation.date', ['attribute' => 'تاریخ گزارش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_request_number_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'request_number' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'request_number' => __('validation.string', ['attribute' => 'شماره درخواست'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_employer_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'employer' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'employer' => __('validation.string', ['attribute' => 'کارفرما'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_contractor_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'contractor' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'contractor' => __('validation.string', ['attribute' => 'پیمانکار'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_work_number_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'work_number' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'work_number' => __('validation.string', ['attribute' => 'شماره کار'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_project_name_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'project_name' => __('validation.required', ['attribute' => 'نام پروژه'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_project_name_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'project_name' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'project_name' => __('validation.string', ['attribute' => 'نام پروژه'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_consultant_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'consultant' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'consultant' => __('validation.string', ['attribute' => 'مشاور'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_applicant_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'applicant' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'applicant' => __('validation.string', ['attribute' => 'متقاضی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_province_id_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'province_id' => __('validation.required', ['attribute' => 'استان'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_province_id_attribute_should_exists_on_province_table(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [
|
||||||
|
'province_id' => $this->faker->numberBetween(10, 100)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'province_id' => __('validation.exists', ['attribute' => 'استان'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_store_a_new_azmayesh(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$province = Province::factory()->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'lat' => $this->faker->numerify,
|
||||||
|
'lng' => $this->faker->numerify,
|
||||||
|
'azmayesh_type_id' => $azmayeshType->id,
|
||||||
|
'request_date' => $this->faker->date,
|
||||||
|
'report_date' => $this->faker->date,
|
||||||
|
'request_number' => $this->faker->numerify,
|
||||||
|
'employer' => $this->faker->name,
|
||||||
|
'contractor' => $this->faker->name,
|
||||||
|
'work_number' => $this->faker->numerify,
|
||||||
|
'project_name' => $this->faker->name,
|
||||||
|
'consultant' => $this->faker->name,
|
||||||
|
'applicant' => $this->faker->name,
|
||||||
|
'province_id' => $province->id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), $data);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayeshes', [
|
||||||
|
'lat' => $data['lat'],
|
||||||
|
'lng' => $data['lng'],
|
||||||
|
'azmayesh_type_id' => $data['azmayesh_type_id'],
|
||||||
|
'request_date' => $data['request_date'],
|
||||||
|
'report_date' => $data['report_date'],
|
||||||
|
'request_number' => $data['request_number'],
|
||||||
|
'employer' => $data['employer'],
|
||||||
|
'contractor' => $data['contractor'],
|
||||||
|
'work_number' => $data['work_number'],
|
||||||
|
'project_name' => $data['project_name'],
|
||||||
|
'consultant' => $data['consultant'],
|
||||||
|
'applicant' => $data['applicant'],
|
||||||
|
'province_id' => $data['province_id'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
396
tests/Feature/V3/Azmayesh/UpdateTest.php
Normal file
396
tests/Feature/V3/Azmayesh/UpdateTest.php
Normal file
@@ -0,0 +1,396 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\Province;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lat_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lat' => __('validation.required', ['attribute' => 'طول جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lat_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'lat' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lat' => __('validation.string', ['attribute' => 'طول جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lng_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lng' => __('validation.required', ['attribute' => 'عرض جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_lng_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'lng' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'lng' => __('validation.string', ['attribute' => 'عرض جغرافیایی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_type_id_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_type_id' => __('validation.required', ['attribute' => 'نوع آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_type_id_attribute_should_exist_on_azmayesh_types_table(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'azmayesh_type_id' => $this->faker->numberBetween(10, 100)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_type_id' => __('validation.exists', ['attribute' => 'نوع آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_request_date_attribute_should_be_date_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'request_date' => $this->faker->lexify
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'request_date' => __('validation.date', ['attribute' => 'تاریخ درخواست'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_report_date_attribute_should_be_date_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'report_date' => $this->faker->lexify
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'report_date' => __('validation.date', ['attribute' => 'تاریخ گزارش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_request_number_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'request_number' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'request_number' => __('validation.string', ['attribute' => 'شماره درخواست'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_employer_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'employer' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'employer' => __('validation.string', ['attribute' => 'کارفرما'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_contractor_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'contractor' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'contractor' => __('validation.string', ['attribute' => 'پیمانکار'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_work_number_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'work_number' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'work_number' => __('validation.string', ['attribute' => 'شماره کار'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_project_name_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'project_name' => __('validation.required', ['attribute' => 'نام پروژه'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_project_name_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'project_name' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'project_name' => __('validation.string', ['attribute' => 'نام پروژه'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_consultant_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'consultant' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'consultant' => __('validation.string', ['attribute' => 'مشاور'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_applicant_attribute_should_be_string_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'applicant' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'applicant' => __('validation.string', ['attribute' => 'متقاضی'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_province_id_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'province_id' => __('validation.required', ['attribute' => 'استان'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_province_id_attribute_should_exists_on_province_table(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [
|
||||||
|
'province_id' => $this->faker->numberBetween(10, 100)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'province_id' => __('validation.exists', ['attribute' => 'استان'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_update_the_azmayesh(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$province = Province::factory()->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'lat' => $this->faker->numerify,
|
||||||
|
'lng' => $this->faker->numerify,
|
||||||
|
'azmayesh_type_id' => $azmayeshType->id,
|
||||||
|
'request_date' => $this->faker->date,
|
||||||
|
'report_date' => $this->faker->date,
|
||||||
|
'request_number' => $this->faker->numerify,
|
||||||
|
'employer' => $this->faker->name,
|
||||||
|
'contractor' => $this->faker->name,
|
||||||
|
'work_number' => $this->faker->numerify,
|
||||||
|
'project_name' => $this->faker->name,
|
||||||
|
'consultant' => $this->faker->name,
|
||||||
|
'applicant' => $this->faker->name,
|
||||||
|
'province_id' => $province->id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), $data);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
tests/Feature/V3/AzmayeshSample/DeleteTest.php
Normal file
47
tests/Feature/V3/AzmayeshSample/DeleteTest.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshSample;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshSample;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DeleteTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.delete', [$azmayeshSample->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_delete_azmayesh_sample(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.delete', [$azmayeshSample->id]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('azmayesh_samples', [
|
||||||
|
'azmayesh_id' => $azmayeshSample->azmayesh_id,
|
||||||
|
'data' => $azmayeshSample->data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
tests/Feature/V3/AzmayeshSample/IndexTest.php
Normal file
106
tests/Feature/V3/AzmayeshSample/IndexTest.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshSample;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshSample;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class IndexTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_samples.index', [
|
||||||
|
1,
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_all_azmayesh_samples_returned_successfully(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Azmayesh::factory(5)
|
||||||
|
->sequence(
|
||||||
|
['id' => 1],
|
||||||
|
['id' => 2],
|
||||||
|
['id' => 3],
|
||||||
|
['id' => 4],
|
||||||
|
['id' => 5]
|
||||||
|
)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
AzmayeshSample::factory(5)
|
||||||
|
->sequence(
|
||||||
|
[
|
||||||
|
'azmayesh_id' => 1,
|
||||||
|
'azmayesh_project_name' => $this->faker->name,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'azmayesh_id' => 2,
|
||||||
|
'azmayesh_project_name' => $this->faker->name,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'azmayesh_id' => 3,
|
||||||
|
'azmayesh_project_name' => $this->faker->name,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'azmayesh_id' => 4,
|
||||||
|
'azmayesh_project_name' => $this->faker->name,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'azmayesh_id' => 1,
|
||||||
|
'azmayesh_project_name' => $this->faker->name,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_samples.index', [
|
||||||
|
1,
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
'id',
|
||||||
|
'azmayesh_id',
|
||||||
|
'azmayesh_project_name',
|
||||||
|
'data',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
"meta" => [
|
||||||
|
"totalRowCount"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
108
tests/Feature/V3/AzmayeshSample/StoreTest.php
Normal file
108
tests/Feature/V3/AzmayeshSample/StoreTest.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshSample;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshSample;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\Province;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class StoreTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_id_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_id' => __('validation.required', ['attribute' => 'آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_id_attribute_should_exists_on_azmayeshes_table(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'), [
|
||||||
|
'azmayesh_id' => $this->faker->numberBetween(10, 100)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_id' => __('validation.exists', ['attribute' => 'آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_data_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'data' => __('validation.required', ['attribute' => 'داده'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_store_a_new_azmayesh_sample(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'azmayesh_id' => $azmayesh->id,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'), $data);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_samples', [
|
||||||
|
'azmayesh_id' => $data['azmayesh_id'],
|
||||||
|
// 'data' => $data['data'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(AzmayeshSample::first()->data, $data['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
111
tests/Feature/V3/AzmayeshSample/UpdateTest.php
Normal file
111
tests/Feature/V3/AzmayeshSample/UpdateTest.php
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshSample;
|
||||||
|
|
||||||
|
use App\Models\Azmayesh;
|
||||||
|
use App\Models\AzmayeshSample;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_id_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_id' => __('validation.required', ['attribute' => 'آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_id_attribute_should_exists_on_azmayeshes_table(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]), [
|
||||||
|
'azmayesh_id' => $this->faker->numberBetween(10, 100)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'azmayesh_id' => __('validation.exists', ['attribute' => 'آزمایش'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_data_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'data' => __('validation.required', ['attribute' => 'داده'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_update_the_azmayesh_sample(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayesh = Azmayesh::factory()->create();
|
||||||
|
$azmayeshSample = AzmayeshSample::factory()->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'azmayesh_id' => $azmayesh->id,
|
||||||
|
'data' => json_encode([$this->faker->numerify]),
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]), $data);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_samples', [
|
||||||
|
'azmayesh_id' => $data['azmayesh_id'],
|
||||||
|
// 'data' => $data['data'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(AzmayeshSample::first()->data, $data['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
tests/Feature/V3/AzmayeshType/DeleteTest.php
Normal file
58
tests/Feature/V3/AzmayeshType/DeleteTest.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshField;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DeleteTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_type_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.delete', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_delete_azmayesh_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
$azmayeshField = AzmayeshField::factory()->create();
|
||||||
|
|
||||||
|
$azmayeshType->azmayeshFields()->attach([$azmayeshField->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.delete', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('azmayesh_types', [
|
||||||
|
'name' => $azmayeshType->name,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('azmayesh_field_azmayesh_type', [
|
||||||
|
'azmayesh_type_id' => $azmayeshType->id,
|
||||||
|
'azmayesh_field_id' => $azmayeshField->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
84
tests/Feature/V3/AzmayeshType/FieldsTest.php
Normal file
84
tests/Feature/V3/AzmayeshType/FieldsTest.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshField;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class FieldsTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_type_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.fields', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_all_fields_for_azmayesh_types_returned_successfully(): void
|
||||||
|
{
|
||||||
|
AzmayeshField::factory(3)
|
||||||
|
->sequence(
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
'type' => $this->faker->name,
|
||||||
|
'option' => json_encode([$this->faker->name]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 2,
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
'type' => $this->faker->name,
|
||||||
|
'option' => json_encode([$this->faker->name]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
'type' => $this->faker->name,
|
||||||
|
'option' => json_encode([$this->faker->name]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$azmayeshType->azmayeshFields()->attach([1, 2, 3]);
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.fields', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
'name',
|
||||||
|
'unit',
|
||||||
|
'type',
|
||||||
|
'option',
|
||||||
|
"created_at",
|
||||||
|
"updated_at"
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
60
tests/Feature/V3/AzmayeshType/IndexTest.php
Normal file
60
tests/Feature/V3/AzmayeshType/IndexTest.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class IndexTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_type_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.index', [
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_all_azmayesh_types_returned_successfully(): void
|
||||||
|
{
|
||||||
|
AzmayeshType::factory(5)->create();
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.index', [
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
tests/Feature/V3/AzmayeshType/ListTest.php
Normal file
49
tests/Feature/V3/AzmayeshType/ListTest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
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;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_type_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.list'));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_type_list_returned_successfully(): void
|
||||||
|
{
|
||||||
|
AzmayeshType::factory(5)->create();
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.list'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
'name',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
66
tests/Feature/V3/AzmayeshType/ShowTest.php
Normal file
66
tests/Feature/V3/AzmayeshType/ShowTest.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshField;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ShowTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_type_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.show', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_azmayesh_type_details_returned_successfully(): void
|
||||||
|
{
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
$azmayeshField = AzmayeshField::factory()->create();
|
||||||
|
|
||||||
|
$azmayeshType->azmayeshFields()->attach([$azmayeshField->id]);
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.show', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertExactJson([
|
||||||
|
'data' => [
|
||||||
|
"id" => $azmayeshType->id,
|
||||||
|
"name" => $azmayeshType->name,
|
||||||
|
"created_at" => $azmayeshType->created_at,
|
||||||
|
"updated_at" => $azmayeshType->updated_at,
|
||||||
|
"azmayesh_fields" => [
|
||||||
|
[
|
||||||
|
"id" => $azmayeshField->id,
|
||||||
|
"name" => $azmayeshField->name,
|
||||||
|
"unit" => $azmayeshField->unit,
|
||||||
|
"type" => $azmayeshField->type,
|
||||||
|
"option" => $azmayeshField->option,
|
||||||
|
"created_at" => $azmayeshField->created_at,
|
||||||
|
"updated_at" => $azmayeshField->updated_at,
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
262
tests/Feature/V3/AzmayeshType/StoreTest.php
Normal file
262
tests/Feature/V3/AzmayeshType/StoreTest.php
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class StoreTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_type_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.required', ['attribute' => "نام"])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'name' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.string', ['attribute' => "نام"])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_fields_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields' => __('validation.required', ['attribute' => 'فیلد ها'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_fields_attribute_should_be_array(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields' => __('validation.array', ['attribute' => 'فیلد ها'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_name_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => [
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.name' => __('validation.required', ['attribute' => 'نام فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_name_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => [
|
||||||
|
['name' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.name' => __('validation.string', ['attribute' => 'نام فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_unit_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => [
|
||||||
|
['unit' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.unit' => __('validation.string', ['attribute' => 'واحد فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_type_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => [
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.type' => __('validation.required', ['attribute' => 'نوع فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_type_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => [
|
||||||
|
['type' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.type' => __('validation.string', ['attribute' => 'نوع فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_option_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), [
|
||||||
|
'fields' => [
|
||||||
|
['option' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.option' => __('validation.string', ['attribute' => 'گزینه های فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_store_fields_for_an_azmayesh_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'fields' => [
|
||||||
|
[
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'type' => $this->faker->randomElement(['input', 'select', 'date']),
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
'option' => json_encode(['test']),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'type' => $this->faker->randomElement(['input', 'select', 'date']),
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.store'), $data);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_fields', [
|
||||||
|
'name' => $data['fields'][0]['name'],
|
||||||
|
'type' => $data['fields'][0]['type'],
|
||||||
|
'unit' => $data['fields'][0]['unit'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_fields', [
|
||||||
|
'name' => $data['fields'][1]['name'],
|
||||||
|
'type' => $data['fields'][1]['type'],
|
||||||
|
'unit' => $data['fields'][1]['unit'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_types', [
|
||||||
|
'name' => $data['name'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
276
tests/Feature/V3/AzmayeshType/UpdateTest.php
Normal file
276
tests/Feature/V3/AzmayeshType/UpdateTest.php
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\AzmayeshType;
|
||||||
|
|
||||||
|
use App\Models\AzmayeshSample;
|
||||||
|
use App\Models\AzmayeshType;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_azmayesh_management_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.required', ['attribute' => "نام"])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'name' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.string', ['attribute' => "نام"])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_fields_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields' => __('validation.required', ['attribute' => 'فیلد ها'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_fields_attribute_should_be_array(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields' => __('validation.array', ['attribute' => 'فیلد ها'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_name_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => [
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.name' => __('validation.required', ['attribute' => 'نام فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_name_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => [
|
||||||
|
['name' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.name' => __('validation.string', ['attribute' => 'نام فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_unit_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => [
|
||||||
|
['unit' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.unit' => __('validation.string', ['attribute' => 'واحد فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_type_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => [
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.type' => __('validation.required', ['attribute' => 'نوع فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_type_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => [
|
||||||
|
['type' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.type' => __('validation.string', ['attribute' => 'نوع فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_field_option_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), [
|
||||||
|
'fields' => [
|
||||||
|
['option' => $this->faker->numberBetween(1, 10)]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'fields.0.option' => __('validation.string', ['attribute' => 'گزینه های فیلد'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_update_fields_for_an_azmayesh_type(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'azmayesh-type-management'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
$azmayeshType = AzmayeshType::factory()->create();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'fields' => [
|
||||||
|
[
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'type' => $this->faker->randomElement(['input', 'select', 'date']),
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
'option' => json_encode(['test']),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'type' => $this->faker->randomElement(['input', 'select', 'date']),
|
||||||
|
'unit' => $this->faker->name,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.azmayesh_types.update', [$azmayeshType->id]), $data);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_fields', [
|
||||||
|
'name' => $data['fields'][0]['name'],
|
||||||
|
'type' => $data['fields'][0]['type'],
|
||||||
|
'unit' => $data['fields'][0]['unit'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_fields', [
|
||||||
|
'name' => $data['fields'][1]['name'],
|
||||||
|
'type' => $data['fields'][1]['type'],
|
||||||
|
'unit' => $data['fields'][1]['unit'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('azmayesh_types', [
|
||||||
|
'name' => $data['name'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user