@fleetbase/fleetops-engine 0.6.64 → 0.6.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASE.md +7 -5
- package/addon/components/attachment-list.hbs +65 -0
- package/addon/components/attachment-list.js +8 -0
- package/addon/components/cell/attached-vehicle.hbs +1 -1
- package/addon/components/cell/attached-vehicle.js +3 -3
- package/addon/components/cell/driver-identity.js +4 -4
- package/addon/components/cell/driver-name.hbs +1 -1
- package/addon/components/cell/translated-value.hbs +9 -0
- package/addon/components/cell/translated-value.js +57 -0
- package/addon/components/contact/card.hbs +58 -0
- package/addon/components/contact/card.js +19 -0
- package/addon/components/contact/form.hbs +1 -1
- package/addon/components/contact/panel-header.hbs +1 -1
- package/addon/components/customer/form.hbs +2 -2
- package/addon/components/device/manager.hbs +26 -28
- package/addon/components/device/manager.js +28 -2
- package/addon/components/device/panel-tabs/vehicle.hbs +13 -13
- package/addon/components/device/panel-tabs/vehicle.js +8 -0
- package/addon/components/driver/card.hbs +24 -13
- package/addon/components/driver/card.js +20 -6
- package/addon/components/driver/form.hbs +3 -3
- package/addon/components/driver/panel-header.hbs +2 -2
- package/addon/components/driver/pill.hbs +2 -2
- package/addon/components/equipment/form.js +11 -4
- package/addon/components/equipment/pill.hbs +20 -0
- package/addon/components/equipment/pill.js +3 -0
- package/addon/components/filter/multi-model.hbs +19 -0
- package/addon/components/filter/multi-model.js +90 -0
- package/addon/components/fleet/driver-listing.hbs +1 -1
- package/addon/components/fleet/vehicle-listing.hbs +1 -1
- package/addon/components/fleet-panel/driver-listing.hbs +1 -1
- package/addon/components/fleet-panel/vehicle-listing.hbs +1 -1
- package/addon/components/layout/fleet-ops-sidebar.js +9 -7
- package/addon/components/maintenance/form.js +12 -4
- package/addon/components/maintenance-schedule/form.js +13 -7
- package/addon/components/map/leaflet-live-map.hbs +52 -0
- package/addon/components/map/order-list-overlay/order.hbs +4 -4
- package/addon/components/modals/attach-equipment.hbs +22 -0
- package/addon/components/modals/attach-equipment.js +3 -0
- package/addon/components/modals/attach-telematic-device.hbs +13 -8
- package/addon/components/modals/attach-telematic-device.js +11 -1
- package/addon/components/modals/attach-trailer.hbs +30 -0
- package/addon/components/modals/attach-trailer.js +3 -0
- package/addon/components/modals/contact-form.hbs +2 -2
- package/addon/components/modals/convert-customer-to-vendor.hbs +1 -1
- package/addon/components/modals/driver-form.hbs +2 -2
- package/addon/components/modals/select-trailer.hbs +35 -0
- package/addon/components/modals/select-trailer.js +3 -0
- package/addon/components/modals/vehicle-form.hbs +2 -2
- package/addon/components/orchestrator/resource-panel.hbs +2 -2
- package/addon/components/order/customer-avatar-stack.hbs +2 -2
- package/addon/components/order/details/detail.hbs +4 -4
- package/addon/components/order/details/payload.hbs +2 -2
- package/addon/components/order/kanban-card.hbs +4 -4
- package/addon/components/order-list-overlay/order.hbs +4 -4
- package/addon/components/trailer/card.hbs +68 -0
- package/addon/components/trailer/card.js +22 -0
- package/addon/components/trailer/details/connections.hbs +57 -0
- package/addon/components/trailer/details/connections.js +59 -0
- package/addon/components/trailer/details/equipment.hbs +25 -0
- package/addon/components/trailer/details/equipment.js +52 -0
- package/addon/components/trailer/details/maintenance-history.hbs +47 -0
- package/addon/components/trailer/details/maintenance-history.js +40 -0
- package/addon/components/trailer/details/schedules.hbs +45 -0
- package/addon/components/trailer/details/schedules.js +40 -0
- package/addon/components/trailer/details/work-orders.hbs +47 -0
- package/addon/components/trailer/details/work-orders.js +40 -0
- package/addon/components/trailer/details.hbs +399 -0
- package/addon/components/trailer/details.js +118 -0
- package/addon/components/trailer/form.hbs +447 -0
- package/addon/components/trailer/form.js +165 -0
- package/addon/components/trailer/panel-header.hbs +45 -0
- package/addon/components/trailer/panel-header.js +3 -0
- package/addon/components/trailer/pill.hbs +21 -0
- package/addon/components/trailer/pill.js +3 -0
- package/addon/components/vehicle/card.hbs +42 -11
- package/addon/components/vehicle/card.js +31 -0
- package/addon/components/vehicle/details/equipment.hbs +25 -0
- package/addon/components/vehicle/details/equipment.js +55 -0
- package/addon/components/vehicle/details/trailers.hbs +35 -0
- package/addon/components/vehicle/details/trailers.js +55 -0
- package/addon/components/vehicle/form.hbs +2 -2
- package/addon/components/vehicle/panel-header.hbs +2 -2
- package/addon/components/vehicle/pill.hbs +2 -2
- package/addon/components/vendor/card.hbs +58 -0
- package/addon/components/vendor/card.js +6 -0
- package/addon/components/vendor/panel-header.hbs +2 -2
- package/addon/components/vendor/personnel-manager.hbs +2 -2
- package/addon/components/work-order/form.js +12 -4
- package/addon/controllers/connectivity/devices/index/details/vehicle.js +11 -0
- package/addon/controllers/connectivity/devices/index/details.js +3 -3
- package/addon/controllers/connectivity/devices/index.js +1 -0
- package/addon/controllers/connectivity/telematics/details/attachments.js +28 -47
- package/addon/controllers/connectivity/telematics/details/devices.js +1 -0
- package/addon/controllers/management/contacts/customers.js +4 -0
- package/addon/controllers/management/contacts/index.js +32 -0
- package/addon/controllers/management/trailers/index/details.js +119 -0
- package/addon/controllers/management/trailers/index/edit.js +67 -0
- package/addon/controllers/management/trailers/index/new.js +43 -0
- package/addon/controllers/management/trailers/index.js +599 -0
- package/addon/controllers/management/vehicles/index/details.js +16 -0
- package/addon/controllers/management/vehicles/index.js +78 -4
- package/addon/controllers/management/vendors/index.js +32 -0
- package/addon/controllers/operations/orders/index.js +3 -1
- package/addon/controllers/settings/custom-fields.js +8 -0
- package/addon/extension.js +7 -0
- package/addon/helpers/placeholder-image.js +6 -0
- package/addon/helpers/resource-image.js +10 -0
- package/addon/helpers/trailer-placeholder-image.js +6 -0
- package/addon/routes/management/trailers/index/details/connections.js +2 -0
- package/addon/routes/management/trailers/index/details/devices.js +2 -0
- package/addon/routes/management/trailers/index/details/equipment.js +2 -0
- package/addon/routes/management/trailers/index/details/index.js +2 -0
- package/addon/routes/management/trailers/index/details/maintenance-history.js +2 -0
- package/addon/routes/management/trailers/index/details/positions.js +2 -0
- package/addon/routes/management/trailers/index/details/schedules.js +2 -0
- package/addon/routes/management/trailers/index/details/work-orders.js +2 -0
- package/addon/routes/management/trailers/index/details.js +30 -0
- package/addon/routes/management/trailers/index/edit.js +23 -0
- package/addon/routes/management/trailers/index/new.js +14 -0
- package/addon/routes/management/trailers/index.js +42 -0
- package/addon/routes/management/vehicles/index/details/trailers.js +2 -0
- package/addon/routes/management/vehicles/index.js +7 -1
- package/addon/routes.js +17 -0
- package/addon/services/device-actions.js +26 -16
- package/addon/services/trailer-actions.js +394 -0
- package/addon/services/vehicle-actions.js +111 -0
- package/addon/styles/fleetops-engine.css +349 -0
- package/addon/templates/connectivity/devices/index/details/vehicle.hbs +19 -19
- package/addon/templates/connectivity/telematics/details/attachments.hbs +15 -15
- package/addon/templates/management/contacts/customers.hbs +48 -29
- package/addon/templates/management/contacts/index.hbs +52 -33
- package/addon/templates/management/trailers/index/details/connections.hbs +1 -0
- package/addon/templates/management/trailers/index/details/devices.hbs +1 -0
- package/addon/templates/management/trailers/index/details/equipment.hbs +1 -0
- package/addon/templates/management/trailers/index/details/index.hbs +1 -0
- package/addon/templates/management/trailers/index/details/maintenance-history.hbs +1 -0
- package/addon/templates/management/trailers/index/details/positions.hbs +1 -0
- package/addon/templates/management/trailers/index/details/schedules.hbs +1 -0
- package/addon/templates/management/trailers/index/details/work-orders.hbs +1 -0
- package/addon/templates/management/trailers/index/details.hbs +15 -0
- package/addon/templates/management/trailers/index/edit.hbs +12 -0
- package/addon/templates/management/trailers/index/new.hbs +11 -0
- package/addon/templates/management/trailers/index.hbs +67 -0
- package/addon/templates/management/vehicles/index/details/equipment.hbs +1 -1
- package/addon/templates/management/vehicles/index/details/trailers.hbs +1 -0
- package/addon/templates/management/vehicles/index/details.hbs +1 -1
- package/addon/templates/management/vendors/index.hbs +66 -32
- package/addon/utils/device-table-columns.js +10 -6
- package/addon/utils/live-map-card-content.js +56 -0
- package/addon/utils/placeholder-images.js +71 -0
- package/addon/utils/trailer-placeholder-image.js +11 -0
- package/app/components/attachment-list.js +1 -0
- package/app/components/cell/translated-value.js +1 -0
- package/app/components/contact/card.js +1 -0
- package/app/components/equipment/pill.js +1 -0
- package/app/components/filter/multi-model.js +1 -0
- package/app/components/modals/attach-equipment.js +1 -0
- package/app/components/modals/attach-trailer.js +1 -0
- package/app/components/modals/select-trailer.js +1 -0
- package/app/components/trailer/card.js +1 -0
- package/app/components/trailer/details/connections.js +1 -0
- package/app/components/trailer/details/equipment.js +1 -0
- package/app/components/trailer/details/maintenance-history.js +1 -0
- package/app/components/trailer/details/schedules.js +1 -0
- package/app/components/trailer/details/work-orders.js +1 -0
- package/app/components/trailer/details.js +1 -0
- package/app/components/trailer/form.js +1 -0
- package/app/components/trailer/panel-header.js +1 -0
- package/app/components/trailer/pill.js +1 -0
- package/app/components/vehicle/details/equipment.js +1 -0
- package/app/components/vehicle/details/trailers.js +1 -0
- package/app/components/vendor/card.js +1 -0
- package/app/controllers/management/trailers/index/details.js +1 -0
- package/app/controllers/management/trailers/index/edit.js +1 -0
- package/app/controllers/management/trailers/index/new.js +1 -0
- package/app/controllers/management/trailers/index.js +1 -0
- package/app/helpers/placeholder-image.js +1 -0
- package/app/helpers/resource-image.js +1 -0
- package/app/helpers/trailer-placeholder-image.js +1 -0
- package/app/routes/management/trailers/index/details/connections.js +1 -0
- package/app/routes/management/trailers/index/details/devices.js +1 -0
- package/app/routes/management/trailers/index/details/equipment.js +1 -0
- package/app/routes/management/trailers/index/details/index.js +1 -0
- package/app/routes/management/trailers/index/details/maintenance-history.js +1 -0
- package/app/routes/management/trailers/index/details/positions.js +1 -0
- package/app/routes/management/trailers/index/details/schedules.js +1 -0
- package/app/routes/management/trailers/index/details/work-orders.js +1 -0
- package/app/routes/management/trailers/index/details.js +1 -0
- package/app/routes/management/trailers/index/edit.js +1 -0
- package/app/routes/management/trailers/index/new.js +1 -0
- package/app/routes/management/trailers/index.js +1 -0
- package/app/routes/management/vehicles/index/details/trailers.js +1 -0
- package/app/services/trailer-actions.js +1 -0
- package/app/templates/management/trailers/index/details/connections.js +1 -0
- package/app/templates/management/trailers/index/details/devices.js +1 -0
- package/app/templates/management/trailers/index/details/equipment.js +1 -0
- package/app/templates/management/trailers/index/details/index.js +1 -0
- package/app/templates/management/trailers/index/details/maintenance-history.js +1 -0
- package/app/templates/management/trailers/index/details/positions.js +1 -0
- package/app/templates/management/trailers/index/details/schedules.js +1 -0
- package/app/templates/management/trailers/index/details/work-orders.js +1 -0
- package/app/templates/management/trailers/index/details.js +1 -0
- package/app/templates/management/trailers/index/edit.js +1 -0
- package/app/templates/management/trailers/index/new.js +1 -0
- package/app/templates/management/trailers/index.js +1 -0
- package/app/templates/management/vehicles/index/details/trailers.js +1 -0
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +1 -1
- package/server/migrations/2026_09_03_000001_add_first_class_trailer_columns_to_assets_table.php +58 -0
- package/server/migrations/2026_09_03_000002_create_asset_connections_table.php +43 -0
- package/server/migrations/2026_09_03_000003_create_device_installations_table.php +33 -0
- package/server/src/Auth/Schemas/FleetOps.php +7 -0
- package/server/src/Events/TrailerLocationChanged.php +70 -0
- package/server/src/Exceptions/DeviceAlreadyAttachedException.php +18 -0
- package/server/src/Exports/TrailerExport.php +31 -0
- package/server/src/Http/Controllers/Api/v1/Concerns/ResolvesFleetOpsApiResources.php +8 -2
- package/server/src/Http/Controllers/Api/v1/DeviceController.php +22 -15
- package/server/src/Http/Controllers/Api/v1/EquipmentController.php +47 -0
- package/server/src/Http/Controllers/Api/v1/TrailerController.php +362 -0
- package/server/src/Http/Controllers/Api/v1/VehicleController.php +1 -0
- package/server/src/Http/Controllers/Internal/v1/DeviceController.php +3 -0
- package/server/src/Http/Controllers/Internal/v1/LiveController.php +1 -1
- package/server/src/Http/Controllers/Internal/v1/SearchController.php +16 -0
- package/server/src/Http/Controllers/Internal/v1/TrailerController.php +360 -0
- package/server/src/Http/Controllers/Internal/v1/VehicleController.php +74 -0
- package/server/src/Http/Filter/EquipmentFilter.php +51 -0
- package/server/src/Http/Filter/OrderFilter.php +15 -0
- package/server/src/Http/Filter/TrailerFilter.php +269 -0
- package/server/src/Http/Filter/VehicleFilter.php +70 -3
- package/server/src/Http/Requests/CreateDeviceRequest.php +1 -1
- package/server/src/Http/Requests/CreateEquipmentRequest.php +1 -1
- package/server/src/Http/Requests/CreateTrailerRequest.php +54 -0
- package/server/src/Http/Requests/UpdateTrailerRequest.php +7 -0
- package/server/src/Http/Resources/v1/AssetConnection.php +90 -0
- package/server/src/Http/Resources/v1/Device.php +3 -1
- package/server/src/Http/Resources/v1/Equipment.php +3 -1
- package/server/src/Http/Resources/v1/Index/Vehicle.php +10 -0
- package/server/src/Http/Resources/v1/Trailer.php +199 -0
- package/server/src/Http/Resources/v1/Vehicle.php +2 -0
- package/server/src/Http/Resources/v1/VehicleWithoutDriver.php +3 -0
- package/server/src/Imports/TrailerImport.php +33 -0
- package/server/src/Models/Asset.php +39 -10
- package/server/src/Models/AssetConnection.php +43 -0
- package/server/src/Models/Device.php +39 -8
- package/server/src/Models/DeviceInstallation.php +27 -0
- package/server/src/Models/Equipment.php +2 -0
- package/server/src/Models/Trailer.php +181 -0
- package/server/src/Models/Vehicle.php +13 -0
- package/server/src/Providers/FleetOpsServiceProvider.php +4 -2
- package/server/src/Support/Ai/FleetOpsAiQueryResources.php +22 -0
- package/server/src/Support/Reporting/FleetOpsReportSchema.php +38 -0
- package/server/src/Support/Telematics/TelematicService.php +35 -0
- package/server/src/Support/TrailerSummary.php +35 -0
- package/server/src/routes.php +29 -0
- package/server/tests/CompactResourceSerializationTest.php +36 -0
- package/server/tests/ControllerFilterContractsTest.php +29 -0
- package/server/tests/Feature/Http/Api/DeviceControllerContractsTest.php +30 -13
- package/server/tests/Feature/Http/Api/TrailerControllerLifecycleTest.php +640 -0
- package/server/tests/Feature/Http/Internal/DeviceControllerContractsTest.php +20 -5
- package/server/tests/Feature/Http/Internal/LiveControllerEndpointsTest.php +19 -0
- package/server/tests/ModelAccessorContractsTest.php +10 -0
- package/server/tests/OrderFilterExecutionTest.php +5 -0
- package/server/tests/PublicApiControllerInputContractsTest.php +11 -0
- package/server/tests/PublicFleetOpsRestEndpointsTest.php +15 -3
- package/server/tests/ReportSchemaContractsTest.php +4 -0
- package/server/tests/TelematicsHardeningTest.php +4 -2
- package/server/tests/TrailerSupportCoverageTest.php +524 -0
- package/server/tests/Unit/Http/Resources/IndexVehicleResourceTest.php +35 -0
- package/server/tests/Unit/Models/EquipmentTest.php +22 -0
- package/server/tests/Unit/Models/ModelLookupFallbackSeamsTest.php +7 -3
- package/server/tests/Unit/Models/TrailerTest.php +204 -0
- package/server/tests/Unit/Support/Telematics/TelematicServiceTelemetryTest.php +93 -0
- package/server/tests/VehicleControllerHelperContractsTest.php +14 -0
- package/translations/ar-ae.yml +396 -0
- package/translations/bg-bg.yaml +424 -0
- package/translations/en-us.yaml +423 -0
- package/translations/es-pa.yaml +425 -0
- package/translations/fr-fr.yaml +424 -0
- package/translations/mn-mn.yaml +424 -0
- package/translations/pt-br.yaml +424 -0
- package/translations/ru-ru.yaml +424 -0
- package/translations/vi-vn.yaml +435 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Fleetbase\FleetOps\Exports\TrailerExport;
|
|
4
|
+
use Fleetbase\FleetOps\Http\Controllers\Api\v1\EquipmentController;
|
|
5
|
+
use Fleetbase\FleetOps\Http\Controllers\Api\v1\TrailerController;
|
|
6
|
+
use Fleetbase\FleetOps\Http\Controllers\Api\v1\VehicleController;
|
|
7
|
+
use Fleetbase\FleetOps\Http\Controllers\Internal\v1\TrailerController as InternalTrailerController;
|
|
8
|
+
use Fleetbase\FleetOps\Http\Controllers\Internal\v1\VehicleController as InternalVehicleController;
|
|
9
|
+
use Fleetbase\FleetOps\Http\Requests\CreateTrailerRequest;
|
|
10
|
+
use Fleetbase\FleetOps\Http\Requests\UpdateTrailerRequest;
|
|
11
|
+
use Fleetbase\FleetOps\Http\Resources\v1\Vehicle as VehicleResource;
|
|
12
|
+
use Fleetbase\FleetOps\Imports\TrailerImport;
|
|
13
|
+
use Fleetbase\FleetOps\Models\Trailer;
|
|
14
|
+
use Fleetbase\FleetOps\Models\Vehicle;
|
|
15
|
+
use Fleetbase\Http\Requests\ExportRequest;
|
|
16
|
+
use Fleetbase\Http\Requests\ImportRequest;
|
|
17
|
+
use Illuminate\Config\Repository;
|
|
18
|
+
use Illuminate\Database\ConnectionResolver;
|
|
19
|
+
use Illuminate\Database\Eloquent\Model as EloquentModel;
|
|
20
|
+
use Illuminate\Database\SQLiteConnection;
|
|
21
|
+
use Illuminate\Events\Dispatcher;
|
|
22
|
+
use Illuminate\Http\Request;
|
|
23
|
+
use Illuminate\Support\Carbon;
|
|
24
|
+
|
|
25
|
+
if (!function_exists('Fleetbase\\Support\\auth')) {
|
|
26
|
+
eval('namespace Fleetbase\\Support; function auth() { return new class { public function user() { return null; } public function id() { return null; } }; }');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!function_exists('Fleetbase\\FleetOps\\Http\\Controllers\\Api\\v1\\abort')) {
|
|
30
|
+
eval('namespace Fleetbase\\FleetOps\\Http\\Controllers\\Api\\v1; function abort($code, $message = "", array $headers = []) { throw new \\Symfony\\Component\\HttpKernel\\Exception\\HttpException($code, $message, null, $headers); }');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!function_exists('Fleetbase\\FleetOps\\Http\\Controllers\\Internal\\v1\\abort')) {
|
|
34
|
+
eval('namespace Fleetbase\\FleetOps\\Http\\Controllers\\Internal\\v1; function abort($code, $message = "", array $headers = []) { throw new \\Symfony\\Component\\HttpKernel\\Exception\\HttpException($code, $message, null, $headers); }');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!function_exists('Fleetbase\\FleetOps\\Http\\Controllers\\Api\\v1\\broadcast')) {
|
|
38
|
+
eval('namespace Fleetbase\\FleetOps\\Http\\Controllers\\Api\\v1; function broadcast($event) { return $event; }');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!class_exists('Fleetbase\\Http\\Requests\\ExportRequest', false)) {
|
|
42
|
+
eval('namespace Fleetbase\\Http\\Requests; class ExportRequest extends \\Illuminate\\Http\\Request {}');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!class_exists('Fleetbase\\Http\\Requests\\ImportRequest', false)) {
|
|
46
|
+
eval('namespace Fleetbase\\Http\\Requests; class ImportRequest extends \\Illuminate\\Http\\Request {}');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class FleetOpsTrailerControllerProbe extends TrailerController
|
|
50
|
+
{
|
|
51
|
+
public function mappedInput(Request $request): array
|
|
52
|
+
{
|
|
53
|
+
return $this->input($request);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected function queryTrailers(Request $request, callable $callback)
|
|
57
|
+
{
|
|
58
|
+
$query = Trailer::where('company_uuid', session('company'));
|
|
59
|
+
$callback($query, $request);
|
|
60
|
+
|
|
61
|
+
return $query->get();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class FleetOpsInternalTrailerSpreadsheetProbe extends InternalTrailerController
|
|
66
|
+
{
|
|
67
|
+
public array $downloads = [];
|
|
68
|
+
public array $imports = [];
|
|
69
|
+
|
|
70
|
+
protected function downloadExport(TrailerExport $export, string $fileName)
|
|
71
|
+
{
|
|
72
|
+
$this->downloads[] = [$export, $fileName];
|
|
73
|
+
|
|
74
|
+
return ['file' => $fileName];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected function createImport(): TrailerImport
|
|
78
|
+
{
|
|
79
|
+
$import = new TrailerImport();
|
|
80
|
+
$import->imported = 2;
|
|
81
|
+
|
|
82
|
+
return $import;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected function importFile(TrailerImport $import, string $path, string $disk): void
|
|
86
|
+
{
|
|
87
|
+
$this->imports[] = [$path, $disk];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
class FleetOpsTrailerExportRequestFake extends ExportRequest
|
|
92
|
+
{
|
|
93
|
+
public function array($key = null, $default = [])
|
|
94
|
+
{
|
|
95
|
+
return (array) $this->input($key, $default);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class FleetOpsTrailerImportRequestFake extends ImportRequest
|
|
100
|
+
{
|
|
101
|
+
public array $resolvedFiles = [];
|
|
102
|
+
|
|
103
|
+
public function resolveFilesFromIds(string $param = 'files')
|
|
104
|
+
{
|
|
105
|
+
return collect($this->resolvedFiles);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fleetOpsTrailerControllerDatabase(): SQLiteConnection
|
|
110
|
+
{
|
|
111
|
+
$pdo = new PDO('sqlite::memory:');
|
|
112
|
+
$pdo->sqliteCreateFunction('ST_PointFromText', fn ($wkt, $srid = 0, $axisOrder = null) => $wkt);
|
|
113
|
+
$pdo->sqliteCreateFunction('ST_GeomFromText', function ($wkt, $srid = 0, $axisOrder = null) {
|
|
114
|
+
if (is_string($wkt) && sscanf($wkt, 'POINT(%f %f)', $longitude, $latitude) === 2) {
|
|
115
|
+
return pack('V', (int) $srid) . pack('C', 1) . pack('V', 1) . pack('d', $longitude) . pack('d', $latitude);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return $wkt;
|
|
119
|
+
});
|
|
120
|
+
$connection = new SQLiteConnection($pdo);
|
|
121
|
+
$resolver = new ConnectionResolver(['default' => $connection, 'mysql' => $connection]);
|
|
122
|
+
$resolver->setDefaultConnection('mysql');
|
|
123
|
+
EloquentModel::setConnectionResolver($resolver);
|
|
124
|
+
EloquentModel::setEventDispatcher(new Dispatcher());
|
|
125
|
+
// Model hooks bind to the dispatcher present when a class boots; re-boot so the
|
|
126
|
+
// hooks of models booted by earlier test files land on this dispatcher.
|
|
127
|
+
EloquentModel::clearBootedModels();
|
|
128
|
+
$config = new Repository([
|
|
129
|
+
'activitylog' => ['enabled' => false, 'default_auth_driver' => null, 'default_log_name' => 'default'],
|
|
130
|
+
'api' => ['cache' => ['enabled' => false]],
|
|
131
|
+
'filesystems' => ['default' => 'local'],
|
|
132
|
+
]);
|
|
133
|
+
app()->instance('config', $config);
|
|
134
|
+
app()->instance(Illuminate\Contracts\Config\Repository::class, $config);
|
|
135
|
+
app()->instance(Spatie\Activitylog\CauserResolver::class, new class extends Spatie\Activitylog\CauserResolver {
|
|
136
|
+
public function __construct()
|
|
137
|
+
{
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public function resolve(EloquentModel|int|string|null $subject = null): ?EloquentModel
|
|
141
|
+
{
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
app()->instance('db', new class($connection) {
|
|
146
|
+
public function __construct(public SQLiteConnection $connection)
|
|
147
|
+
{
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public function connection($name = null): SQLiteConnection
|
|
151
|
+
{
|
|
152
|
+
return $this->connection;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public function __call($method, $arguments)
|
|
156
|
+
{
|
|
157
|
+
return $this->connection->{$method}(...$arguments);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
Illuminate\Support\Facades\DB::clearResolvedInstance('db');
|
|
161
|
+
app()->instance('db.schema', $connection->getSchemaBuilder());
|
|
162
|
+
app()->instance('responsecache', new class {
|
|
163
|
+
public function __call($method, $arguments)
|
|
164
|
+
{
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
app()->instance('request', Request::create('/'));
|
|
169
|
+
|
|
170
|
+
$schema = $connection->getSchemaBuilder();
|
|
171
|
+
$schema->create('assets', function ($table) {
|
|
172
|
+
$table->increments('id');
|
|
173
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'category_uuid', 'vendor_uuid', 'warranty_uuid', 'telematic_uuid', 'current_place_uuid', 'photo_uuid', 'name', 'description', 'code', 'type', 'body_type', 'asset_class', 'status', 'vin', 'plate_number', 'serial_number', 'make', 'model', 'year', 'color', 'usage_type', 'measurement_system', 'odometer', 'odometer_unit', 'ownership_type', 'purchased_at', 'lease_expires_at', 'financing_status', 'currency', 'acquisition_cost', 'current_value', 'insurance_value', 'depreciation_rate', 'length', 'width', 'height', 'tare_weight', 'gvwr', 'payload_capacity', 'cargo_volume', 'axle_count', 'tire_count', 'door_count', 'coupling_type', 'brake_type', 'abs_equipped', 'ebs_equipped', 'refrigerated', 'temperature_min', 'temperature_max', 'reefer_engine_hours', 'capacity', 'specs', 'attributes', 'notes', 'location', 'speed', 'heading', 'altitude', 'online', 'last_online_at', 'telematics', 'slug', '_key'] as $column) {
|
|
174
|
+
$table->string($column)->nullable();
|
|
175
|
+
}
|
|
176
|
+
$table->timestamps();
|
|
177
|
+
$table->softDeletes();
|
|
178
|
+
});
|
|
179
|
+
$schema->create('vehicles', function ($table) {
|
|
180
|
+
$table->increments('id');
|
|
181
|
+
foreach (['uuid', 'public_id', 'internal_id', 'company_uuid', 'name', 'display_name', 'plate_number', 'status', 'slug', '_key'] as $column) {
|
|
182
|
+
$table->string($column)->nullable();
|
|
183
|
+
}
|
|
184
|
+
$table->timestamps();
|
|
185
|
+
$table->softDeletes();
|
|
186
|
+
});
|
|
187
|
+
$schema->create('users', function ($table) {
|
|
188
|
+
$table->increments('id');
|
|
189
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'name', 'email', '_key'] as $column) {
|
|
190
|
+
$table->string($column)->nullable();
|
|
191
|
+
}
|
|
192
|
+
$table->timestamps();
|
|
193
|
+
$table->softDeletes();
|
|
194
|
+
});
|
|
195
|
+
$schema->create('drivers', function ($table) {
|
|
196
|
+
$table->increments('id');
|
|
197
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'user_uuid', 'vehicle_uuid', 'status', '_key'] as $column) {
|
|
198
|
+
$table->string($column)->nullable();
|
|
199
|
+
}
|
|
200
|
+
$table->timestamps();
|
|
201
|
+
$table->softDeletes();
|
|
202
|
+
});
|
|
203
|
+
$schema->create('asset_connections', function ($table) {
|
|
204
|
+
$table->increments('id');
|
|
205
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'connector_type', 'connector_uuid', 'connected_type', 'connected_uuid', 'active_connected_uuid', 'active_connector_position', 'relationship_type', 'position', 'connected_at', 'disconnected_at', 'source', 'confidence', 'notes', 'meta', 'created_by_uuid', 'updated_by_uuid', '_key'] as $column) {
|
|
206
|
+
$table->string($column)->nullable();
|
|
207
|
+
}
|
|
208
|
+
$table->timestamps();
|
|
209
|
+
$table->softDeletes();
|
|
210
|
+
});
|
|
211
|
+
foreach (['categories', 'vendors', 'warranties', 'files'] as $name) {
|
|
212
|
+
$schema->create($name, function ($table) {
|
|
213
|
+
$table->increments('id');
|
|
214
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'name', 'type', 'path', 'disk', 'status', '_key'] as $column) {
|
|
215
|
+
$table->string($column)->nullable();
|
|
216
|
+
}
|
|
217
|
+
$table->timestamps();
|
|
218
|
+
$table->softDeletes();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
foreach (['devices', 'equipments'] as $name) {
|
|
222
|
+
$schema->create($name, function ($table) {
|
|
223
|
+
$table->increments('id');
|
|
224
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'warranty_uuid', 'photo_uuid', 'name', 'attachable_type', 'attachable_uuid', 'equipable_type', 'equipable_uuid', 'status', '_key'] as $column) {
|
|
225
|
+
$table->string($column)->nullable();
|
|
226
|
+
}
|
|
227
|
+
$table->timestamps();
|
|
228
|
+
$table->softDeletes();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
$schema->create('custom_field_values', function ($table) {
|
|
232
|
+
$table->increments('id');
|
|
233
|
+
foreach (['uuid', 'company_uuid', 'custom_field_uuid', 'subject_uuid', 'subject_type', 'value', 'value_type'] as $column) {
|
|
234
|
+
$table->string($column)->nullable();
|
|
235
|
+
}
|
|
236
|
+
$table->timestamps();
|
|
237
|
+
$table->softDeletes();
|
|
238
|
+
});
|
|
239
|
+
$schema->create('custom_fields', function ($table) {
|
|
240
|
+
$table->increments('id');
|
|
241
|
+
foreach (['uuid', 'company_uuid', 'label', 'name', 'type'] as $column) {
|
|
242
|
+
$table->string($column)->nullable();
|
|
243
|
+
}
|
|
244
|
+
$table->timestamps();
|
|
245
|
+
$table->softDeletes();
|
|
246
|
+
});
|
|
247
|
+
$schema->create('maintenances', function ($table) {
|
|
248
|
+
$table->increments('id');
|
|
249
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'maintainable_type', 'maintainable_uuid', 'status', 'completed_at'] as $column) {
|
|
250
|
+
$table->string($column)->nullable();
|
|
251
|
+
}
|
|
252
|
+
$table->timestamps();
|
|
253
|
+
$table->softDeletes();
|
|
254
|
+
});
|
|
255
|
+
$schema->create('maintenance_schedules', function ($table) {
|
|
256
|
+
$table->increments('id');
|
|
257
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'subject_type', 'subject_uuid', 'status', 'next_due_at'] as $column) {
|
|
258
|
+
$table->string($column)->nullable();
|
|
259
|
+
}
|
|
260
|
+
$table->timestamps();
|
|
261
|
+
$table->softDeletes();
|
|
262
|
+
});
|
|
263
|
+
$schema->create('activity_log', function ($table) {
|
|
264
|
+
$table->increments('id');
|
|
265
|
+
foreach (['uuid', 'company_uuid', 'log_name', 'description', 'subject_type', 'subject_id', 'causer_type', 'causer_id', 'properties', 'event', 'batch_uuid'] as $column) {
|
|
266
|
+
$table->string($column)->nullable();
|
|
267
|
+
}
|
|
268
|
+
$table->timestamps();
|
|
269
|
+
});
|
|
270
|
+
$schema->create('positions', function ($table) {
|
|
271
|
+
$table->increments('id');
|
|
272
|
+
foreach (['uuid', 'public_id', 'company_uuid', 'subject_type', 'subject_uuid', 'destination_uuid', 'coordinates', 'heading', 'bearing', 'speed', 'altitude', '_key'] as $column) {
|
|
273
|
+
$table->string($column)->nullable();
|
|
274
|
+
}
|
|
275
|
+
$table->timestamps();
|
|
276
|
+
$table->softDeletes();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
session(['company' => 'company-trailer-api', 'user' => 'user-trailer-api']);
|
|
280
|
+
|
|
281
|
+
return $connection;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function fleetOpsSeedTrailerApi(SQLiteConnection $connection): void
|
|
285
|
+
{
|
|
286
|
+
$connection->table('assets')->insert([
|
|
287
|
+
['uuid' => 'trailer-api-1', 'public_id' => 'trailer_api_one', 'company_uuid' => 'company-trailer-api', 'name' => 'Trailer One', 'asset_class' => 'trailer', 'status' => 'available'],
|
|
288
|
+
['uuid' => 'trailer-api-2', 'public_id' => 'trailer_api_two', 'company_uuid' => 'company-trailer-api', 'name' => 'Trailer Two', 'asset_class' => 'trailer', 'status' => 'available'],
|
|
289
|
+
['uuid' => 'trailer-other', 'public_id' => 'trailer_other', 'company_uuid' => 'company-other', 'name' => 'Other Trailer', 'asset_class' => 'trailer', 'status' => 'available'],
|
|
290
|
+
]);
|
|
291
|
+
$connection->table('vehicles')->insert([
|
|
292
|
+
['uuid' => 'vehicle-api-1', 'public_id' => 'vehicle_api_one', 'internal_id' => 'TRUCK-1', 'company_uuid' => 'company-trailer-api', 'name' => 'Truck One'],
|
|
293
|
+
['uuid' => 'vehicle-api-2', 'public_id' => 'vehicle_api_two', 'internal_id' => 'TRUCK-2', 'company_uuid' => 'company-trailer-api', 'name' => 'Truck Two'],
|
|
294
|
+
]);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function fleetOpsCreateTrailerApiRequest(array $input): CreateTrailerRequest
|
|
298
|
+
{
|
|
299
|
+
return CreateTrailerRequest::create('/v1/trailers', 'POST', $input);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function fleetOpsUpdateTrailerApiRequest(array $input): UpdateTrailerRequest
|
|
303
|
+
{
|
|
304
|
+
return UpdateTrailerRequest::create('/v1/trailers/trailer_api_one', 'PATCH', $input);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
test('public trailer controller creates queries finds updates and deletes company trailers', function () {
|
|
308
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
309
|
+
fleetOpsSeedTrailerApi($connection);
|
|
310
|
+
$controller = new FleetOpsTrailerControllerProbe();
|
|
311
|
+
|
|
312
|
+
$created = $controller->create(fleetOpsCreateTrailerApiRequest(['name' => 'Created Trailer', 'type' => 'flatbed']));
|
|
313
|
+
expect($created)->not->toBeNull()
|
|
314
|
+
->and($connection->table('assets')->where('name', 'Created Trailer')->value('asset_class'))->toBe('trailer');
|
|
315
|
+
|
|
316
|
+
$query = $controller->query(Request::create('/v1/trailers', 'GET'));
|
|
317
|
+
expect($query->count())->toBe(3)
|
|
318
|
+
->and($controller->find('trailer_api_one'))->not->toBeNull()
|
|
319
|
+
->and($controller->find('missing')->getStatusCode())->toBe(404);
|
|
320
|
+
|
|
321
|
+
$updated = $controller->update('trailer_api_one', fleetOpsUpdateTrailerApiRequest(['name' => 'Renamed Trailer']));
|
|
322
|
+
expect($updated)->not->toBeNull()
|
|
323
|
+
->and($connection->table('assets')->where('uuid', 'trailer-api-1')->value('name'))->toBe('Renamed Trailer')
|
|
324
|
+
->and($controller->update('missing', fleetOpsUpdateTrailerApiRequest(['name' => 'Missing']))->getStatusCode())->toBe(404)
|
|
325
|
+
->and($controller->delete('missing')->getStatusCode())->toBe(404);
|
|
326
|
+
|
|
327
|
+
$deleted = $controller->delete('trailer_api_two');
|
|
328
|
+
expect($deleted)->not->toBeNull()
|
|
329
|
+
->and($connection->table('assets')->where('uuid', 'trailer-api-2')->whereNull('deleted_at')->count())->toBe(0);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test('public trailer input accepts coordinate forms and clears public relations', function () {
|
|
333
|
+
fleetOpsTrailerControllerDatabase();
|
|
334
|
+
$controller = new FleetOpsTrailerControllerProbe();
|
|
335
|
+
$coordinates = $controller->mappedInput(Request::create('/v1/trailers', 'POST', ['name' => 'Located', 'latitude' => 1.3, 'longitude' => 103.8]));
|
|
336
|
+
$point = $controller->mappedInput(Request::create('/v1/trailers', 'POST', ['name' => 'Located', 'location' => [103.8, 1.3]]));
|
|
337
|
+
$cleared = $controller->mappedInput(Request::create('/v1/trailers', 'POST', ['name' => 'No Relations', 'category' => '', 'vendor' => '', 'warranty' => '', 'photo' => '']));
|
|
338
|
+
expect($coordinates['location'])->not->toBeNull()
|
|
339
|
+
->and($point['location'])->not->toBeNull()
|
|
340
|
+
->and($cleared)->toMatchArray(['category_uuid' => null, 'vendor_uuid' => null, 'warranty_uuid' => null, 'photo_uuid' => null]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test('public trailer tracking persists positions and rejects stale and missing events', function () {
|
|
344
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
345
|
+
fleetOpsSeedTrailerApi($connection);
|
|
346
|
+
$controller = new TrailerController();
|
|
347
|
+
Carbon::setTestNow('2026-09-03 12:00:00');
|
|
348
|
+
|
|
349
|
+
$tracked = $controller->track('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/track', 'POST', ['latitude' => 1.3, 'longitude' => 103.8, 'speed' => 40, 'heading' => 180, 'altitude' => 10, 'odometer' => 1200, 'observed_at' => '2026-09-03 12:00:00']));
|
|
350
|
+
expect($tracked)->not->toBeNull()
|
|
351
|
+
->and($connection->table('positions')->count())->toBe(1);
|
|
352
|
+
|
|
353
|
+
$connection->table('assets')->where('uuid', 'trailer-api-1')->update(['telematics' => json_encode(['last_event_at' => '2026-09-03T12:00:00.000000Z'])]);
|
|
354
|
+
$controller->track('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/track', 'POST', ['latitude' => 1.2, 'longitude' => 103.7, 'observed_at' => '2026-09-03 11:00:00']));
|
|
355
|
+
expect($connection->table('positions')->count())->toBe(1)
|
|
356
|
+
->and($controller->track('missing', Request::create('/v1/trailers/missing/track', 'POST', ['latitude' => 1, 'longitude' => 2]))->getStatusCode())->toBe(404);
|
|
357
|
+
Carbon::setTestNow();
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('public trailer towing lifecycle is idempotent conflict safe and exposes history', function () {
|
|
361
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
362
|
+
fleetOpsSeedTrailerApi($connection);
|
|
363
|
+
$controller = new TrailerController();
|
|
364
|
+
|
|
365
|
+
$attached = $controller->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'vehicle_api_one', 'position' => 1, 'source' => 'dispatcher']));
|
|
366
|
+
expect($attached)->not->toBeNull()
|
|
367
|
+
->and($connection->table('asset_connections')->count())->toBe(1)
|
|
368
|
+
->and($controller->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'vehicle_api_one', 'position' => 1])))->not->toBeNull()
|
|
369
|
+
->and($connection->table('asset_connections')->count())->toBe(1);
|
|
370
|
+
|
|
371
|
+
expect($controller->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'vehicle_api_two']))->getStatusCode())->toBe(409)
|
|
372
|
+
->and($controller->delete('trailer_api_one')->getStatusCode())->toBe(409)
|
|
373
|
+
->and($controller->connections('trailer_api_one')->count())->toBe(1)
|
|
374
|
+
->and($controller->vehicleTrailers('vehicle_api_one')->count())->toBe(1)
|
|
375
|
+
->and($controller->connections('missing')->getStatusCode())->toBe(404)
|
|
376
|
+
->and($controller->vehicleTrailers('missing')->getStatusCode())->toBe(404);
|
|
377
|
+
|
|
378
|
+
expect($controller->detach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/detach', 'POST', ['notes' => 'Arrived']))->getStatusCode())->toBe(200)
|
|
379
|
+
->and($controller->detach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/detach', 'POST'))->getStatusCode())->toBe(200)
|
|
380
|
+
->and($controller->detach('missing', Request::create('/v1/trailers/missing/detach', 'POST'))->getStatusCode())->toBe(404);
|
|
381
|
+
|
|
382
|
+
$controller->attach('trailer_api_two', Request::create('/v1/trailers/trailer_api_two/attach', 'POST', ['vehicle' => 'vehicle_api_one', 'position' => 1]));
|
|
383
|
+
expect($controller->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'vehicle_api_one', 'position' => 1]))->getStatusCode())->toBe(409)
|
|
384
|
+
->and($controller->attach('missing', Request::create('/v1/trailers/missing/attach', 'POST', ['vehicle' => 'vehicle_api_one']))->getStatusCode())->toBe(404)
|
|
385
|
+
->and($controller->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'missing']))->getStatusCode())->toBe(404);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
class FleetOpsInternalTrailerAfterSaveFake extends Trailer
|
|
389
|
+
{
|
|
390
|
+
public array $syncedValues = [];
|
|
391
|
+
|
|
392
|
+
public function syncCustomFieldValues(array $values, array $options = []): array
|
|
393
|
+
{
|
|
394
|
+
$this->syncedValues[] = $values;
|
|
395
|
+
|
|
396
|
+
return $values;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
class FleetOpsInternalTrailerDeleteProbe extends InternalTrailerController
|
|
401
|
+
{
|
|
402
|
+
public array $deleted = [];
|
|
403
|
+
|
|
404
|
+
protected function deleteTrailerRecord($id, Request $request)
|
|
405
|
+
{
|
|
406
|
+
$this->deleted[] = $id;
|
|
407
|
+
|
|
408
|
+
return response()->json(['status' => 'deleted']);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
class FleetOpsVehicleExpansionProbe extends VehicleController
|
|
413
|
+
{
|
|
414
|
+
public function mapExpansions(Request $request): array
|
|
415
|
+
{
|
|
416
|
+
return $this->resolvePublicExpansions($request, static::EXPANDABLE);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
test('internal trailer controller syncs custom fields and manages towing', function () {
|
|
421
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
422
|
+
fleetOpsSeedTrailerApi($connection);
|
|
423
|
+
$controller = new InternalTrailerController();
|
|
424
|
+
$fake = new FleetOpsInternalTrailerAfterSaveFake();
|
|
425
|
+
$controller->afterSave(Request::create('/int/v1/trailers', 'POST', ['trailer' => ['custom_field_values' => ['door' => 'sealed']]]), $fake);
|
|
426
|
+
$controller->afterSave(Request::create('/int/v1/trailers', 'POST'), $fake);
|
|
427
|
+
expect($fake->syncedValues)->toBe([['door' => 'sealed']]);
|
|
428
|
+
|
|
429
|
+
expect($controller->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'vehicle-api-1', 'position' => 1]), 'trailer-api-1')->getStatusCode())->toBe(200)
|
|
430
|
+
->and($connection->table('asset_connections')->count())->toBe(1)
|
|
431
|
+
->and($controller->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'vehicle-api-1', 'position' => 1]), 'trailer-api-1')->getStatusCode())->toBe(200)
|
|
432
|
+
->and($connection->table('asset_connections')->count())->toBe(1)
|
|
433
|
+
->and($controller->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'vehicle-api-2']), 'trailer-api-1')->getStatusCode())->toBe(409)
|
|
434
|
+
->and($controller->attach(Request::create('/int/v1/trailers/missing/attach', 'POST', ['vehicle' => 'vehicle-api-1']), 'missing')->getStatusCode())->toBe(404)
|
|
435
|
+
->and($controller->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'missing']), 'trailer-api-1')->getStatusCode())->toBe(404);
|
|
436
|
+
|
|
437
|
+
expect($controller->detach('trailer-api-1')->getStatusCode())->toBe(200)
|
|
438
|
+
->and($controller->detach('trailer-api-1')->getStatusCode())->toBe(200)
|
|
439
|
+
->and($controller->detach('missing')->getStatusCode())->toBe(404);
|
|
440
|
+
$controller->attach(Request::create('/int/v1/trailers/trailer-api-2/attach', 'POST', ['vehicle' => 'vehicle-api-1', 'position' => 1]), 'trailer-api-2');
|
|
441
|
+
expect($controller->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'vehicle-api-1', 'position' => 1]), 'trailer-api-1')->getStatusCode())->toBe(409);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test('internal trailer controller attaches and detaches equipment with ownership guards', function () {
|
|
445
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
446
|
+
fleetOpsSeedTrailerApi($connection);
|
|
447
|
+
$connection->table('equipments')->insert([
|
|
448
|
+
['uuid' => 'equipment-api-1', 'public_id' => 'equipment_api_one', 'company_uuid' => 'company-trailer-api', 'name' => 'Lift Gate'],
|
|
449
|
+
['uuid' => 'equipment-api-2', 'public_id' => 'equipment_api_two', 'company_uuid' => 'company-trailer-api', 'name' => 'Pump'],
|
|
450
|
+
]);
|
|
451
|
+
$controller = new InternalTrailerController();
|
|
452
|
+
expect($controller->attachEquipment(Request::create('/attach', 'POST', ['equipment' => 'equipment_api_one']), 'trailer-api-1')->getStatusCode())->toBe(200)
|
|
453
|
+
->and($connection->table('equipments')->where('uuid', 'equipment-api-1')->value('equipable_uuid'))->toBe('trailer-api-1')
|
|
454
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'equipment_api_two']), 'trailer-api-1')->getStatusCode())->toBe(422)
|
|
455
|
+
->and($controller->attachEquipment(Request::create('/attach', 'POST', ['equipment' => 'equipment_api_one']), 'missing')->getStatusCode())->toBe(404)
|
|
456
|
+
->and($controller->attachEquipment(Request::create('/attach', 'POST', ['equipment' => 'missing']), 'trailer-api-1')->getStatusCode())->toBe(404)
|
|
457
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'equipment_api_one']), 'missing')->getStatusCode())->toBe(404)
|
|
458
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'missing']), 'trailer-api-1')->getStatusCode())->toBe(404)
|
|
459
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'equipment_api_one']), 'trailer-api-1')->getStatusCode())->toBe(200)
|
|
460
|
+
->and($connection->table('equipments')->where('uuid', 'equipment-api-1')->value('equipable_uuid'))->toBeNull();
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
test('internal trailer controller attaches and detaches devices with ownership guards', function () {
|
|
464
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
465
|
+
fleetOpsSeedTrailerApi($connection);
|
|
466
|
+
$connection->table('devices')->insert([
|
|
467
|
+
['uuid' => 'device-api-1', 'public_id' => 'device_api_one', 'company_uuid' => 'company-trailer-api', 'name' => 'Tracker', 'attachable_type' => null, 'attachable_uuid' => null],
|
|
468
|
+
['uuid' => 'device-api-2', 'public_id' => 'device_api_two', 'company_uuid' => 'company-trailer-api', 'name' => 'Other Tracker', 'attachable_type' => null, 'attachable_uuid' => null],
|
|
469
|
+
// Already installed on Trailer Two: attaching it to Trailer One must be refused, not re-homed.
|
|
470
|
+
['uuid' => 'device-api-3', 'public_id' => 'device_api_three', 'company_uuid' => 'company-trailer-api', 'name' => 'Installed Tracker', 'attachable_type' => 'Fleetbase\\FleetOps\\Models\\Trailer', 'attachable_uuid' => 'trailer-api-2'],
|
|
471
|
+
]);
|
|
472
|
+
app()->forgetInstance('db.schema');
|
|
473
|
+
$controller = new InternalTrailerController();
|
|
474
|
+
$conflict = $controller->attachDevice(Request::create('/attach', 'POST', ['device' => 'device_api_three']), 'trailer-api-1');
|
|
475
|
+
expect($conflict->getStatusCode())->toBe(409)
|
|
476
|
+
->and($conflict->getData(true)['errors'][0] ?? $conflict->getData(true)['error'] ?? null)->toBe('Device is already attached to Trailer Two. Detach it before attaching it elsewhere.')
|
|
477
|
+
->and($connection->table('devices')->where('uuid', 'device-api-3')->value('attachable_uuid'))->toBe('trailer-api-2');
|
|
478
|
+
expect($controller->attachDevice(Request::create('/attach', 'POST', ['device' => 'device_api_one']), 'trailer-api-1')->getStatusCode())->toBe(200)
|
|
479
|
+
->and($connection->table('devices')->where('uuid', 'device-api-1')->value('attachable_uuid'))->toBe('trailer-api-1')
|
|
480
|
+
->and($controller->detachDevice(Request::create('/detach', 'POST', ['device' => 'device_api_two']), 'trailer-api-1')->getStatusCode())->toBe(422)
|
|
481
|
+
->and($controller->attachDevice(Request::create('/attach', 'POST', ['device' => 'device_api_one']), 'missing')->getStatusCode())->toBe(404)
|
|
482
|
+
->and($controller->attachDevice(Request::create('/attach', 'POST', ['device' => 'missing']), 'trailer-api-1')->getStatusCode())->toBe(404)
|
|
483
|
+
->and($controller->detachDevice(Request::create('/detach', 'POST', ['device' => 'device_api_one']), 'missing')->getStatusCode())->toBe(404)
|
|
484
|
+
->and($controller->detachDevice(Request::create('/detach', 'POST', ['device' => 'missing']), 'trailer-api-1')->getStatusCode())->toBe(404)
|
|
485
|
+
->and($controller->detachDevice(Request::create('/detach', 'POST', ['device' => 'device_api_one']), 'trailer-api-1')->getStatusCode())->toBe(200)
|
|
486
|
+
->and($connection->table('devices')->where('uuid', 'device-api-1')->value('attachable_uuid'))->toBeNull();
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test('public equipment attachment endpoints support trailers, idempotence, detach and missing resources', function () {
|
|
490
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
491
|
+
fleetOpsSeedTrailerApi($connection);
|
|
492
|
+
$connection->table('equipments')->insert(['uuid' => 'equipment-public-1', 'public_id' => 'equipment_public_one', 'company_uuid' => 'company-trailer-api', 'name' => 'Trailer Pump']);
|
|
493
|
+
$controller = new EquipmentController();
|
|
494
|
+
|
|
495
|
+
expect($controller->attach(Request::create('/v1/equipment/equipment_public_one/attach', 'POST', ['attachable_type' => 'trailer', 'attachable' => 'trailer_api_one']), 'equipment_public_one'))->not->toBeNull()
|
|
496
|
+
->and($connection->table('equipments')->where('uuid', 'equipment-public-1')->value('equipable_uuid'))->toBe('trailer-api-1')
|
|
497
|
+
->and($controller->attach(Request::create('/v1/equipment/equipment_public_one/attach', 'POST', ['attachable_type' => 'trailer', 'attachable' => 'trailer_api_one']), 'equipment_public_one'))->not->toBeNull()
|
|
498
|
+
->and($controller->attach(Request::create('/v1/equipment/missing/attach', 'POST', ['attachable_type' => 'trailer', 'attachable' => 'trailer_api_one']), 'missing')->getStatusCode())->toBe(404)
|
|
499
|
+
->and($controller->detach('equipment_public_one'))->not->toBeNull()
|
|
500
|
+
->and($connection->table('equipments')->where('uuid', 'equipment-public-1')->value('equipable_uuid'))->toBeNull()
|
|
501
|
+
->and($controller->detach('equipment_public_one'))->not->toBeNull()
|
|
502
|
+
->and($controller->detach('missing')->getStatusCode())->toBe(404);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
test('internal trailer spreadsheet endpoints scope exports and count imported files', function () {
|
|
506
|
+
$controller = new FleetOpsInternalTrailerSpreadsheetProbe();
|
|
507
|
+
$exportRequest = FleetOpsTrailerExportRequestFake::create('/int/v1/trailers/export', 'POST', ['format' => 'csv', 'selections' => ['trailer-api-1']]);
|
|
508
|
+
$download = $controller->export($exportRequest);
|
|
509
|
+
expect($download['file'])->toEndWith('.csv')
|
|
510
|
+
->and($controller->downloads[0][0])->toBeInstanceOf(TrailerExport::class);
|
|
511
|
+
|
|
512
|
+
$importRequest = FleetOpsTrailerImportRequestFake::create('/int/v1/trailers/import', 'POST', ['disk' => 'local']);
|
|
513
|
+
$importRequest->resolvedFiles = [(object) ['path' => 'trailers-one.csv'], (object) ['path' => 'trailers-two.csv']];
|
|
514
|
+
$response = $controller->import($importRequest);
|
|
515
|
+
expect($response->getData(true)['imported'])->toBe(4)
|
|
516
|
+
->and($controller->imports)->toBe([['trailers-one.csv', 'local'], ['trailers-two.csv', 'local']]);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
test('public trailer responses expose relation identifiers, expansions and sanitized telematics', function () {
|
|
520
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
521
|
+
fleetOpsSeedTrailerApi($connection);
|
|
522
|
+
$connection->table('vendors')->insert(['uuid' => 'vendor-api-1', 'public_id' => 'vendor_api_one', 'company_uuid' => 'company-trailer-api', 'name' => 'Trailer Vendor']);
|
|
523
|
+
$connection->table('assets')->where('uuid', 'trailer-api-1')->update([
|
|
524
|
+
'vendor_uuid' => 'vendor-api-1',
|
|
525
|
+
'telematics' => json_encode(['last_provider' => 'flespi', 'last_device_uuid' => 'device-uuid', 'last_event_uuid' => 'event-uuid', 'last_event_at' => '2026-09-01T00:00:00Z']),
|
|
526
|
+
]);
|
|
527
|
+
$controller = new FleetOpsTrailerControllerProbe();
|
|
528
|
+
|
|
529
|
+
// No request injected: the controller falls back to the container request.
|
|
530
|
+
app()->instance('request', Request::create('/v1/trailers/trailer_api_one', 'GET'));
|
|
531
|
+
$plain = $controller->find('trailer_api_one')->resolve();
|
|
532
|
+
expect($plain['id'])->toBe('trailer_api_one')
|
|
533
|
+
->and($plain['vendor_id'])->toBe('vendor_api_one')
|
|
534
|
+
->and($plain['category_id'])->toBeNull()
|
|
535
|
+
->and($plain['vehicle_id'])->toBeNull()
|
|
536
|
+
->and($plain['current_vehicle'])->toBeNull()
|
|
537
|
+
->and($plain)->not->toHaveKeys(['uuid', 'company_uuid', 'vendor', 'vendor_uuid', 'equipments'])
|
|
538
|
+
->and((array) $plain['telematics'])->toBe(['last_provider' => 'flespi', 'last_event_at' => '2026-09-01T00:00:00Z'])
|
|
539
|
+
->and($plain['equipment']->resolve())->toBe([])
|
|
540
|
+
->and($plain['devices_count'])->toBe(0);
|
|
541
|
+
|
|
542
|
+
$withRequest = Request::create('/v1/trailers/trailer_api_one', 'GET', ['with' => 'vendor,category,not_a_relation']);
|
|
543
|
+
$expanded = $controller->find('trailer_api_one', $withRequest)->resolve($withRequest);
|
|
544
|
+
expect($expanded['vendor_id'])->toBe('vendor_api_one')
|
|
545
|
+
->and($expanded['vendor'])->not->toBeNull()
|
|
546
|
+
->and($expanded['category'])->toBeNull();
|
|
547
|
+
|
|
548
|
+
$controller->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'TRUCK-1']));
|
|
549
|
+
$attached = $controller->find('trailer_api_one', Request::create('/v1/trailers/trailer_api_one', 'GET'))->resolve();
|
|
550
|
+
expect($attached['vehicle_id'])->toBe('vehicle_api_one')
|
|
551
|
+
->and($attached['current_vehicle'])->toBe(['id' => 'vehicle_api_one', 'name' => 'Truck One', 'plate_number' => null])
|
|
552
|
+
->and($attached['attachment_state'])->toBe('attached');
|
|
553
|
+
$connectionBody = $attached['current_connection']->resolve();
|
|
554
|
+
expect($connectionBody['vehicle_id'])->toBe('vehicle_api_one')
|
|
555
|
+
->and($connectionBody['trailer_id'])->toBe('trailer_api_one')
|
|
556
|
+
->and($connectionBody)->not->toHaveKeys(['uuid', 'connector_uuid', 'connected_uuid']);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
test('public trailer tracking ignores null island observations', function () {
|
|
560
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
561
|
+
fleetOpsSeedTrailerApi($connection);
|
|
562
|
+
app()->instance('request', Request::create('/'));
|
|
563
|
+
$controller = new FleetOpsTrailerControllerProbe();
|
|
564
|
+
|
|
565
|
+
expect($controller->track('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/track', 'POST', ['latitude' => 0, 'longitude' => 0])))->not->toBeNull()
|
|
566
|
+
->and($connection->table('positions')->count())->toBe(0)
|
|
567
|
+
->and($connection->table('assets')->where('uuid', 'trailer-api-1')->value('last_online_at'))->toBeNull();
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
test('public vehicle responses expand currently attached trailers', function () {
|
|
571
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
572
|
+
fleetOpsSeedTrailerApi($connection);
|
|
573
|
+
(new FleetOpsTrailerControllerProbe())->attach('trailer_api_one', Request::create('/v1/trailers/trailer_api_one/attach', 'POST', ['vehicle' => 'vehicle_api_one']));
|
|
574
|
+
|
|
575
|
+
$request = Request::create('/v1/vehicles/vehicle_api_one', 'GET', ['with' => 'trailers,driver']);
|
|
576
|
+
app()->instance('request', $request);
|
|
577
|
+
$mapped = (new FleetOpsVehicleExpansionProbe())->mapExpansions($request);
|
|
578
|
+
expect($mapped)->toBe(['currentTrailers', 'driver']);
|
|
579
|
+
|
|
580
|
+
$request->merge(['with' => $mapped]);
|
|
581
|
+
$vehicle = Vehicle::where('uuid', 'vehicle-api-1')->firstOrFail();
|
|
582
|
+
$resolved = (new VehicleResource($vehicle))->toArray($request);
|
|
583
|
+
expect($resolved['trailers']->resolve()[0]['id'])->toBe('trailer_api_one');
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
test('internal trailer controller refuses to delete an attached trailer and delegates otherwise', function () {
|
|
587
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
588
|
+
fleetOpsSeedTrailerApi($connection);
|
|
589
|
+
$controller = new FleetOpsInternalTrailerDeleteProbe();
|
|
590
|
+
$controller->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'vehicle-api-1']), 'trailer-api-1');
|
|
591
|
+
$request = Request::create('/int/v1/trailers/trailer-api-1', 'DELETE');
|
|
592
|
+
|
|
593
|
+
expect($controller->deleteRecord('trailer-api-1', $request)->getStatusCode())->toBe(409)
|
|
594
|
+
->and($controller->deleted)->toBe([]);
|
|
595
|
+
|
|
596
|
+
$controller->detach('trailer-api-1');
|
|
597
|
+
expect($controller->deleteRecord('trailer-api-1', $request)->getStatusCode())->toBe(200)
|
|
598
|
+
->and($controller->deleteRecord('missing', $request)->getStatusCode())->toBe(200)
|
|
599
|
+
->and($controller->deleted)->toBe(['trailer-api-1', 'missing']);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test('trailer bulk removal skips attached trailers and refuses fully attached selections', function () {
|
|
603
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
604
|
+
fleetOpsSeedTrailerApi($connection);
|
|
605
|
+
(new InternalTrailerController())->attach(Request::create('/int/v1/trailers/trailer-api-1/attach', 'POST', ['vehicle' => 'vehicle-api-1']), 'trailer-api-1');
|
|
606
|
+
|
|
607
|
+
expect(fn () => (new Trailer())->bulkRemove(['trailer-api-1', 'trailer_api_one']))->toThrow(RuntimeException::class)
|
|
608
|
+
->and((new Trailer())->bulkRemove(['trailer-api-1', 'trailer_api_two', 'trailer-other']))->toBe(1)
|
|
609
|
+
->and($connection->table('assets')->where('uuid', 'trailer-api-2')->whereNotNull('deleted_at')->exists())->toBeTrue()
|
|
610
|
+
->and($connection->table('assets')->where('uuid', 'trailer-api-1')->whereNull('deleted_at')->exists())->toBeTrue()
|
|
611
|
+
->and($connection->table('assets')->where('uuid', 'trailer-other')->whereNull('deleted_at')->exists())->toBeTrue();
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
test('internal trailer controller exposes lifecycle statuses and types for console filters', function () {
|
|
615
|
+
fleetOpsTrailerControllerDatabase();
|
|
616
|
+
$controller = new InternalTrailerController();
|
|
617
|
+
|
|
618
|
+
expect($controller->statuses()->getData(true))->toBe(Trailer::STATUSES)
|
|
619
|
+
->and($controller->types()->getData(true))->toBe(Trailer::TYPES);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
test('internal vehicle controller attaches and detaches equipment with ownership guards', function () {
|
|
623
|
+
$connection = fleetOpsTrailerControllerDatabase();
|
|
624
|
+
fleetOpsSeedTrailerApi($connection);
|
|
625
|
+
$connection->table('equipments')->insert([
|
|
626
|
+
['uuid' => 'equipment-vehicle-1', 'public_id' => 'equipment_vehicle_one', 'company_uuid' => 'company-trailer-api', 'name' => 'Lift Gate'],
|
|
627
|
+
['uuid' => 'equipment-vehicle-2', 'public_id' => 'equipment_vehicle_two', 'company_uuid' => 'company-trailer-api', 'name' => 'Pump'],
|
|
628
|
+
]);
|
|
629
|
+
$controller = new InternalVehicleController();
|
|
630
|
+
|
|
631
|
+
expect($controller->attachEquipment(Request::create('/attach', 'POST', ['equipment' => 'equipment_vehicle_one']), 'vehicle-api-1')->getStatusCode())->toBe(200)
|
|
632
|
+
->and($connection->table('equipments')->where('uuid', 'equipment-vehicle-1')->value('equipable_uuid'))->toBe('vehicle-api-1')
|
|
633
|
+
->and($controller->attachEquipment(Request::create('/attach', 'POST', ['equipment' => 'equipment_vehicle_one']), 'missing')->getStatusCode())->toBe(404)
|
|
634
|
+
->and($controller->attachEquipment(Request::create('/attach', 'POST', ['equipment' => 'missing']), 'vehicle-api-1')->getStatusCode())->toBe(404)
|
|
635
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'equipment_vehicle_two']), 'vehicle-api-1')->getStatusCode())->toBe(422)
|
|
636
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'equipment_vehicle_one']), 'missing')->getStatusCode())->toBe(404)
|
|
637
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'missing']), 'vehicle-api-1')->getStatusCode())->toBe(404)
|
|
638
|
+
->and($controller->detachEquipment(Request::create('/detach', 'POST', ['equipment' => 'equipment_vehicle_one']), 'vehicle-api-1')->getStatusCode())->toBe(200)
|
|
639
|
+
->and($connection->table('equipments')->where('uuid', 'equipment-vehicle-1')->value('equipable_uuid'))->toBeNull();
|
|
640
|
+
});
|