From c0d991cdc056f35096def46b31067a33061a418c Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 9 Mar 2024 13:59:02 +0330 Subject: [PATCH] write test for nominatim usage --- .env.testing | 65 ++++ app/Models/City.php | 2 + app/Models/EdarateOstani.php | 2 + app/Models/EdarateShahri.php | 2 + app/Models/InfoItem.php | 4 + app/Models/LogList.php | 5 +- app/Models/Permission.php | 12 + app/Models/UserActivityLog.php | 2 + database/factories/CityFactory.php | 23 ++ database/factories/EdarateOstaniFactory.php | 23 ++ database/factories/EdarateShahriFactory.php | 23 ++ database/factories/InfoItemFactory.php | 23 ++ database/factories/LogListFactory.php | 24 ++ database/factories/PermissionFactory.php | 23 ++ database/factories/UserActivityLogFactory.php | 23 ++ database/factories/UserFactory.php | 4 +- ...03_05_133823_create__geopoints_2_table.php | 4 +- ...4_03_05_133823_create__geopoints_table.php | 4 +- ...23_create_personal_access_tokens_table.php | 40 --- ...33823_create_road_items_projects_table.php | 2 +- ..._133823_create_telescope_entries_table.php | 39 --- ...23_create_telescope_entries_tags_table.php | 33 -- ...3823_create_telescope_monitoring_table.php | 30 -- ...n_keys_to_telescope_entries_tags_table.php | 32 -- phpunit.xml | 7 +- routes/v2.php | 1 + .../operatorFirstStepStoreTest.php | 282 +++++++++++++++++- 27 files changed, 550 insertions(+), 184 deletions(-) create mode 100644 .env.testing create mode 100644 app/Models/Permission.php create mode 100644 database/factories/CityFactory.php create mode 100644 database/factories/EdarateOstaniFactory.php create mode 100644 database/factories/EdarateShahriFactory.php create mode 100644 database/factories/InfoItemFactory.php create mode 100644 database/factories/LogListFactory.php create mode 100644 database/factories/PermissionFactory.php create mode 100644 database/factories/UserActivityLogFactory.php delete mode 100644 database/migrations/2024_03_05_133823_create_personal_access_tokens_table.php delete mode 100644 database/migrations/2024_03_05_133823_create_telescope_entries_table.php delete mode 100644 database/migrations/2024_03_05_133823_create_telescope_entries_tags_table.php delete mode 100644 database/migrations/2024_03_05_133823_create_telescope_monitoring_table.php delete mode 100644 database/migrations/2024_03_05_133826_add_foreign_keys_to_telescope_entries_tags_table.php diff --git a/.env.testing b/.env.testing new file mode 100644 index 00000000..9e25675d --- /dev/null +++ b/.env.testing @@ -0,0 +1,65 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY=base64:R0FQ6mq9Ar2n5ToqeseUNN6zh94JGDnECsjF/pLOqaM= +APP_DEBUG=false +APP_URL=https://rms.witel.ir + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=localhost +DB_PORT=3306 +DB_DATABASE=rms_db +DB_USERNAME=root +DB_PASSWORD=password + +DB_CONNECTION_2= +DB_HOST_2= +DB_PORT_2= +DB_DATABASE_2= +DB_USERNAME_2= +DB_PASSWORD_2= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + + +PAYMENT_USERNAME="cspay" +PAYMENT_PASSWORD="cspay123" +PAYMENT_LINK="https://payment.rmto.ir" + +RMS_VERSION=3.0 +RMS_CTO_PHONE_NUMBER="09380220400" + +TELESCOPE_RESPONSE_SIZE_LIMIT=128 + +DEBUGBAR_ENABLED=false \ No newline at end of file diff --git a/app/Models/City.php b/app/Models/City.php index d6c6f89e..0aa06865 100644 --- a/app/Models/City.php +++ b/app/Models/City.php @@ -2,10 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class City extends Model { + use HasFactory; /** * The attributes that should be hidden for arrays. * diff --git a/app/Models/EdarateOstani.php b/app/Models/EdarateOstani.php index 1254eda3..c677a37f 100644 --- a/app/Models/EdarateOstani.php +++ b/app/Models/EdarateOstani.php @@ -2,10 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class EdarateOstani extends Model { + use HasFactory; protected $table = 'edarate_ostani'; public function roadObserved() diff --git a/app/Models/EdarateShahri.php b/app/Models/EdarateShahri.php index 2bc84ee3..2bb8d025 100644 --- a/app/Models/EdarateShahri.php +++ b/app/Models/EdarateShahri.php @@ -2,10 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class EdarateShahri extends Model { + use HasFactory; protected $table = 'edarate_shahri'; public function cities() diff --git a/app/Models/InfoItem.php b/app/Models/InfoItem.php index 0b71ea2e..b47fc192 100644 --- a/app/Models/InfoItem.php +++ b/app/Models/InfoItem.php @@ -2,10 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class InfoItem extends Model { + use HasFactory; + + public $timestamps = false; public function roadItemsProjects() { diff --git a/app/Models/LogList.php b/app/Models/LogList.php index f200410c..c7831a54 100644 --- a/app/Models/LogList.php +++ b/app/Models/LogList.php @@ -2,9 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class LogList extends Model { - // + use HasFactory; + + public $timestamps = false; } \ No newline at end of file diff --git a/app/Models/Permission.php b/app/Models/Permission.php new file mode 100644 index 00000000..e559c90d --- /dev/null +++ b/app/Models/Permission.php @@ -0,0 +1,12 @@ + + */ +class CityFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name_fa' => $this->faker->name + ]; + } +} diff --git a/database/factories/EdarateOstaniFactory.php b/database/factories/EdarateOstaniFactory.php new file mode 100644 index 00000000..cb70e66c --- /dev/null +++ b/database/factories/EdarateOstaniFactory.php @@ -0,0 +1,23 @@ + + */ +class EdarateOstaniFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name_fa' => $this->faker->name + ]; + } +} diff --git a/database/factories/EdarateShahriFactory.php b/database/factories/EdarateShahriFactory.php new file mode 100644 index 00000000..ff6f9ab2 --- /dev/null +++ b/database/factories/EdarateShahriFactory.php @@ -0,0 +1,23 @@ + + */ +class EdarateShahriFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name_fa' => $this->faker->name + ]; + } +} diff --git a/database/factories/InfoItemFactory.php b/database/factories/InfoItemFactory.php new file mode 100644 index 00000000..23a901c1 --- /dev/null +++ b/database/factories/InfoItemFactory.php @@ -0,0 +1,23 @@ + + */ +class InfoItemFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'item' => $this->faker->randomNumber() + ]; + } +} diff --git a/database/factories/LogListFactory.php b/database/factories/LogListFactory.php new file mode 100644 index 00000000..e3a8ebe9 --- /dev/null +++ b/database/factories/LogListFactory.php @@ -0,0 +1,24 @@ + + */ +class LogListFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'description' => $this->faker->name, + 'log_unique_code' => 1134 + ]; + } +} diff --git a/database/factories/PermissionFactory.php b/database/factories/PermissionFactory.php new file mode 100644 index 00000000..f92e8630 --- /dev/null +++ b/database/factories/PermissionFactory.php @@ -0,0 +1,23 @@ + + */ +class PermissionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name + ]; + } +} diff --git a/database/factories/UserActivityLogFactory.php b/database/factories/UserActivityLogFactory.php new file mode 100644 index 00000000..e993202b --- /dev/null +++ b/database/factories/UserActivityLogFactory.php @@ -0,0 +1,23 @@ + + */ +class UserActivityLogFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'description' => $this->faker->name + ]; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index a335e139..f54ede76 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -17,7 +17,9 @@ class UserFactory extends Factory public function definition(): array { return [ - 'username' => $this->faker->name + 'username' => $this->faker->name, + 'enabled' => true, + 'confirmed' => 1 ]; } } diff --git a/database/migrations/2024_03_05_133823_create__geopoints_2_table.php b/database/migrations/2024_03_05_133823_create__geopoints_2_table.php index 388121dd..18177c12 100644 --- a/database/migrations/2024_03_05_133823_create__geopoints_2_table.php +++ b/database/migrations/2024_03_05_133823_create__geopoints_2_table.php @@ -16,8 +16,8 @@ return new class extends Migration Schema::create('_geopoints_2', function (Blueprint $table) { $table->integer('pid', true); $table->point('geopoint'); - - $table->spatialIndex(['geopoint'], 'geopoint'); +// +// $table->spatialIndex(['geopoint'], 'geopoint'); }); } diff --git a/database/migrations/2024_03_05_133823_create__geopoints_table.php b/database/migrations/2024_03_05_133823_create__geopoints_table.php index 97f7a65a..76c515f6 100644 --- a/database/migrations/2024_03_05_133823_create__geopoints_table.php +++ b/database/migrations/2024_03_05_133823_create__geopoints_table.php @@ -16,8 +16,8 @@ return new class extends Migration Schema::create('_geopoints', function (Blueprint $table) { $table->integer('pid', true); $table->point('geopoint'); - - $table->spatialIndex(['geopoint'], 'geopoint'); +// +// $table->spatialIndex(['geopoint'], 'geopoint'); }); } diff --git a/database/migrations/2024_03_05_133823_create_personal_access_tokens_table.php b/database/migrations/2024_03_05_133823_create_personal_access_tokens_table.php deleted file mode 100644 index f7cddbdc..00000000 --- a/database/migrations/2024_03_05_133823_create_personal_access_tokens_table.php +++ /dev/null @@ -1,40 +0,0 @@ -bigIncrements('id'); - $table->string('tokenable_type'); - $table->unsignedBigInteger('tokenable_id'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - - $table->index(['tokenable_type', 'tokenable_id']); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('personal_access_tokens'); - } -}; diff --git a/database/migrations/2024_03_05_133823_create_road_items_projects_table.php b/database/migrations/2024_03_05_133823_create_road_items_projects_table.php index a0dcfbb9..d3257d2d 100644 --- a/database/migrations/2024_03_05_133823_create_road_items_projects_table.php +++ b/database/migrations/2024_03_05_133823_create_road_items_projects_table.php @@ -27,7 +27,7 @@ return new class extends Migration $table->string('sub_item_fa')->nullable(); $table->longText('sub_item_data')->nullable(); $table->string('sub_items'); - $table->longText('sub_items_data')->nullable()->index('road_items_subss'); + $table->longText('sub_items_data')->nullable(); $table->timestamps(); $table->unsignedTinyInteger('province_id'); $table->string('province_fa')->nullable(); diff --git a/database/migrations/2024_03_05_133823_create_telescope_entries_table.php b/database/migrations/2024_03_05_133823_create_telescope_entries_table.php deleted file mode 100644 index ce1095d4..00000000 --- a/database/migrations/2024_03_05_133823_create_telescope_entries_table.php +++ /dev/null @@ -1,39 +0,0 @@ -bigIncrements('sequence'); - $table->char('uuid', 36)->unique(); - $table->char('batch_id', 36)->index(); - $table->string('family_hash')->nullable()->index(); - $table->boolean('should_display_on_index')->default(true); - $table->string('type', 20); - $table->longText('content'); - $table->dateTime('created_at')->nullable()->index(); - - $table->index(['type', 'should_display_on_index']); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('telescope_entries'); - } -}; diff --git a/database/migrations/2024_03_05_133823_create_telescope_entries_tags_table.php b/database/migrations/2024_03_05_133823_create_telescope_entries_tags_table.php deleted file mode 100644 index 6c9b6134..00000000 --- a/database/migrations/2024_03_05_133823_create_telescope_entries_tags_table.php +++ /dev/null @@ -1,33 +0,0 @@ -char('entry_uuid', 36); - $table->string('tag')->index(); - - $table->primary(['entry_uuid', 'tag']); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('telescope_entries_tags'); - } -}; diff --git a/database/migrations/2024_03_05_133823_create_telescope_monitoring_table.php b/database/migrations/2024_03_05_133823_create_telescope_monitoring_table.php deleted file mode 100644 index d9fb40a8..00000000 --- a/database/migrations/2024_03_05_133823_create_telescope_monitoring_table.php +++ /dev/null @@ -1,30 +0,0 @@ -string('tag')->primary(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('telescope_monitoring'); - } -}; diff --git a/database/migrations/2024_03_05_133826_add_foreign_keys_to_telescope_entries_tags_table.php b/database/migrations/2024_03_05_133826_add_foreign_keys_to_telescope_entries_tags_table.php deleted file mode 100644 index fedfff03..00000000 --- a/database/migrations/2024_03_05_133826_add_foreign_keys_to_telescope_entries_tags_table.php +++ /dev/null @@ -1,32 +0,0 @@ -foreign(['entry_uuid'])->references(['uuid'])->on('telescope_entries')->onUpdate('no action')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('telescope_entries_tags', function (Blueprint $table) { - $table->dropForeign('telescope_entries_tags_entry_uuid_foreign'); - }); - } -}; diff --git a/phpunit.xml b/phpunit.xml index ff19ac12..27aac949 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,8 +21,11 @@ - - + + + + + diff --git a/routes/v2.php b/routes/v2.php index 4bdab8bb..f9320de7 100644 --- a/routes/v2.php +++ b/routes/v2.php @@ -341,6 +341,7 @@ Route::prefix('safety_and_privacy')->group(function () { /** TEST routes begin */ use Illuminate\Http\Request; +use Illuminate\Support\Facades\Route; if (App::environment('local')) { Route::get('otp', function (Request $request) { diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php index 32c2778f..b6c94cd4 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php @@ -2,9 +2,17 @@ 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\User; +use App\Models\UserActivityLog; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Http\UploadedFile; use Tests\TestCase; class operatorFirstStepStoreTest extends TestCase @@ -17,8 +25,280 @@ class operatorFirstStepStoreTest extends TestCase { $user = User::factory()->create(); - $response = $this->post('v2/safety_and_privacy/operator/first_step'); + $response = $this->actingAs($user)->postJson('v2/safety_and_privacy/operator/first_step'); $response->assertForbidden(); } + + public function test_user_should_not_have_city_id(): void + { + $edarateOstani = EdarateOstani::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/first_step'); + + $response->assertStatus(400) + ->assertExactJson([ + 'message' => 'امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!' + ]); + } + + public function test_user_should_not_have_edarate_shahri_id(): void + { + $city = City::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/first_step'); + + $response->assertStatus(400) + ->assertExactJson([ + 'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!' + ]); + } + + public function test_point_is_required(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step'); + + $response->assertUnprocessable() + ->assertInvalid([ + 'point' => __('validation.required', ['attribute' => 'point']) + ]); + } + + public function test_info_id_is_required(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step'); + + $response->assertUnprocessable() + ->assertInvalid([ + 'info_id' => __('validation.required', ['attribute' => 'info id']) + ]); + } + + public function test_activity_date_is_required(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step'); + + $response->assertUnprocessable() + ->assertInvalid([ + 'activity_date' => __('validation.required', ['attribute' => 'تاریخ فعالیت']) + ]); + } + + public function test_activity_date_should_match_the_format(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step', [ + 'activity_date' => $this->faker->date('d-m-Y-H-i-s') + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'activity_date' => __('validation.date_format', ['attribute' => 'تاریخ فعالیت', 'format' => 'Y-m-d']) + ]); + } + + public function test_activity_time_is_required(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step'); + + $response->assertUnprocessable() + ->assertInvalid([ + 'activity_time' => __('validation.required', ['attribute' => 'ساعت فعالیت']) + ]); + } + + public function test_activity_time_should_match_the_format(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step', [ + 'activity_time' => $this->faker->date('d-m-Y-H-i-s') + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'activity_time' => __('validation.date_format', ['attribute' => 'ساعت فعالیت', 'format' => 'H:i']) + ]); + } + + public function test_recognize_picture_is_required(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step'); + + $response->assertUnprocessable() + ->assertInvalid([ + 'recognize_picture' => __('validation.required', ['attribute' => 'recognize picture']) + ]); + } + + public function test_recognize_picture_should_be_image(): void + { + $city = City::factory()->create(); + $edarateShari = EdarateShahri::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/first_step', [ + 'recognize_picture' => $this->faker->name + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'recognize_picture' => __('validation.image', ['attribute' => 'recognize picture']) + ]); + } + + public function test_new_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 + ]; + + $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, + ]); + } }