chore: run pint

This commit is contained in:
Benjamin Nussbaum 2025-06-03 18:18:25 +02:00
parent 78f1f74594
commit 4102d33336
11 changed files with 37 additions and 37 deletions

View file

@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Jobs\FirmwarePollJob; use App\Jobs\FirmwarePollJob;
use App\Models\Firmware; use App\Models\Firmware;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use function Laravel\Prompts\spin; use function Laravel\Prompts\spin;
use function Laravel\Prompts\table; use function Laravel\Prompts\table;

View file

@ -45,27 +45,25 @@ class FirmwareUpdateCommand extends Command
...Device::all()->mapWithKeys(function ($device) { ...Device::all()->mapWithKeys(function ($device) {
// without _ returns index // without _ returns index
return ["_$device->id" => "$device->name (Current version: $device->last_firmware_version)"]; return ["_$device->id" => "$device->name (Current version: $device->last_firmware_version)"];
})->toArray() })->toArray(),
], ],
scroll: 10 scroll: 10
); );
if (empty($devices)) { if (empty($devices)) {
$this->error('No devices selected. Aborting.'); $this->error('No devices selected. Aborting.');
return; return;
} }
if (in_array('all', $devices)) { if (in_array('all', $devices)) {
$devices = Device::pluck('id')->toArray(); $devices = Device::pluck('id')->toArray();
} else { } else {
$devices = array_map(function($selected) { $devices = array_map(function ($selected) {
return (int) str_replace('_', '', $selected); return (int) str_replace('_', '', $selected);
}, $devices); }, $devices);
} }
foreach ($devices as $deviceId) { foreach ($devices as $deviceId) {
Device::find($deviceId)->update(['update_firmware_id' => $firmwareVersion]); Device::find($deviceId)->update(['update_firmware_id' => $firmwareVersion]);

View file

@ -8,7 +8,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class CleanupDeviceLogsJob implements ShouldQueue class CleanupDeviceLogsJob implements ShouldQueue
{ {

View file

@ -27,8 +27,9 @@ class FirmwarePollJob implements ShouldQueue
try { try {
$response = Http::get('https://usetrmnl.com/api/firmware/latest')->json(); $response = Http::get('https://usetrmnl.com/api/firmware/latest')->json();
if (!is_array($response) || !isset($response['version']) || !isset($response['url'])) { if (! is_array($response) || ! isset($response['version']) || ! isset($response['url'])) {
\Log::error('Invalid firmware response format received'); \Log::error('Invalid firmware response format received');
return; return;
} }

View file

@ -14,7 +14,7 @@ class DeviceLogFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'log_entry' => ["creation_timestamp"=>fake()->dateTimeBetween('-1 month', 'now')->getTimestamp(),"device_status_stamp"=>["wifi_rssi_level"=>-65,"wifi_status"=>"connected","refresh_rate"=>900,"time_since_last_sleep_start"=>901,"current_fw_version"=>"1.5.5","special_function"=>"none","battery_voltage"=>4.052,"wakeup_reason"=>"timer","free_heap_size"=>215128,"max_alloc_size"=>192500],"log_id"=>17,"log_message"=>"Error fetching API display: 7, detail: HTTP Client failed with error: connection refused(-1)","log_codeline"=>586,"log_sourcefile"=>"src\/bl.cpp","additional_info"=>["filename_current"=>"UUID.png","filename_new"=>null,"retry_attempt"=>5]], 'log_entry' => ['creation_timestamp' => fake()->dateTimeBetween('-1 month', 'now')->getTimestamp(), 'device_status_stamp' => ['wifi_rssi_level' => -65, 'wifi_status' => 'connected', 'refresh_rate' => 900, 'time_since_last_sleep_start' => 901, 'current_fw_version' => '1.5.5', 'special_function' => 'none', 'battery_voltage' => 4.052, 'wakeup_reason' => 'timer', 'free_heap_size' => 215128, 'max_alloc_size' => 192500], 'log_id' => 17, 'log_message' => 'Error fetching API display: 7, detail: HTTP Client failed with error: connection refused(-1)', 'log_codeline' => 586, 'log_sourcefile' => "src\/bl.cpp", 'additional_info' => ['filename_current' => 'UUID.png', 'filename_new' => null, 'retry_attempt' => 5]],
'device_timestamp' => fake()->dateTimeBetween('-1 month', 'now'), 'device_timestamp' => fake()->dateTimeBetween('-1 month', 'now'),
'created_at' => Carbon::now(), 'created_at' => Carbon::now(),
'updated_at' => Carbon::now(), 'updated_at' => Carbon::now(),

View file

@ -5,7 +5,8 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::create('device_logs', function (Blueprint $table) { Schema::create('device_logs', function (Blueprint $table) {

View file

@ -5,6 +5,7 @@ namespace Tests\Feature;
use App\Models\Device; use App\Models\Device;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\actingAs; use function Pest\Laravel\actingAs;
uses(RefreshDatabase::class); uses(RefreshDatabase::class);

View file

@ -2,7 +2,6 @@
use App\Jobs\FirmwareDownloadJob; use App\Jobs\FirmwareDownloadJob;
use App\Models\Firmware; use App\Models\Firmware;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;

View file

@ -13,11 +13,11 @@ test('it creates new firmware record when polling', function () {
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => Http::response([ 'usetrmnl.com/api/firmware/latest' => Http::response([
'version' => '1.0.0', 'version' => '1.0.0',
'url' => 'https://example.com/firmware.bin' 'url' => 'https://example.com/firmware.bin',
], 200) ], 200),
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
expect(Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue() expect(Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue()
->and(Firmware::where('version_tag', '1.0.0')->first()) ->and(Firmware::where('version_tag', '1.0.0')->first())
@ -29,17 +29,17 @@ test('it updates existing firmware record when polling', function () {
$existingFirmware = Firmware::factory()->create([ $existingFirmware = Firmware::factory()->create([
'version_tag' => '1.0.0', 'version_tag' => '1.0.0',
'url' => 'https://old-url.com/firmware.bin', 'url' => 'https://old-url.com/firmware.bin',
'latest' => true 'latest' => true,
]); ]);
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => Http::response([ 'usetrmnl.com/api/firmware/latest' => Http::response([
'version' => '1.0.0', 'version' => '1.0.0',
'url' => 'https://new-url.com/firmware.bin' 'url' => 'https://new-url.com/firmware.bin',
], 200) ], 200),
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
expect($existingFirmware->fresh()) expect($existingFirmware->fresh())
->url->toBe('https://new-url.com/firmware.bin') ->url->toBe('https://new-url.com/firmware.bin')
@ -49,17 +49,17 @@ test('it updates existing firmware record when polling', function () {
test('it marks previous firmware as not latest when new version is found', function () { test('it marks previous firmware as not latest when new version is found', function () {
$oldFirmware = Firmware::factory()->create([ $oldFirmware = Firmware::factory()->create([
'version_tag' => '1.0.0', 'version_tag' => '1.0.0',
'latest' => true 'latest' => true,
]); ]);
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => Http::response([ 'usetrmnl.com/api/firmware/latest' => Http::response([
'version' => '1.1.0', 'version' => '1.1.0',
'url' => 'https://example.com/firmware.bin' 'url' => 'https://example.com/firmware.bin',
], 200) ], 200),
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
expect($oldFirmware->fresh()->latest)->toBeFalse() expect($oldFirmware->fresh()->latest)->toBeFalse()
->and(Firmware::where('version_tag', '1.1.0')->first()->latest)->toBeTrue(); ->and(Firmware::where('version_tag', '1.1.0')->first()->latest)->toBeTrue();
@ -69,10 +69,10 @@ test('it handles connection exception gracefully', function () {
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => function () { 'usetrmnl.com/api/firmware/latest' => function () {
throw new ConnectionException('Connection failed'); throw new ConnectionException('Connection failed');
} },
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
// Verify no firmware records were created // Verify no firmware records were created
expect(Firmware::count())->toBe(0); expect(Firmware::count())->toBe(0);
@ -80,10 +80,10 @@ test('it handles connection exception gracefully', function () {
test('it handles invalid response gracefully', function () { test('it handles invalid response gracefully', function () {
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => Http::response(null, 200) 'usetrmnl.com/api/firmware/latest' => Http::response(null, 200),
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
// Verify no firmware records were created // Verify no firmware records were created
expect(Firmware::count())->toBe(0); expect(Firmware::count())->toBe(0);
@ -92,11 +92,11 @@ test('it handles invalid response gracefully', function () {
test('it handles missing version in response gracefully', function () { test('it handles missing version in response gracefully', function () {
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => Http::response([ 'usetrmnl.com/api/firmware/latest' => Http::response([
'url' => 'https://example.com/firmware.bin' 'url' => 'https://example.com/firmware.bin',
], 200) ], 200),
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
// Verify no firmware records were created // Verify no firmware records were created
expect(Firmware::count())->toBe(0); expect(Firmware::count())->toBe(0);
@ -105,11 +105,11 @@ test('it handles missing version in response gracefully', function () {
test('it handles missing url in response gracefully', function () { test('it handles missing url in response gracefully', function () {
Http::fake([ Http::fake([
'usetrmnl.com/api/firmware/latest' => Http::response([ 'usetrmnl.com/api/firmware/latest' => Http::response([
'version' => '1.0.0' 'version' => '1.0.0',
], 200) ], 200),
]); ]);
(new FirmwarePollJob())->handle(); (new FirmwarePollJob)->handle();
// Verify no firmware records were created // Verify no firmware records were created
expect(Firmware::count())->toBe(0); expect(Firmware::count())->toBe(0);

View file

@ -20,8 +20,8 @@ test('device log casts log_entry to array', function () {
'log_entry' => [ 'log_entry' => [
'message' => 'test message', 'message' => 'test message',
'level' => 'info', 'level' => 'info',
'timestamp' => time() 'timestamp' => time(),
] ],
]); ]);
expect($log->log_entry)->toBeArray() expect($log->log_entry)->toBeArray()
@ -33,7 +33,7 @@ test('device log casts device_timestamp to datetime', function () {
Device::factory()->create(); Device::factory()->create();
$timestamp = now(); $timestamp = now();
$log = DeviceLog::factory()->create([ $log = DeviceLog::factory()->create([
'device_timestamp' => $timestamp 'device_timestamp' => $timestamp,
]); ]);
expect($log->device_timestamp)->toBeInstanceOf(\Carbon\Carbon::class) expect($log->device_timestamp)->toBeInstanceOf(\Carbon\Carbon::class)
@ -56,8 +56,8 @@ test('device log can be created with minimal required fields', function () {
'device_id' => $device->id, 'device_id' => $device->id,
'device_timestamp' => now(), 'device_timestamp' => now(),
'log_entry' => [ 'log_entry' => [
'message' => 'test message' 'message' => 'test message',
] ],
]); ]);
expect($log->exists)->toBeTrue() expect($log->exists)->toBeTrue()