From 4b4f621b3420f318c2193049a760e48c5ed36844 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 16 Apr 2024 13:17:58 +0330 Subject: [PATCH] Revert "use RefreshDataBase and DB::transaction" This reverts commit 9f8855e8363e2d80546e890bf2cb5374a1034d34. --- app/Models/User.php | 132 +++++++++--------- .../Dashboard/RoadItemsProject/DeleteTest.php | 4 +- .../RoadItemsProject/RestoreTest.php | 4 +- .../Dashboard/RoadItemsProject/StoreTest.php | 4 +- .../Dashboard/RoadItemsProject/UpdateTest.php | 4 +- .../Dashboard/RoadObservation/CountTest.php | 4 +- .../Dashboard/RoadObservation/HandleTest.php | 3 +- .../Dashboard/RoadObservation/ReferTest.php | 4 +- .../Dashboard/RoadObservation/RestoreTest.php | 4 +- .../verifyBySupervisorTest.php | 4 +- .../RoadPatrolProject/DeleteTest.php | 4 +- .../RoadPatrolProject/GetAllDataToMapTest.php | 4 +- .../Dashboard/RoadPatrolProject/StoreTest.php | 4 +- .../Dashboard/SafetyAndPrivacy/DeleteTest.php | 4 +- .../Dashboard/SafetyAndPrivacy/DetailTest.php | 4 +- .../SafetyAndPrivacy/getAllDataToMapTest.php | 4 +- .../operatorFirstStepStoreTest.php | 113 +++++++-------- .../operatorSecondStepStoreTest.php | 4 +- .../operatorThirdStepStoreTest.php | 4 +- 19 files changed, 153 insertions(+), 159 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 233d5c67..dd207a20 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,12 +6,12 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Http\Request; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Illuminate\Support\Facades\DB; use Spatie\Permission\Traits\HasRoles; use Spatie\Permission\Traits\HasPermissions; use Illuminate\Database\Eloquent\Factories\HasFactory; use App\Models\UserActivityLog; use App\Models\LogList; +use DB; class User extends Authenticatable { @@ -60,10 +60,39 @@ class User extends Authenticatable public function addActivityComplete($log_unique_code, $model = null) { -// DB::beginTransaction(); + DB::beginTransaction(); try { - DB::transaction(function () use ($log_unique_code, $model){ + $temp = new UserActivityLog(); + $temp->user_id = $this->id; + $temp->username = $this->username; + $temp->user_name = $this->name; + $temp->user_first_name = $this->first_name; + $temp->user_last_name = $this->last_name; + $temp->position = $this->position; + $temp->mobile = $this->mobile; + $temp->province_id = $this->province_id; + $temp->province_fa = $this->province_fa; + $temp->city_id = $this->city_id; + $temp->city_fa = $this->city_fa; + + $log = LogList::where('log_unique_code', $log_unique_code)->first(); + $temp->log_unique_code = $log_unique_code; + $temp->description = $log->description; + $temp->action_type = $log->action_type; + + $temp->agent = request()->header('user-agent') ?? null; + $temp->method = request()->method() ?? null; + $temp->ip = request()->ip() ?? null; + $temp->url = request()->Url() ?? null; + $temp->query_parameter = serialize(request()->all()); + + $temp->model = serialize($model) ?? null; + $temp->save(); + DB::commit(); + } catch (\Throwable $th) { + DB::rollBack(); + try { $temp = new UserActivityLog(); $temp->user_id = $this->id; $temp->username = $this->username; @@ -81,80 +110,45 @@ class User extends Authenticatable $temp->log_unique_code = $log_unique_code; $temp->description = $log->description; $temp->action_type = $log->action_type; - + $temp->agent = request()->header('user-agent') ?? null; $temp->method = request()->method() ?? null; $temp->ip = request()->ip() ?? null; $temp->url = request()->Url() ?? null; - $temp->query_parameter = serialize(request()->all()); - + $temp->query_parameter = serialize(request()->input()); + $temp->model = serialize($model) ?? null; $temp->save(); - }); -// DB::commit(); - } catch (\Throwable $th) { -// DB::rollBack(); - try { - DB::transaction(function () use ($log_unique_code, $model){ - $temp = new UserActivityLog(); - $temp->user_id = $this->id; - $temp->username = $this->username; - $temp->user_name = $this->name; - $temp->user_first_name = $this->first_name; - $temp->user_last_name = $this->last_name; - $temp->position = $this->position; - $temp->mobile = $this->mobile; - $temp->province_id = $this->province_id; - $temp->province_fa = $this->province_fa; - $temp->city_id = $this->city_id; - $temp->city_fa = $this->city_fa; - - $log = LogList::where('log_unique_code', $log_unique_code)->first(); - $temp->log_unique_code = $log_unique_code; - $temp->description = $log->description; - $temp->action_type = $log->action_type; - - $temp->agent = request()->header('user-agent') ?? null; - $temp->method = request()->method() ?? null; - $temp->ip = request()->ip() ?? null; - $temp->url = request()->Url() ?? null; - $temp->query_parameter = serialize(request()->input()); - - $temp->model = serialize($model) ?? null; - $temp->save(); - }); -// DB::commit(); + DB::commit(); } catch (\Throwable $th) { -// DB::rollBack(); - DB::transaction(function () use ($log_unique_code, $model) { - $temp = new UserActivityLog(); - $temp->user_id = $this->id; - $temp->username = $this->username; - $temp->user_name = $this->name; - $temp->user_first_name = $this->first_name; - $temp->user_last_name = $this->last_name; - $temp->position = $this->position; - $temp->mobile = $this->mobile; - $temp->province_id = $this->province_id; - $temp->province_fa = $this->province_fa; - $temp->city_id = $this->city_id; - $temp->city_fa = $this->city_fa; + DB::rollBack(); + $temp = new UserActivityLog(); + $temp->user_id = $this->id; + $temp->username = $this->username; + $temp->user_name = $this->name; + $temp->user_first_name = $this->first_name; + $temp->user_last_name = $this->last_name; + $temp->position = $this->position; + $temp->mobile = $this->mobile; + $temp->province_id = $this->province_id; + $temp->province_fa = $this->province_fa; + $temp->city_id = $this->city_id; + $temp->city_fa = $this->city_fa; - $log = LogList::where('log_unique_code', $log_unique_code)->first(); - $temp->log_unique_code = $log_unique_code; - $temp->description = $log->description; - $temp->action_type = $log->action_type; - - $temp->agent = request()->header('user-agent') ?? null; - $temp->method = request()->method() ?? null; - $temp->ip = request()->ip() ?? null; - $temp->url = request()->Url() ?? null; - $temp->query_parameter = "Request is to big !!!!!"; - - $temp->model = serialize($model) ?? null; - $temp->save(); - }); -// DB::commit(); + $log = LogList::where('log_unique_code', $log_unique_code)->first(); + $temp->log_unique_code = $log_unique_code; + $temp->description = $log->description; + $temp->action_type = $log->action_type; + + $temp->agent = request()->header('user-agent') ?? null; + $temp->method = request()->method() ?? null; + $temp->ip = request()->ip() ?? null; + $temp->url = request()->Url() ?? null; + $temp->query_parameter = "Request is to big !!!!!"; + + $temp->model = serialize($model) ?? null; + $temp->save(); + DB::commit(); } } diff --git a/tests/Feature/V2/Dashboard/RoadItemsProject/DeleteTest.php b/tests/Feature/V2/Dashboard/RoadItemsProject/DeleteTest.php index 67aff95b..54d5e3ad 100644 --- a/tests/Feature/V2/Dashboard/RoadItemsProject/DeleteTest.php +++ b/tests/Feature/V2/Dashboard/RoadItemsProject/DeleteTest.php @@ -13,7 +13,7 @@ use App\Models\Province; use App\Models\RoadItemsProject; use App\Models\User; use App\Models\UserActivityLog; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Validation\ValidationException; @@ -22,7 +22,7 @@ use Tests\TestCase; class DeleteTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadItemsProject/RestoreTest.php b/tests/Feature/V2/Dashboard/RoadItemsProject/RestoreTest.php index d7946971..07b4bc60 100644 --- a/tests/Feature/V2/Dashboard/RoadItemsProject/RestoreTest.php +++ b/tests/Feature/V2/Dashboard/RoadItemsProject/RestoreTest.php @@ -13,7 +13,7 @@ use App\Models\Province; use App\Models\RoadItemsProject; use App\Models\User; use App\Models\UserActivityLog; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Validation\ValidationException; @@ -22,7 +22,7 @@ use Tests\TestCase; class RestoreTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadItemsProject/StoreTest.php b/tests/Feature/V2/Dashboard/RoadItemsProject/StoreTest.php index f89b01a0..da5146ed 100644 --- a/tests/Feature/V2/Dashboard/RoadItemsProject/StoreTest.php +++ b/tests/Feature/V2/Dashboard/RoadItemsProject/StoreTest.php @@ -13,7 +13,7 @@ use App\Models\Province; use App\Models\User; use App\Models\UserActivityLog; use App\Services\NominatimService; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Validation\ValidationException; @@ -22,7 +22,7 @@ use Tests\TestCase; class StoreTest extends TestCase { - use RefreshDatabase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadItemsProject/UpdateTest.php b/tests/Feature/V2/Dashboard/RoadItemsProject/UpdateTest.php index bda9c3db..94deb3f0 100644 --- a/tests/Feature/V2/Dashboard/RoadItemsProject/UpdateTest.php +++ b/tests/Feature/V2/Dashboard/RoadItemsProject/UpdateTest.php @@ -13,7 +13,7 @@ use App\Models\Province; use App\Models\RoadItemsProject; use App\Models\User; use App\Models\UserActivityLog; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Validation\ValidationException; @@ -22,7 +22,7 @@ use Tests\TestCase; class UpdateTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadObservation/CountTest.php b/tests/Feature/V2/Dashboard/RoadObservation/CountTest.php index 8f6471fd..21776794 100644 --- a/tests/Feature/V2/Dashboard/RoadObservation/CountTest.php +++ b/tests/Feature/V2/Dashboard/RoadObservation/CountTest.php @@ -7,12 +7,12 @@ use App\Models\Permission; use App\Models\Province; use App\Models\RoadObserved; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Tests\TestCase; class CountTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadObservation/HandleTest.php b/tests/Feature/V2/Dashboard/RoadObservation/HandleTest.php index 6728de02..af64c85e 100644 --- a/tests/Feature/V2/Dashboard/RoadObservation/HandleTest.php +++ b/tests/Feature/V2/Dashboard/RoadObservation/HandleTest.php @@ -9,7 +9,6 @@ use App\Models\RoadObserved; use App\Models\User; use App\Services\NikarayanService; use Illuminate\Foundation\Testing\DatabaseTruncation; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Mockery\MockInterface; @@ -17,7 +16,7 @@ use Tests\TestCase; class HandleTest extends TestCase { - use RefreshDatabase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadObservation/ReferTest.php b/tests/Feature/V2/Dashboard/RoadObservation/ReferTest.php index 4d8f250f..f7e639ba 100644 --- a/tests/Feature/V2/Dashboard/RoadObservation/ReferTest.php +++ b/tests/Feature/V2/Dashboard/RoadObservation/ReferTest.php @@ -6,12 +6,12 @@ use App\Models\EdarateShahri; use App\Models\LogList; use App\Models\RoadObserved; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Tests\TestCase; class ReferTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadObservation/RestoreTest.php b/tests/Feature/V2/Dashboard/RoadObservation/RestoreTest.php index dc960d8c..b4d19b52 100644 --- a/tests/Feature/V2/Dashboard/RoadObservation/RestoreTest.php +++ b/tests/Feature/V2/Dashboard/RoadObservation/RestoreTest.php @@ -6,12 +6,12 @@ use App\Models\LogList; use App\Models\Permission; use App\Models\RoadObserved; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Tests\TestCase; class RestoreTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadObservation/verifyBySupervisorTest.php b/tests/Feature/V2/Dashboard/RoadObservation/verifyBySupervisorTest.php index 6a8c989c..8e58b11b 100644 --- a/tests/Feature/V2/Dashboard/RoadObservation/verifyBySupervisorTest.php +++ b/tests/Feature/V2/Dashboard/RoadObservation/verifyBySupervisorTest.php @@ -6,12 +6,12 @@ use App\Models\LogList; use App\Models\Permission; use App\Models\RoadObserved; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Tests\TestCase; class verifyBySupervisorTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadPatrolProject/DeleteTest.php b/tests/Feature/V2/Dashboard/RoadPatrolProject/DeleteTest.php index eb557007..0803ba31 100644 --- a/tests/Feature/V2/Dashboard/RoadPatrolProject/DeleteTest.php +++ b/tests/Feature/V2/Dashboard/RoadPatrolProject/DeleteTest.php @@ -11,12 +11,12 @@ use App\Models\ObservedItem; use App\Models\Permission; use App\Models\RoadPatrol; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Tests\TestCase; class DeleteTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadPatrolProject/GetAllDataToMapTest.php b/tests/Feature/V2/Dashboard/RoadPatrolProject/GetAllDataToMapTest.php index 0fc2c3c4..c68e62de 100644 --- a/tests/Feature/V2/Dashboard/RoadPatrolProject/GetAllDataToMapTest.php +++ b/tests/Feature/V2/Dashboard/RoadPatrolProject/GetAllDataToMapTest.php @@ -5,12 +5,12 @@ namespace Tests\Feature\V2\Dashboard\RoadPatrolProject; use App\Models\Province; use App\Models\RoadPatrol; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDataBase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Tests\TestCase; class GetAllDataToMapTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/RoadPatrolProject/StoreTest.php b/tests/Feature/V2/Dashboard/RoadPatrolProject/StoreTest.php index 5872ae63..348e31ab 100644 --- a/tests/Feature/V2/Dashboard/RoadPatrolProject/StoreTest.php +++ b/tests/Feature/V2/Dashboard/RoadPatrolProject/StoreTest.php @@ -12,14 +12,14 @@ use App\Models\Permission; use App\Models\Province; use App\Models\User; use App\Services\NominatimService; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Mockery\MockInterface; use Tests\TestCase; class StoreTest extends TestCase { - use RefreshDatabase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DeleteTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DeleteTest.php index d0ad8485..5f639e3f 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DeleteTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DeleteTest.php @@ -7,12 +7,12 @@ 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\DatabaseTruncation; use Tests\TestCase; class DeleteTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DetailTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DetailTest.php index 7b633b0e..4b275022 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DetailTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/DetailTest.php @@ -7,12 +7,12 @@ 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\DatabaseTruncation; use Tests\TestCase; class DetailTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/getAllDataToMapTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/getAllDataToMapTest.php index c5b55945..89415e0e 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/getAllDataToMapTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/getAllDataToMapTest.php @@ -7,12 +7,12 @@ 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\DatabaseTruncation; use Tests\TestCase; class getAllDataToMapTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php index 14da4b12..a5134329 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorFirstStepStoreTest.php @@ -12,14 +12,13 @@ use App\Models\User; use App\Models\UserActivityLog; use App\Services\NominatimService; use Illuminate\Foundation\Testing\DatabaseTruncation; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; use Mockery\MockInterface; use Tests\TestCase; class operatorFirstStepStoreTest extends TestCase { - use RefreshDatabase; + use DatabaseTruncation; /** * A basic feature test example. */ @@ -254,58 +253,60 @@ class operatorFirstStepStoreTest extends TestCase ]); } -// public function test_new_safety_and_privacy_can_be_stored(): void -// { -// $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 -// ]); -// } + 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 + ]; + + $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 + ]); + } } diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorSecondStepStoreTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorSecondStepStoreTest.php index 2efbf507..79505c68 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorSecondStepStoreTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorSecondStepStoreTest.php @@ -12,7 +12,7 @@ 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\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Mockery\MockInterface; @@ -20,7 +20,7 @@ use Tests\TestCase; class operatorSecondStepStoreTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */ diff --git a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorThirdStepStoreTest.php b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorThirdStepStoreTest.php index a8ae5981..e48cf799 100644 --- a/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorThirdStepStoreTest.php +++ b/tests/Feature/V2/Dashboard/SafetyAndPrivacy/operatorThirdStepStoreTest.php @@ -12,7 +12,7 @@ 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\DatabaseTruncation; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Mockery\MockInterface; @@ -20,7 +20,7 @@ use Tests\TestCase; class operatorThirdStepStoreTest extends TestCase { - use RefreshDataBase; + use DatabaseTruncation; /** * A basic feature test example. */