use DataBaseTruncation instead of RefreshDataBase

This commit is contained in:
2024-04-14 14:13:16 +03:30
parent 8a87c201f6
commit 7e63c3eda0
35 changed files with 1927 additions and 194 deletions

View File

@@ -12,16 +12,14 @@ use App\Models\Permission;
use App\Models\Province;
use App\Models\User;
use App\Services\NominatimService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\DatabaseTruncation;
use Illuminate\Http\UploadedFile;
use Mockery\MockInterface;
use Tests\TestCase;
class StoreTest extends TestCase
{
use RefreshDatabase, WithFaker;
use DatabaseTruncation;
/**
* A basic feature test example.
*/
@@ -627,97 +625,6 @@ class StoreTest extends TestCase
]);
}
public function test_can_store_a_road_patrol_when_instant_action_is_0(): void
{
$city = City::factory()->create();
$edarateShari = EdarateShahri::factory()->create();
$logList = LogList::factory()->create([
'log_unique_code' => 1147
]);
$user = User::factory()
->has(Permission::factory([
'name' => 'add-road-patrol'
]))
->create([
'city_id' => $city->id,
'edarate_shahri_id' => $edarateShari->id
]);
$attributes = [
'start_point' => '12,12',
'end_point' => '13,13',
'officer_name' => $this->faker->name,
'officer_plaque' => $this->faker->numerify(),
'officer_phone_number' => $this->faker->numerify("###########"),
'start_time' => '2016-01-23 11:53',
'end_time' => '2017-01-23 11:53',
'observed_items' => [
[
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
'item_id' => 1,
'sub_item_id' => 1,
'local_name' => $this->faker->name(),
'instant_action' => 0,
'start_point' => '12,12',
'priority' => $this->faker->numberBetween(1, 3),
'priority_fa' => $this->faker->name,
]
]
];
$infoItem = InfoItem::factory()->create([
'item' => 1,
'sub_item' => 1,
]);
$mock = $this->mock(NominatimService::class, function (MockInterface $mock) {
$mock->shouldReceive('get_way_id_from_nominatim')->andReturn(0);
});
Sms::shouldReceive('sendSms');
$response = $this->actingAs($user)->postJson('v2/road_patrols/operator/store', $attributes);
$response->assertOk();
$this->assertDatabaseHas('road_patrols', [
'start_lat' => 12,
'start_lon' => 12,
'end_lat' => 13,
'end_lon' => 13,
'officer_name' => $attributes['officer_name'],
'officer_phone_number' => $attributes['officer_phone_number'],
'officer_plaque' => $attributes['officer_plaque'],
'operator_id' => $user->id,
'operator_name' => $user->name,
'province_id' => $user->province_id,
'province_fa' => $user->province_fa,
'city_id' => $user->city_id,
'city_fa' => $user->city_fa,
'edare_id' => $user->edarate_shahri_id,
'edare_name' => $user->edarate_shahri_name,
'start_way_id' => 0,
'end_way_id' => 0,
'status' => 0,
'status_fa' => 'در حال بررسی',
'start_time' => $attributes['start_time'],
'end_time' => $attributes['end_time'],
'description' => null,
]);
$this->assertDatabaseHas('observed_items', [
'item_id' => $infoItem->item,
'item_name' => $infoItem->item_str,
'sub_item_id' => $infoItem->sub_item,
'sub_item_name' => $infoItem->sub_item_str,
'local_name' => $attributes['observed_items'][0]['local_name'],
'description' => null,
'start_lat' => 12,
'start_lon' => 12,
]);
}
public function test_end_point_is_required_when_instant_action_is_1(): void
{
$city = City::factory()->create();
@@ -981,11 +888,12 @@ class StoreTest extends TestCase
'end_time' => '2017-01-23 11:53',
'observed_items' => [
[
'start_point' => '12,12',
'end_point' => '13,13',
'item_id' => 1,
'sub_item_id' => 1,
'local_name' => $this->faker->name(),
'instant_action' => 1,
'start_point' => '12,12',
'priority' => $this->faker->numberBetween(1, 3),
'priority_fa' => $this->faker->name,
'amount' => $this->faker->numberBetween(1, 10)
@@ -996,6 +904,7 @@ class StoreTest extends TestCase
$infoItem = InfoItem::factory()->create([
'item' => 1,
'sub_item' => 1,
'needs_end_point' => 1
]);
$mock = $this->mock(NominatimService::class, function (MockInterface $mock) {
@@ -1069,4 +978,95 @@ class StoreTest extends TestCase
'is_new' => 1,
]);
}
public function test_user_can_store_a_road_patrol_when_instant_action_is_0(): void
{
$city = City::factory()->create();
$edarateShari = EdarateShahri::factory()->create();
$logList = LogList::factory()->create([
'log_unique_code' => 1147
]);
$user = User::factory()
->has(Permission::factory([
'name' => 'add-road-patrol'
]))
->create([
'city_id' => $city->id,
'edarate_shahri_id' => $edarateShari->id
]);
$attributes = [
'start_point' => '12,12',
'end_point' => '13,13',
'officer_name' => $this->faker->name,
'officer_plaque' => $this->faker->numerify(),
'officer_phone_number' => $this->faker->numerify("###########"),
'start_time' => '2016-01-23 11:53',
'end_time' => '2017-01-23 11:53',
'observed_items' => [
[
'after_image' => UploadedFile::fake()->create('image.jpg', 10),
'item_id' => 1,
'sub_item_id' => 1,
'local_name' => $this->faker->name(),
'instant_action' => 0,
'start_point' => '12,12',
'priority' => $this->faker->numberBetween(1, 3),
'priority_fa' => $this->faker->name,
]
]
];
$infoItem = InfoItem::factory()->create([
'item' => 1,
'sub_item' => 1,
]);
$mock = $this->mock(NominatimService::class, function (MockInterface $mock) {
$mock->shouldReceive('get_way_id_from_nominatim')->andReturn(0);
});
Sms::shouldReceive('sendSms');
$response = $this->actingAs($user)->postJson('v2/road_patrols/operator/store', $attributes);
$response->assertOk();
$this->assertDatabaseHas('road_patrols', [
'start_lat' => 12,
'start_lon' => 12,
'end_lat' => 13,
'end_lon' => 13,
'officer_name' => $attributes['officer_name'],
'officer_phone_number' => $attributes['officer_phone_number'],
'officer_plaque' => $attributes['officer_plaque'],
'operator_id' => $user->id,
'operator_name' => $user->name,
'province_id' => $user->province_id,
'province_fa' => $user->province_fa,
'city_id' => $user->city_id,
'city_fa' => $user->city_fa,
'edare_id' => $user->edarate_shahri_id,
'edare_name' => $user->edarate_shahri_name,
'start_way_id' => 0,
'end_way_id' => 0,
'status' => 0,
'status_fa' => 'در حال بررسی',
'start_time' => $attributes['start_time'],
'end_time' => $attributes['end_time'],
'description' => null,
]);
$this->assertDatabaseHas('observed_items', [
'item_id' => $infoItem->item,
'item_name' => $infoItem->item_str,
'sub_item_id' => $infoItem->sub_item,
'sub_item_name' => $infoItem->sub_item_str,
'local_name' => $attributes['observed_items'][0]['local_name'],
'description' => null,
'start_lat' => 12,
'start_lon' => 12,
]);
}
}