write test for map
This commit is contained in:
@@ -477,6 +477,7 @@ class RoadPatrolProjectController extends Controller
|
|||||||
|
|
||||||
public function getAllDataToMap(Request $request)
|
public function getAllDataToMap(Request $request)
|
||||||
{
|
{
|
||||||
|
// dd($request->date_from, $request->date_to, $request->province_id, $request->edare_id);
|
||||||
$date_from = $request->date_from ? $request->date_from .' 00:00:00' : Date('Y-m-d') .' 00:00:00';
|
$date_from = $request->date_from ? $request->date_from .' 00:00:00' : Date('Y-m-d') .' 00:00:00';
|
||||||
$date_to = $request->date_to ? $request->date_to.' 23:59:59' : (new \DateTime('tomorrow'))->format('Y-m-d').' 23:59:59';
|
$date_to = $request->date_to ? $request->date_to.' 23:59:59' : (new \DateTime('tomorrow'))->format('Y-m-d').' 23:59:59';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class GetAllDataToMapTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*/
|
||||||
|
public function test_all_data_can_be_seen_with_no_filter(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
RoadPatrol::factory(7)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson('/v2/road_patrols/report/map');
|
||||||
|
|
||||||
|
$response->assertStatus(200)
|
||||||
|
->assertExactJson([
|
||||||
|
'status' => 'succeed',
|
||||||
|
'count' => 7,
|
||||||
|
'message' => '',
|
||||||
|
'data' => [
|
||||||
|
["id" => 1, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
["id" => 2, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
["id" => 3, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
["id" => 4, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
["id" => 5, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
["id" => 6, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
["id" => 7, "start_lat" => 0, "start_lon" => 0],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_all_data_can_be_seen_with_filter(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$province = Province::factory()->create();
|
||||||
|
|
||||||
|
RoadPatrol::factory()
|
||||||
|
->sequence(
|
||||||
|
['created_at' => '2022-05-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 1],
|
||||||
|
['created_at' => '2025-05-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 5],
|
||||||
|
['created_at' => '2022-05-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 9],
|
||||||
|
['created_at' => '2026-05-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 2],
|
||||||
|
['created_at' => '2022-05-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 6],
|
||||||
|
['created_at' => '2026-08-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 16],
|
||||||
|
['created_at' => '2022-05-03 12:25:00', 'province_id' => $province->id, 'edare_id' => 35],
|
||||||
|
)
|
||||||
|
->count(7)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
// $response = $this->actingAs($user)->getJson(route('v2.road_patrols.report.map', [
|
||||||
|
// 'date_from' => '2021-05-02',
|
||||||
|
// 'date_to' => '2024-09-01',
|
||||||
|
// 'province_id' => 1,
|
||||||
|
// 'edare_id' => 1,
|
||||||
|
// ]));
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->getJson('/v2/road_patrols/report/map?date_from=2021-05-02&date_to=2024-09-01&province_id=1&edare_id=1');
|
||||||
|
|
||||||
|
$response->assertStatus(200)
|
||||||
|
->assertExactJson([
|
||||||
|
'status' => 'succeed',
|
||||||
|
'count' => 1,
|
||||||
|
'message' => '',
|
||||||
|
'data' => [
|
||||||
|
[
|
||||||
|
"id" => 1,
|
||||||
|
"start_lat" => 0,
|
||||||
|
"start_lon" => 0
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\V2\Dashboard\RoadPatrolProject;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class MapTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase, WithFaker;
|
|
||||||
/**
|
|
||||||
* A basic feature test example.
|
|
||||||
*/
|
|
||||||
public function test_example(): void
|
|
||||||
{
|
|
||||||
$response = $this->get('/');
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user