third step test
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Services\NominatimService;
|
|||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -151,16 +152,19 @@ class operatorSecondStepStoreTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_new_second_safety_and_privacy_can_be_stored(): void
|
public function test_second_safety_and_privacy(): void
|
||||||
{
|
{
|
||||||
$this->withOutExceptionHandling();
|
$this->withOutExceptionHandling();
|
||||||
|
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
$infoItem = InfoItem::factory()->create([
|
$infoItem = InfoItem::factory()->create([
|
||||||
'item' => 17
|
'item' => 17
|
||||||
]);
|
]);
|
||||||
$city = City::factory()->create();
|
$city = City::factory()->create();
|
||||||
$edarateShari = EdarateShahri::factory()->create();
|
$edarateShari = EdarateShahri::factory()->create();
|
||||||
$logList = LogList::factory()->create();
|
$logList = LogList::factory()->create([
|
||||||
|
'log_unique_code' => 1135,
|
||||||
|
]);
|
||||||
$userActivityLog = UserActivityLog::factory()->create();
|
$userActivityLog = UserActivityLog::factory()->create();
|
||||||
$image = UploadedFile::fake()->create('image.jpg', 10);
|
$image = UploadedFile::fake()->create('image.jpg', 10);
|
||||||
|
|
||||||
@@ -174,37 +178,28 @@ class operatorSecondStepStoreTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'point' => '12,12',
|
'judiciary_document' => [
|
||||||
'info_id' => $infoItem->id,
|
$image
|
||||||
'activity_date' => $this->faker->date('Y-m-d'),
|
]
|
||||||
'activity_time' => $this->faker->date('H:i'),
|
|
||||||
'recognize_picture' => $image
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$mock = $this->mock(NominatimService::class, function (MockInterface $mock) {
|
Storage::fake();
|
||||||
$mock->shouldReceive('get_way_id_from_nominatim')
|
|
||||||
->once()
|
|
||||||
->andReturn(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
$response = $this->actingAs($user)->postJson('v2/safety_and_privacy/operator/first_step', $data);
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/second_step/{$safetyAndPrivacy->id}", $data);
|
||||||
|
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
|
|
||||||
$this->assertDatabaseHas('safety_and_privacy', [
|
$this->assertDatabaseHas('safety_and_privacy', [
|
||||||
'lat' => 12,
|
'operator_id' => $safetyAndPrivacy->operator_id,
|
||||||
'lon' => 12,
|
'operator_name' => $safetyAndPrivacy->name,
|
||||||
'operator_id' => $user->id,
|
'province_id' => $safetyAndPrivacy->province_id,
|
||||||
'operator_name' => $user->name,
|
'province_fa' => $safetyAndPrivacy->province_fa,
|
||||||
'province_id' => $user->province_id,
|
'info_id' => $safetyAndPrivacy->info_id,
|
||||||
'province_fa' => $user->province_fa,
|
'city_id' => $safetyAndPrivacy->city_id,
|
||||||
'info_id' => $infoItem->id,
|
'city_fa' => $safetyAndPrivacy->city_fa,
|
||||||
'city_id' => $city->id,
|
'edare_shahri_id' => $safetyAndPrivacy->edare_shahri_id,
|
||||||
'city_fa' => $user->city_fa,
|
'edare_shahri_name' => $safetyAndPrivacy->edare_shahri_name,
|
||||||
'activity_date_time' => $data['activity_date']." ".$data['activity_time'],
|
'way_id' => $safetyAndPrivacy->way_id
|
||||||
'edare_shahri_id' => $edarateShari->id,
|
|
||||||
'edare_shahri_name' => $edarateShari->name,
|
|
||||||
'way_id' => 0
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\V2\Dashboard\SafetyAndPrivacy;
|
||||||
|
|
||||||
|
use App\Models\City;
|
||||||
|
use App\Models\EdarateOstani;
|
||||||
|
use App\Models\EdarateShahri;
|
||||||
|
use App\Models\InfoItem;
|
||||||
|
use App\Models\LogList;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\SafetyAndPrivacy;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\UserActivityLog;
|
||||||
|
use App\Services\NominatimService;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Mockery\MockInterface;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class operatorThirdStepStoreTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_user_should_have_add_safety_and_privacy_permission(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/third_step/{$safetyAndPrivacy->id}");
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_should_not_have_city_id(): void
|
||||||
|
{
|
||||||
|
$edarateOstani = EdarateOstani::factory()->create();
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'add-safety-and-privacy'
|
||||||
|
]))
|
||||||
|
->create([
|
||||||
|
'edarate_ostani_id' => $edarateOstani->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/third_step/{$safetyAndPrivacy->id}");
|
||||||
|
|
||||||
|
$response->assertStatus(400)
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => 'امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_should_not_have_edarate_shahri_id(): void
|
||||||
|
{
|
||||||
|
$city = City::factory()->create();
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'add-safety-and-privacy'
|
||||||
|
]))
|
||||||
|
->create([
|
||||||
|
'city_id' => $city->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/third_step/{$safetyAndPrivacy->id}");
|
||||||
|
|
||||||
|
$response->assertStatus(400)
|
||||||
|
->assertExactJson([
|
||||||
|
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_action_picture_is_required(): void
|
||||||
|
{
|
||||||
|
$city = City::factory()->create();
|
||||||
|
$edarateShari = EdarateShahri::factory()->create();
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'add-safety-and-privacy'
|
||||||
|
]))
|
||||||
|
->create([
|
||||||
|
'city_id' => $city->id,
|
||||||
|
'edarate_shahri_id' => $edarateShari->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/third_step/{$safetyAndPrivacy->id}");
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'action_picture' => __('validation.required', ['attribute' => 'action picture'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_action_picture_should_be_image(): void
|
||||||
|
{
|
||||||
|
$city = City::factory()->create();
|
||||||
|
$edarateShari = EdarateShahri::factory()->create();
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'add-safety-and-privacy'
|
||||||
|
]))
|
||||||
|
->create([
|
||||||
|
'city_id' => $city->id,
|
||||||
|
'edarate_shahri_id' => $edarateShari->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/third_step/{$safetyAndPrivacy->id}", [
|
||||||
|
'action_picture' => $this->faker->name
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable()
|
||||||
|
->assertInvalid([
|
||||||
|
'action_picture' => __('validation.image', ['attribute' => 'action picture'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_third_safety_and_privacy(): void
|
||||||
|
{
|
||||||
|
$this->withOutExceptionHandling();
|
||||||
|
|
||||||
|
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||||
|
$infoItem = InfoItem::factory()->create([
|
||||||
|
'item' => 17
|
||||||
|
]);
|
||||||
|
$city = City::factory()->create();
|
||||||
|
$edarateShari = EdarateShahri::factory()->create();
|
||||||
|
$logList = LogList::factory()->create([
|
||||||
|
'log_unique_code' => 1136,
|
||||||
|
]);
|
||||||
|
$userActivityLog = UserActivityLog::factory()->create();
|
||||||
|
$image = UploadedFile::fake()->create('image.jpg', 10);
|
||||||
|
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory([
|
||||||
|
'name' => 'add-safety-and-privacy'
|
||||||
|
]))
|
||||||
|
->create([
|
||||||
|
'city_id' => $city->id,
|
||||||
|
'edarate_shahri_id' => $edarateShari->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action_picture' => $image
|
||||||
|
];
|
||||||
|
|
||||||
|
Storage::fake();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/operator/third_step/{$safetyAndPrivacy->id}", $data);
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('safety_and_privacy', [
|
||||||
|
'operator_id' => $safetyAndPrivacy->operator_id,
|
||||||
|
'operator_name' => $safetyAndPrivacy->name,
|
||||||
|
'province_id' => $safetyAndPrivacy->province_id,
|
||||||
|
'province_fa' => $safetyAndPrivacy->province_fa,
|
||||||
|
'info_id' => $safetyAndPrivacy->info_id,
|
||||||
|
'city_id' => $safetyAndPrivacy->city_id,
|
||||||
|
'city_fa' => $safetyAndPrivacy->city_fa,
|
||||||
|
'edare_shahri_id' => $safetyAndPrivacy->edare_shahri_id,
|
||||||
|
'edare_shahri_name' => $safetyAndPrivacy->edare_shahri_name,
|
||||||
|
'way_id' => $safetyAndPrivacy->way_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user