create FMS service with test

This commit is contained in:
2024-04-22 11:28:19 +03:30
parent 5f839385f8
commit acd7c496b5
15 changed files with 701 additions and 67 deletions

View File

@@ -0,0 +1,248 @@
<?php
namespace Tests\Feature\Coridors;
use App\Models\Contracts;
use App\Models\ContractSubItems;
use App\Models\LogList;
use App\Models\Province;
use App\Models\RoadItemsProject;
use App\Models\RoadObserved;
use App\Models\RoadPatrol;
use App\Models\RoadPatrolProject;
use App\Models\User;
use App\Services\NominatimService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Mockery\MockInterface;
use Tests\TestCase;
class AxisReportByLatAndLngTest extends TestCase
{
use RefreshDatabase;
/**
* A basic feature test example.
*/
public function test_type_is_required_for_filtering(): void
{
$response = $this->getJson(route('api.axis-report'));
$response->assertStatus(400)
->assertExactJson([
'status' => 'error',
'message' => ' لطفا یک گزینه از فیلتر ها را انتخاب نمایید.'
]);
}
public function test_filtering_road_item_works_properly(): void
{
RoadItemsProject::factory()
->sequence(
["id" => 1, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 1, 'start_way_id' => 1, 'end_way_id' => 2],
["id" => 2, 'created_at' => '2025-05-03 12:25:00', 'info_id' => 2, 'start_way_id' => 5, 'end_way_id' => 3],
["id" => 3, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 5, 'start_way_id' => 9, 'end_way_id' => 4],
["id" => 4, 'created_at' => '2026-05-03 12:25:00', 'info_id' => 6, 'start_way_id' => 2, 'end_way_id' => 1],
["id" => 5, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 1, 'start_way_id' => 6, 'end_way_id' => 6],
["id" => 6, 'created_at' => '2026-08-03 12:25:00', 'info_id' => 9, 'start_way_id' => 16, 'end_way_id' => 7],
["id" => 7, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 2, 'start_way_id' => 35, 'end_way_id' => 9],
)
->count(7)
->create();
$this->mock(NominatimService::class, function (MockInterface $mock) {
$mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]);
});
$response = $this->getJson(route('api.axis-report', [
'date_to' => '2023-07-26',
'date_from' => '2021-07-26',
'daily_activity' => [1, 2],
'road_type' => 'test',
'slng' => '12',
'slat' => '12',
'dlng' => '13',
'dlat' => '13',
'type' => [1],
// 'contract_status' => '',
// 'project_type' => '',
]));
$response->assertStatus(200)
->assertExactJson([
'status' => 'success',
'data' => [
"roadObserved" => null,
"roadPatrolProject" => null,
"contractSubItems" => null,
'roadItemsProject' => [
[
"start_lat" => "0.0000000000",
"start_lng" => "0.0000000000",
"id" => 1
]
]
]
]);
}
public function test_filtering_road_patrol_works_properly(): void
{
RoadPatrol::factory()
->sequence(
["id" => 1, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 1, 'start_way_id' => 1, 'end_way_id' => 2],
["id" => 2, 'created_at' => '2025-05-03 12:25:00', 'start_lat' => 2, 'start_way_id' => 5, 'end_way_id' => 3],
["id" => 3, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 5, 'start_way_id' => 9, 'end_way_id' => 4],
["id" => 4, 'created_at' => '2026-05-03 12:25:00', 'start_lat' => 6, 'start_way_id' => 2, 'end_way_id' => 1],
["id" => 5, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 1, 'start_way_id' => 6, 'end_way_id' => 6],
["id" => 6, 'created_at' => '2026-08-03 12:25:00', 'start_lat' => 9, 'start_way_id' => 16, 'end_way_id' => 7],
["id" => 7, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 2, 'start_way_id' => 35, 'end_way_id' => 9],
)
->count(7)
->create();
$this->mock(NominatimService::class, function (MockInterface $mock) {
$mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]);
});
$response = $this->getJson(route('api.axis-report', [
'date_to' => '2023-07-26',
'date_from' => '2021-07-26',
// 'daily_activity' => [1, 2],
'road_type' => 'test',
'slng' => '12',
'slat' => '12',
'dlng' => '13',
'dlat' => '13',
'type' => [2],
// 'contract_status' => '',
// 'project_type' => '',
]));
$response->assertStatus(200)
->assertExactJson([
'status' => 'success',
'data' => [
"roadObserved" => null,
"roadItemsProject" => null,
"contractSubItems" => null,
'roadPatrolProject' => [
[
"start_lat" => 1,
"start_lon" => 0,
"id" => 1
]
]
]
]);
}
public function test_filtering_road_observed_works_properly(): void
{
RoadObserved::factory()
->sequence(
["id" => 1, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 1, 'observed_way_id' => 1, 'fk_FeatureType' => 'test', 'rms_status' => 1],
["id" => 2, 'created_at' => '2025-05-03 12:25:00', 'handling_way_id' => 2, 'observed_way_id' => 5, 'fk_FeatureType' => 'fake'],
["id" => 3, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 5, 'observed_way_id' => 9, 'fk_FeatureType' => 'fake'],
["id" => 4, 'created_at' => '2026-05-03 12:25:00', 'handling_way_id' => 6, 'observed_way_id' => 2, 'fk_FeatureType' => 'fake'],
["id" => 5, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 1, 'observed_way_id' => 6, 'fk_FeatureType' => 'fake'],
["id" => 6, 'created_at' => '2026-08-03 12:25:00', 'handling_way_id' => 9, 'observed_way_id' => 16, 'fk_FeatureType' => 'fake'],
["id" => 7, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 2, 'observed_way_id' => 35, 'fk_FeatureType' => 'fake'],
)
->count(7)
->create();
$this->mock(NominatimService::class, function (MockInterface $mock) {
$mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]);
});
$response = $this->getJson(route('api.axis-report', [
'date_to' => '2023-07-26',
'date_from' => '2021-07-26',
// 'daily_activity' => [1, 2],
'road_type' => ['test'],
'slng' => '12',
'slat' => '12',
'dlng' => '13',
'dlat' => '13',
'type' => [4],
// 'contract_status' => '',
// 'project_type' => '',
]));
$response->assertStatus(200)
->assertExactJson([
'status' => 'success',
'data' => [
"roadItemsProject" => null,
"roadPatrolProject" => null,
"contractSubItems" => null,
'roadObserved' => [
[
"start_lat" => null,
"start_lng" => null,
"id" => 1
]
]
]
]);
}
public function test_filtering_contract_sub_items_works_properly(): void
{
$user = User::factory()->create();
LogList::factory()->create(['log_unique_code' => 1005]);
LogList::factory()->create(['log_unique_code' => 1006]);
LogList::factory()->create(['log_unique_code' => 1001]);
$this->actingAs($user);
ContractSubItems::factory()
->sequence(
["id" => 1, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 1, 'end_way_id' => 2],
["id" => 2, 'contract_date_from_parent_contract' => '2025-05-03 12:25:00', 'start_way_id' => 5, 'end_way_id' => 3],
["id" => 3, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 9, 'end_way_id' => 4],
["id" => 4, 'contract_date_from_parent_contract' => '2026-05-03 12:25:00', 'start_way_id' => 2, 'end_way_id' => 1],
["id" => 5, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 6, 'end_way_id' => 6],
["id" => 6, 'contract_date_from_parent_contract' => '2026-08-03 12:25:00', 'start_way_id' => 16, 'end_way_id' => 7],
["id" => 7, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 35, 'end_way_id' => 9],
)
->count(7)
->create();
$this->mock(NominatimService::class, function (MockInterface $mock) {
$mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]);
});
$response = $this->getJson(route('api.axis-report', [
'date_to' => '2023-07-26',
'date_from' => '2021-07-26',
// 'daily_activity' => [1, 2],
'road_type' => ['test'],
'slng' => '12',
'slat' => '12',
'dlng' => '13',
'dlat' => '13',
'type' => [3],
// 'contract_status' => '',
// 'project_type' => '',
]));
$response->assertStatus(200)
->assertExactJson([
'status' => 'success',
'data' => [
"roadItemsProject" => null,
"roadPatrolProject" => null,
"roadObserved" => null,
'contractSubItems' => [
[
"start_lat" => null,
"start_lng" => null,
"id" => 1
]
]
]
]);
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace Tests\Feature\Receipt;
use App\Models\Accident;
use App\Models\LogList;
use App\Models\User;
use App\Services\PaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Mockery\MockInterface;
use Tests\TestCase;
class CallPaymentStatusTest extends TestCase
{
use RefreshDatabase;
/**
* A basic feature test example.
*/
public function test_payment_status_will_return_by_the_service(): void
{
$user = User::factory()->create();
LogList::factory()->create(['log_unique_code' => 1130]);
$accident = Accident::factory()->create([
'final_amount' => $this->faker->numerify('##')
]);
$this->mock(PaymentService::class, function (MockInterface $mock) {
$mock->shouldReceive('callPaymentStatusBillApi')->andReturn(json_encode(['isPayed' => 1]));
});
$response = $this->actingAs($user)->postJson("/v2/receipt/call-payment-status/{$accident->id}");
$response->assertStatus(200)
->assertExactJson([
"accident_date" => $accident->accident_date,
"accident_time" => $accident->accident_time,
"accident_type" => $accident->accident_type,
"accident_type_fa" => $accident->accident_type_fa,
"axis_name" => $accident->axis_name,
"bill_code" => $accident->bill_code,
"city_fa" => $accident->city_fa,
"city_id" => $accident->city_id,
"created_at" => $accident->created_at,
"damage_picture1" => $accident->damage_picture1,
"damage_picture2" => $accident->damage_picture2,
"deposit_daghi_amount" => 0,
"deposit_daghi_image" => $accident->deposit_daghi_image,
"deposit_date" => $accident->deposit_date,
"deposit_insurance_amount" => 0,
"deposit_insurance_image" => $accident->deposit_insurance_image,
"driver_name" => $accident->driver_name,
"driver_national_code" => $accident->driver_national_code,
"driver_phone_number" => $accident->driver_phone_number,
"final_amount" => $accident->final_amount,
"id" => $accident->id,
"lat" => $accident->lat,
"lng" => $accident->lng,
"ojrate_nasb" => $accident->ojrate_nasb,
"plaque" => $accident->plaque,
"police_file" => $accident->police_file,
"police_file_date" => $accident->police_file_date,
"police_serial" => $accident->police_serial,
"province_fa" => $accident->province_fa,
"province_id" => $accident->province_id,
"report_base" => $accident->report_base,
"status" => 0,
"status_fa" => $accident->status_fa,
"status_history" => '0',
"sum" => $accident->sum,
"support_description" => $accident->support_description,
"updated_at" => $accident->updated_at,
"user_id" => $accident->user_id,
"way_id" => $accident->way_id
]);
}
public function test_payment_status_works_properly(): void
{
$user = User::factory()->create();
LogList::factory()->create(['log_unique_code' => 1130]);
$accident = Accident::factory()->create([
'final_amount' => $this->faker->numerify('0')
]);
$response = $this->actingAs($user)->postJson("/v2/receipt/call-payment-status/{$accident->id}");
$response->assertStatus(200)
->assertExactJson([
"accident_date" => $accident->accident_date,
"accident_time" => $accident->accident_time,
"accident_type" => $accident->accident_type,
"accident_type_fa" => $accident->accident_type_fa,
"axis_name" => $accident->axis_name,
"bill_code" => $accident->bill_code,
"city_fa" => $accident->city_fa,
"city_id" => $accident->city_id,
"created_at" => $accident->created_at,
"damage_picture1" => $accident->damage_picture1,
"damage_picture2" => $accident->damage_picture2,
"deposit_daghi_amount" => 0,
"deposit_daghi_image" => $accident->deposit_daghi_image,
"deposit_date" => $accident->deposit_date,
"deposit_insurance_amount" => 0,
"deposit_insurance_image" => $accident->deposit_insurance_image,
"driver_name" => $accident->driver_name,
"driver_national_code" => $accident->driver_national_code,
"driver_phone_number" => $accident->driver_phone_number,
"final_amount" => $accident->final_amount,
"id" => $accident->id,
"lat" => $accident->lat,
"lng" => $accident->lng,
"ojrate_nasb" => $accident->ojrate_nasb,
"plaque" => $accident->plaque,
"police_file" => $accident->police_file,
"police_file_date" => $accident->police_file_date,
"police_serial" => $accident->police_serial,
"province_fa" => $accident->province_fa,
"province_id" => $accident->province_id,
"report_base" => $accident->report_base,
"status" => 0,
"status_fa" => $accident->status_fa,
"status_history" => '0',
"sum" => $accident->sum,
"support_description" => $accident->support_description,
"updated_at" => $accident->updated_at,
"user_id" => $accident->user_id,
"way_id" => $accident->way_id
]);
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Tests\Feature\Receipt;
use App\Facades\Sms\Sms;
use App\Models\Accident;
use App\Models\LogList;
use App\Models\User;
use App\Services\PaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Mockery\MockInterface;
use Tests\TestCase;
class InvoiceBillTest extends TestCase
{
use RefreshDatabase;
/**
* A basic feature test example.
*/
public function test_invoice_bill_calls_the_service_and_return_data(): void
{
$user = User::factory()->create();
LogList::factory()->create(['log_unique_code' => 1129]);
$accident = Accident::factory()->create([
'sum' => $this->faker->numberBetween(21, 100),
'deposit_insurance_amount' => $this->faker->numberBetween(1, 10),
'deposit_daghi_amount' => $this->faker->numberBetween(1, 10),
]);
$final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount);
$this->mock(PaymentService::class, function (MockInterface $mock) {
$mock->shouldReceive('invoiceBillApi')->andReturn(0);
});
Sms::shouldReceive('sendSms');
$response = $this->actingAs($user)->postJson("/v2/receipt/invoice-bill/{$accident->id}");
$response->assertStatus(200)
->assertExactJson([
"accident_date" => $accident->accident_date,
"accident_time" => $accident->accident_time,
"accident_type" => $accident->accident_type,
"accident_type_fa" => $accident->accident_type_fa,
"axis_name" => $accident->axis_name,
"bill_code" => 0,
"city_fa" => $accident->city_fa,
"city_id" => $accident->city_id,
"created_at" => $accident->created_at,
"damage_picture1" => $accident->damage_picture1,
"damage_picture2" => $accident->damage_picture2,
"deposit_daghi_amount" => $accident->deposit_daghi_amount,
"deposit_daghi_image" => $accident->deposit_daghi_image,
"deposit_date" => $accident->deposit_date,
"deposit_insurance_amount" => $accident->deposit_insurance_amount,
"deposit_insurance_image" => $accident->deposit_insurance_image,
"driver_name" => $accident->driver_name,
"driver_national_code" => $accident->driver_national_code,
"driver_phone_number" => $accident->driver_phone_number,
"final_amount" => $final_amount,
"id" => $accident->id,
"lat" => $accident->lat,
"lng" => $accident->lng,
"ojrate_nasb" => $accident->ojrate_nasb,
"plaque" => $accident->plaque,
"police_file" => $accident->police_file,
"police_file_date" => $accident->police_file_date,
"police_serial" => $accident->police_serial,
"province_fa" => $accident->province_fa,
"province_id" => $accident->province_id,
"report_base" => $accident->report_base,
"status" => 0,
"status_fa" => $accident->status_fa,
"status_history" => '0',
"sum" => $accident->sum,
"support_description" => $accident->support_description,
"updated_at" => $accident->updated_at,
"user_id" => $accident->user_id,
"way_id" => $accident->way_id
]);
}
}