write test for safety and privacy controller
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\SafetyAndPrivacyReportAble;
|
||||
|
||||
class SafetyAndPrivacy extends Model
|
||||
{
|
||||
use SafetyAndPrivacyReportAble;
|
||||
use SafetyAndPrivacyReportAble, HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'recognize_picture',
|
||||
|
||||
23
database/factories/SafetyAndPrivacyFactory.php
Normal file
23
database/factories/SafetyAndPrivacyFactory.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\User>
|
||||
*/
|
||||
class SafetyAndPrivacyFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'edare_shahri_name' => $this->faker->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
51
tests/Feature/V2/Dashboard/SafetyAndPrivacy/DeleteTest.php
Normal file
51
tests/Feature/V2/Dashboard/SafetyAndPrivacy/DeleteTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V2\Dashboard\SafetyAndPrivacy;
|
||||
|
||||
use App\Models\LogList;
|
||||
use App\Models\Permission;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\User;
|
||||
use App\Models\UserActivityLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_user_should_have_delete_road_item_permission(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/delete/{$safetyAndPrivacy->id}");
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_can_delete_a_safety_and_privacy(): void
|
||||
{
|
||||
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||
$logList = LogList::factory()->create([
|
||||
'log_unique_code' => 1155
|
||||
]);
|
||||
$userActivityLog = UserActivityLog::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
'name' => 'delete-road-item'
|
||||
]))
|
||||
->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson("v2/safety_and_privacy/delete/{$safetyAndPrivacy->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertExactJson([
|
||||
'status' => 'succeed'
|
||||
]);
|
||||
}
|
||||
}
|
||||
50
tests/Feature/V2/Dashboard/SafetyAndPrivacy/DetailTest.php
Normal file
50
tests/Feature/V2/Dashboard/SafetyAndPrivacy/DetailTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V2\Dashboard\SafetyAndPrivacy;
|
||||
|
||||
use App\Models\LogList;
|
||||
use App\Models\Permission;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\User;
|
||||
use App\Models\UserActivityLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DetailTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_can_see_a_safety_and_privacy_detail(): void
|
||||
{
|
||||
$safetyAndPrivacy = SafetyAndPrivacy::factory()->create();
|
||||
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson("v2/safety_and_privacy/{$safetyAndPrivacy->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'id',
|
||||
'lat',
|
||||
'lon',
|
||||
'province_id',
|
||||
'province_fa',
|
||||
'city_id',
|
||||
'city_fa',
|
||||
'edare_shahri_id',
|
||||
'edare_shahri_name',
|
||||
'recognize_picture',
|
||||
'activity_date_time',
|
||||
'judiciary_document',
|
||||
'judiciary_document_upload_date',
|
||||
'action_picture',
|
||||
'info_id',
|
||||
'info_fa',
|
||||
'way_id'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V2\Dashboard\SafetyAndPrivacy;
|
||||
|
||||
use App\Models\LogList;
|
||||
use App\Models\Permission;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\User;
|
||||
use App\Models\UserActivityLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class getAllDataToMapTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_can_see_all_data_to_map(): void
|
||||
{
|
||||
$date_from = $this->faker->date;
|
||||
$date_to = $this->faker->date;
|
||||
|
||||
$user = User::factory()
|
||||
->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('v2.safety_and_privacy.report.map', [
|
||||
'date_from' => $date_from,
|
||||
'date_to' => $date_to
|
||||
]));
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'status',
|
||||
'count',
|
||||
'message',
|
||||
'data'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?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 Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class operatorSecondStepStoreTest 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/second_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/second_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/second_step/{$safetyAndPrivacy->id}");
|
||||
|
||||
$response->assertStatus(400)
|
||||
->assertExactJson([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_judiciary_document_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/second_step/{$safetyAndPrivacy->id}");
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'judiciary_document' => __('validation.required', ['attribute' => 'judiciary document'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_judiciary_document_should_be_array(): 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/second_step/{$safetyAndPrivacy->id}", [
|
||||
'judiciary_document' => $this->faker->name
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'judiciary_document' => __('validation.array', ['attribute' => 'judiciary document'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_judiciary_document_file_should_be_file_format(): 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/second_step/{$safetyAndPrivacy->id}", [
|
||||
'judiciary_document' => [
|
||||
['text']
|
||||
]
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertInvalid([
|
||||
'judiciary_document.0' => __('validation.file', ['attribute' => 'judiciary_document.0'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_new_second_safety_and_privacy_can_be_stored(): void
|
||||
{
|
||||
$this->withOutExceptionHandling();
|
||||
|
||||
$infoItem = InfoItem::factory()->create([
|
||||
'item' => 17
|
||||
]);
|
||||
$city = City::factory()->create();
|
||||
$edarateShari = EdarateShahri::factory()->create();
|
||||
$logList = LogList::factory()->create();
|
||||
$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 = [
|
||||
'point' => '12,12',
|
||||
'info_id' => $infoItem->id,
|
||||
'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) {
|
||||
$mock->shouldReceive('get_way_id_from_nominatim')
|
||||
->once()
|
||||
->andReturn(0);
|
||||
});
|
||||
|
||||
$response = $this->actingAs($user)->postJson('v2/safety_and_privacy/operator/first_step', $data);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('safety_and_privacy', [
|
||||
'lat' => 12,
|
||||
'lon' => 12,
|
||||
'operator_id' => $user->id,
|
||||
'operator_name' => $user->name,
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'info_id' => $infoItem->id,
|
||||
'city_id' => $city->id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'activity_date_time' => $data['activity_date']." ".$data['activity_time'],
|
||||
'edare_shahri_id' => $edarateShari->id,
|
||||
'edare_shahri_name' => $edarateShari->name,
|
||||
'way_id' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user