write test for the lists
This commit is contained in:
@@ -65,6 +65,15 @@ class RoadItemsProjectController extends Controller
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
|
||||
foreach ($data['data'] as $road_item) {
|
||||
if (Gate::allows('gate-supervise-road-item', $road_item)) {
|
||||
$road_item['can_supervise'] = 1;
|
||||
} else {
|
||||
$road_item['can_supervise'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
36
tests/Feature/V3/CMMSMachine/ListTest.php
Normal file
36
tests/Feature/V3/CMMSMachine/ListTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V3\CMMSMachine;
|
||||
|
||||
use App\Models\CMMSMachine;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_machine_code_list_return_successfully(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
CMMSMachine::factory(5)->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('v3.cmms_machines.list'));
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => [
|
||||
"machine_code",
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
36
tests/Feature/V3/Rahdaran/ListTest.php
Normal file
36
tests/Feature/V3/Rahdaran/ListTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V3\Rahdaran;
|
||||
|
||||
use App\Models\Rahdaran;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_machine_code_list_return_successfully(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
Rahdaran::factory(5)->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('v3.rahdaran.list'));
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => [
|
||||
"name",
|
||||
"code",
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,17 @@ class SupervisorIndexTest extends TestCase
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_operator_can_see_the_data_table(): void
|
||||
public function test_supervisor_can_see_the_data_table(): void
|
||||
{
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
'name' => 'create-road-item'
|
||||
'name' => 'show-road-item-supervise-cartable'
|
||||
]))
|
||||
->create();
|
||||
|
||||
RoadItemsProject::factory(10)->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('v3.road_items.operatorIndex', [
|
||||
$response = $this->actingAs($user)->getJson(route('v3.road_items.supervisorIndex', [
|
||||
'size' => 10,
|
||||
'start' => 0,
|
||||
'sorting' => json_encode([]),
|
||||
@@ -90,6 +90,7 @@ class SupervisorIndexTest extends TestCase
|
||||
"cmms_machine_code",
|
||||
"rahdar_id",
|
||||
"rahdar_code",
|
||||
"can_supervise",
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user