wrote test for restore,supervisorIndex,verify
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||||
@@ -18,7 +19,16 @@ class RoadItemsProjectFactory extends Factory
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'item' => $this->faker->numberBetween(1, 10),
|
'item' => $this->faker->numberBetween(1, 10),
|
||||||
'sub_item' => $this->faker->numberBetween(1, 10),
|
'sub_items' => $this->faker->title(),
|
||||||
|
'start_lat' =>$this->faker->latitude(),
|
||||||
|
'start_lng' =>$this->faker->longitude(),
|
||||||
|
'is_new' => $this->faker->boolean(),
|
||||||
|
'status' => $this->faker->randomElement([0, 1, 2]),
|
||||||
|
'activity_date_time' =>$this->faker->dateTimeBetween('-1 year', 'now'),
|
||||||
|
'province_id' => $this->faker->numberBetween(1, 10),
|
||||||
|
'city_id' => $this->faker->numberBetween(1, 10),
|
||||||
|
'user_id' =>$this->faker->numberBetween(1, 10),
|
||||||
|
'user_name' => $this->faker->name(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
72
tests/Feature/V3/RoadItemsProject/RestoreTest.php
Normal file
72
tests/Feature/V3/RoadItemsProject/RestoreTest.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\RoadItemsProject;
|
||||||
|
|
||||||
|
use App\Models\LogList;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\RoadItemsProject;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\UserActivityLog;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use function Ramsey\Uuid\v3;
|
||||||
|
|
||||||
|
class RestoreTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
|
||||||
|
public function test_user_should_have_show_road_item_supervise_restore_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id]));
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
public function test_user_cannot_access_authentication_restore(): void
|
||||||
|
{
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
$response =$this->postJson(route('v3.road_items.restore', [$roadItem->id]));
|
||||||
|
$response->assertStatus(401);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function test_user_can_restore_road_item(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'restore-road-item'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$logList = LogList::factory()->create([
|
||||||
|
'log_unique_code' => 1150,
|
||||||
|
]);
|
||||||
|
UserActivityLog::factory()->create();
|
||||||
|
|
||||||
|
$roadItem = RoadItemsProject::factory()->create([
|
||||||
|
'status' => 1,
|
||||||
|
'status_fa' => 'تایید شده',
|
||||||
|
'supervisor_id' => $user->id,
|
||||||
|
'supervisor_name' => $user->name,
|
||||||
|
'supervisor_description' => 'تایید شده توسط تست',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id]));
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertJson([
|
||||||
|
'message' => __('messages.successful'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('road_items_projects', [
|
||||||
|
'id' => $roadItem->id,
|
||||||
|
'status' => 0,
|
||||||
|
'status_fa' => 'در حال بررسی',
|
||||||
|
'supervisor_id' => null,
|
||||||
|
'supervisor_name' => null,
|
||||||
|
'supervisor_description' => null,
|
||||||
|
'supervising_time' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,6 +23,13 @@ class SupervisorIndexTest extends TestCase
|
|||||||
|
|
||||||
$response->assertForbidden();
|
$response->assertForbidden();
|
||||||
}
|
}
|
||||||
|
public function test_user_cannot_access_authentication_to_supervisor_index(): void
|
||||||
|
{
|
||||||
|
$response = $this->getJson(route('v3.road_items.supervisorIndex'));
|
||||||
|
|
||||||
|
$response->assertStatus(401);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function test_supervisor_can_see_the_data_table(): void
|
public function test_supervisor_can_see_the_data_table(): void
|
||||||
{
|
{
|
||||||
@@ -47,49 +54,21 @@ class SupervisorIndexTest extends TestCase
|
|||||||
'data' => [
|
'data' => [
|
||||||
'*' => [
|
'*' => [
|
||||||
"id",
|
"id",
|
||||||
"user_id",
|
|
||||||
"start_lat",
|
"start_lat",
|
||||||
"start_lng",
|
"start_lng",
|
||||||
"end_lat",
|
"end_lat",
|
||||||
"end_lng",
|
"end_lng",
|
||||||
"project_distance",
|
|
||||||
"item",
|
"item",
|
||||||
"item_fa",
|
"item_fa",
|
||||||
"sub_item",
|
|
||||||
"sub_item_fa",
|
"sub_item_fa",
|
||||||
"sub_item_data",
|
"sub_item_data",
|
||||||
"sub_items",
|
|
||||||
"sub_items_data",
|
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
|
||||||
"province_id",
|
|
||||||
"province_fa",
|
"province_fa",
|
||||||
"city_id",
|
|
||||||
"city_fa",
|
|
||||||
"is_new",
|
|
||||||
"parent_id",
|
|
||||||
"start_way_id",
|
|
||||||
"end_way_id",
|
|
||||||
"unit_fa",
|
"unit_fa",
|
||||||
"user_name",
|
|
||||||
"created_at_fa",
|
|
||||||
"info_id",
|
|
||||||
"status",
|
"status",
|
||||||
"status_fa",
|
"status_fa",
|
||||||
"edarat_id",
|
|
||||||
"edarat_name",
|
"edarat_name",
|
||||||
"edarat_type",
|
|
||||||
"activity_date",
|
|
||||||
"activity_time",
|
|
||||||
"activity_date_time",
|
"activity_date_time",
|
||||||
"supervisor_id",
|
|
||||||
"supervisor_name",
|
|
||||||
"supervisor_description",
|
|
||||||
"supervising_time",
|
|
||||||
"cmms_machine_id",
|
|
||||||
"cmms_machine_code",
|
|
||||||
"rahdar_id",
|
|
||||||
"rahdar_code",
|
|
||||||
"can_supervise",
|
"can_supervise",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|||||||
133
tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php
Normal file
133
tests/Feature/V3/RoadItemsProject/VerifyBySupervisor.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\RoadItemsProject;
|
||||||
|
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\RoadItemsProject;
|
||||||
|
use App\Models\UserActivityLog;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Mockery;
|
||||||
|
use App\Models\LogList;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class VerifyBySupervisor extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
|
||||||
|
public function test_user_cannot_access_authentication_to_verify_by_supervisor(): void
|
||||||
|
{
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]));
|
||||||
|
|
||||||
|
$response->assertStatus(401);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_supervisor_without_permission_cannot_verify_road_item(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
Gate::shouldReceive('allows')
|
||||||
|
->andReturn(false);
|
||||||
|
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id,]));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
public function test_validation_fails_when_required_fields_are_missing(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
|
||||||
|
Gate::shouldReceive('allows')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'verify' => __('validation.required', ['attribute' => 'verify']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_validation_fails_when_verify_field_is_invalid(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
|
||||||
|
Gate::shouldReceive('allows')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]), [
|
||||||
|
'verify' => 5,
|
||||||
|
'description' => $this->faker()->sentence(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'verify' => __('validation.in', ['attribute' => 'verify']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_verify_description_must_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
|
||||||
|
Gate::shouldReceive('allows')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id]), [
|
||||||
|
'description' => 12345,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'description' => __('validation.string', ['attribute' =>"توضیحات"]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function test_supervisor_can_view_road_item_data(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
LogList::factory()->create([
|
||||||
|
'log_unique_code' => 1149,
|
||||||
|
]);
|
||||||
|
UserActivityLog::factory()->create();
|
||||||
|
|
||||||
|
$roadItem = RoadItemsProject::factory()->create();
|
||||||
|
|
||||||
|
Gate::shouldReceive('allows')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$description = fake()->sentence();
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.road_items.VerifyBySupervisor', [$roadItem->id,]), [
|
||||||
|
'verify' => 1,
|
||||||
|
'description' =>$description,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertJson([
|
||||||
|
'message' => __('messages.successful'),
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('road_items_projects', [
|
||||||
|
'id' => $roadItem->id,
|
||||||
|
'status' => 1,
|
||||||
|
'status_fa' => 'تایید شده',
|
||||||
|
'supervisor_id' => $user->id,
|
||||||
|
'supervisor_name' => $user->name,
|
||||||
|
'supervisor_description' =>$description,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user