write test for permission controller
This commit is contained in:
@@ -33,16 +33,14 @@ class SendRoadObservationToNikarayanCommand extends Command
|
|||||||
$this->info("Dispatching jobs with a delay between each...");
|
$this->info("Dispatching jobs with a delay between each...");
|
||||||
|
|
||||||
DB::transaction(function () use (&$count) {
|
DB::transaction(function () use (&$count) {
|
||||||
$delay = 0;
|
|
||||||
RoadObserved::query()
|
RoadObserved::query()
|
||||||
->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-13 23:59:59'])
|
->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-13 23:59:59'])
|
||||||
->chunkById(50, function ($roads) use (&$delay, &$count) {
|
->chunkById(50, function ($roads) use (&$count) {
|
||||||
foreach ($roads as $road) {
|
foreach ($roads as $road) {
|
||||||
$road->update(['status' => 1]);
|
$road->update(['status' => 1]);
|
||||||
SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addSeconds($delay));
|
SendRoadObservationToNikarayan::dispatch($road);
|
||||||
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with a {$delay} seconds delay.");
|
Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled.");
|
||||||
$this->info("Scheduled job for Road ID: {$road->id} {$delay}s");
|
$this->info("Scheduled job for Road ID: {$road->id}");
|
||||||
$delay += 3;
|
|
||||||
$count +=1;
|
$count +=1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,12 +45,14 @@ class SendRoadObservationToNikarayan implements ShouldQueue
|
|||||||
);
|
);
|
||||||
|
|
||||||
$soapClient = new SoapClient($url);
|
$soapClient = new SoapClient($url);
|
||||||
|
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
|
||||||
$soapClient->UpdateInfo_RoadObservedProblems($array);
|
Log::channel('road_observation_problem')->info(json_encode($result), [$this->roadObserved->id]);
|
||||||
}
|
}
|
||||||
catch (\Exception $exception){
|
catch (\Exception $exception){
|
||||||
Log::channel('road_observation_problem')->error($exception->getMessage(), [
|
Log::channel('road_observation_problem')->error($exception->getMessage(), [
|
||||||
'roadObserved' => $this->roadObserved,
|
'roadObserved' => $this->roadObserved->id,
|
||||||
|
'line' => $exception->getLine(),
|
||||||
|
'file' => $exception->getFile(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class NikarayanService
|
|||||||
|
|
||||||
$soapClient = new SoapClient($url);
|
$soapClient = new SoapClient($url);
|
||||||
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
|
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
|
||||||
Log::channel('nikarayan')->info($result);
|
Log::channel('nikarayan')->info(json_encode($result));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ return new class extends Migration
|
|||||||
$table->decimal('end_lat', 12, 10)->nullable();
|
$table->decimal('end_lat', 12, 10)->nullable();
|
||||||
$table->decimal('end_lng', 12, 10)->nullable();
|
$table->decimal('end_lng', 12, 10)->nullable();
|
||||||
$table->string('project_distance')->nullable();
|
$table->string('project_distance')->nullable();
|
||||||
$table->unsignedTinyInteger('item')->index('item');
|
$table->unsignedTinyInteger('item');//->index('item');
|
||||||
$table->string('item_fa')->nullable();
|
$table->string('item_fa')->nullable();
|
||||||
$table->integer('sub_item')->nullable();
|
$table->integer('sub_item')->nullable();
|
||||||
$table->string('sub_item_fa')->nullable();
|
$table->string('sub_item_fa')->nullable();
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ return new class extends Migration
|
|||||||
$table->string('action_type', 100)->nullable();
|
$table->string('action_type', 100)->nullable();
|
||||||
$table->text('model')->nullable();
|
$table->text('model')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->integer('mm')->nullable()->storedAs('month(`created_at`)');
|
$table->integer('mm')->nullable();//->storedAs('month(`created_at`)');
|
||||||
$table->integer('yy')->nullable()->storedAs('year(`created_at`)');
|
$table->integer('yy')->nullable();//->storedAs('year(`created_at`)');
|
||||||
$table->integer('dd')->nullable()->storedAs('dayofmonth(`created_at`)');
|
$table->integer('dd')->nullable();//->storedAs('dayofmonth(`created_at`)');
|
||||||
$table->integer('hh')->nullable()->storedAs('hour(`created_at`)');
|
$table->integer('hh')->nullable();//->storedAs('hour(`created_at`)');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||||
<env name="CACHE_DRIVER" value="array"/>
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
<env name="DB_CONNECTION" value="mysql"/>
|
<env name="DB_CONNECTION" value="sqlite"/>
|
||||||
<env name="DB_DATABASE" value="rms_test_db"/>
|
<env name="DB_DATABASE" value=":memory:"/>
|
||||||
<env name="MAIL_MAILER" value="array"/>
|
<env name="MAIL_MAILER" value="array"/>
|
||||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||||
<env name="SESSION_DRIVER" value="array"/>
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ Route::prefix('road_observations')
|
|||||||
|
|
||||||
Route::prefix('log_list')
|
Route::prefix('log_list')
|
||||||
->name('logList.')
|
->name('logList.')
|
||||||
|
->middleware('permission:manage-log-list')
|
||||||
->controller(LogListManagementController::class)
|
->controller(LogListManagementController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/', 'index')->name('index');
|
Route::get('/', 'index')->name('index');
|
||||||
@@ -372,6 +373,7 @@ Route::name('items.')
|
|||||||
|
|
||||||
Route::prefix('permissions')
|
Route::prefix('permissions')
|
||||||
->name('permissions.')
|
->name('permissions.')
|
||||||
|
->middleware('permission:manage-permissions')
|
||||||
->controller(PermissionManagementController::class)
|
->controller(PermissionManagementController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/', 'index')->name('index');
|
Route::get('/', 'index')->name('index');
|
||||||
|
|||||||
59
tests/Feature/V3/Permission/IndexTest.php
Normal file
59
tests/Feature/V3/Permission/IndexTest.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Permission;
|
||||||
|
|
||||||
|
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_manage_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.permissions.index'));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_all_permissions_returned_successfully(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson(route('v3.permissions.index', [
|
||||||
|
'start' => 0,
|
||||||
|
'size' => 10,
|
||||||
|
'filters' => json_encode([]),
|
||||||
|
'sorting' => json_encode([]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonStructure([
|
||||||
|
'data' => [
|
||||||
|
'*' => [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'name_fa',
|
||||||
|
'type',
|
||||||
|
'type_fa',
|
||||||
|
'description',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
"meta" => [
|
||||||
|
"totalRowCount"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
297
tests/Feature/V3/Permission/StoreTest.php
Normal file
297
tests/Feature/V3/Permission/StoreTest.php
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V3\Permission;
|
||||||
|
|
||||||
|
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_manage_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.required', ['attribute' => 'نام'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'name' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.string', ['attribute' => 'نام'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_attribute_should_be_unique(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$permission = Permission::factory()->create([
|
||||||
|
'name' => $this->faker->name()
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'name' => $permission->name,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name' => __('validation.unique', ['attribute' => 'نام'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_fa_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name_fa' => __('validation.required', ['attribute' => 'name fa'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_name_fa_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'name_fa' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'name_fa' => __('validation.string', ['attribute' => 'name fa'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_description_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'description' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'description' => __('validation.string', ['attribute' => 'توضیحات'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_type_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'type' => __('validation.required', ['attribute' => 'type'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_type_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'type' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'type' => __('validation.string', ['attribute' => 'type'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_type_fa_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'type_fa' => __('validation.required', ['attribute' => 'type fa'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_type_fa_attribute_should_be_string(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'type_fa' => $this->faker->numberBetween(1, 10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'type_fa' => __('validation.string', ['attribute' => 'type fa'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_need_province_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'need_province' => __('validation.required', ['attribute' => 'need province'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_need_province_attribute_should_be_1_or_0(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'need_province' => $this->faker->numberBetween(3, 9),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'need_province' => __('validation.in', ['attribute' => 'need province'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_need_edare_shahri_attribute_is_required(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'));
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'need_edare_shahri' => __('validation.required', ['attribute' => 'need edare shahri'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_need_edare_shahri_attribute_should_be_1_or_0(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), [
|
||||||
|
'need_edare_shahri' => $this->faker->numberBetween(3, 9),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'need_edare_shahri' => __('validation.in', ['attribute' => 'need edare shahri'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_can_create_a_permission()
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'manage-permissions'
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$inputData = [
|
||||||
|
'name' => $this->faker->name(),
|
||||||
|
'name_fa' => $this->faker->name(),
|
||||||
|
'description' => $this->faker->lexify(),
|
||||||
|
'type' => $this->faker->name(),
|
||||||
|
'type_fa' => $this->faker->name(),
|
||||||
|
'need_province' => $this->faker->numberBetween(0, 1),
|
||||||
|
'need_edare_shahri' => $this->faker->numberBetween(0, 1),
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.permissions.store'), $inputData);
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => __('messages.successful'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('permissions', $inputData);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user