mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
chore: run pint
This commit is contained in:
parent
78f1f74594
commit
4102d33336
11 changed files with 37 additions and 37 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
|||
use App\Jobs\FirmwarePollJob;
|
||||
use App\Models\Firmware;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use function Laravel\Prompts\spin;
|
||||
use function Laravel\Prompts\table;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,27 +45,25 @@ class FirmwareUpdateCommand extends Command
|
|||
...Device::all()->mapWithKeys(function ($device) {
|
||||
// without _ returns index
|
||||
return ["_$device->id" => "$device->name (Current version: $device->last_firmware_version)"];
|
||||
})->toArray()
|
||||
})->toArray(),
|
||||
],
|
||||
scroll: 10
|
||||
);
|
||||
|
||||
|
||||
|
||||
if (empty($devices)) {
|
||||
$this->error('No devices selected. Aborting.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array('all', $devices)) {
|
||||
$devices = Device::pluck('id')->toArray();
|
||||
} else {
|
||||
$devices = array_map(function($selected) {
|
||||
$devices = array_map(function ($selected) {
|
||||
return (int) str_replace('_', '', $selected);
|
||||
}, $devices);
|
||||
}
|
||||
|
||||
|
||||
foreach ($devices as $deviceId) {
|
||||
Device::find($deviceId)->update(['update_firmware_id' => $firmwareVersion]);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CleanupDeviceLogsJob implements ShouldQueue
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ class FirmwarePollJob implements ShouldQueue
|
|||
try {
|
||||
$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');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class DeviceLogFactory extends Factory
|
|||
public function definition(): array
|
||||
{
|
||||
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'),
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now(),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ use Illuminate\Database\Migrations\Migration;
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('device_logs', function (Blueprint $table) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Tests\Feature;
|
|||
use App\Models\Device;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
use function Pest\Laravel\actingAs;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use App\Jobs\FirmwareDownloadJob;
|
||||
use App\Models\Firmware;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ test('it creates new firmware record when polling', function () {
|
|||
Http::fake([
|
||||
'usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'version' => '1.0.0',
|
||||
'url' => 'https://example.com/firmware.bin'
|
||||
], 200)
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
(new FirmwarePollJob())->handle();
|
||||
(new FirmwarePollJob)->handle();
|
||||
|
||||
expect(Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue()
|
||||
->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([
|
||||
'version_tag' => '1.0.0',
|
||||
'url' => 'https://old-url.com/firmware.bin',
|
||||
'latest' => true
|
||||
'latest' => true,
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'version' => '1.0.0',
|
||||
'url' => 'https://new-url.com/firmware.bin'
|
||||
], 200)
|
||||
'url' => 'https://new-url.com/firmware.bin',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
(new FirmwarePollJob())->handle();
|
||||
(new FirmwarePollJob)->handle();
|
||||
|
||||
expect($existingFirmware->fresh())
|
||||
->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 () {
|
||||
$oldFirmware = Firmware::factory()->create([
|
||||
'version_tag' => '1.0.0',
|
||||
'latest' => true
|
||||
'latest' => true,
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'version' => '1.1.0',
|
||||
'url' => 'https://example.com/firmware.bin'
|
||||
], 200)
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
(new FirmwarePollJob())->handle();
|
||||
(new FirmwarePollJob)->handle();
|
||||
|
||||
expect($oldFirmware->fresh()->latest)->toBeFalse()
|
||||
->and(Firmware::where('version_tag', '1.1.0')->first()->latest)->toBeTrue();
|
||||
|
|
@ -69,10 +69,10 @@ test('it handles connection exception gracefully', function () {
|
|||
Http::fake([
|
||||
'usetrmnl.com/api/firmware/latest' => function () {
|
||||
throw new ConnectionException('Connection failed');
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
(new FirmwarePollJob())->handle();
|
||||
(new FirmwarePollJob)->handle();
|
||||
|
||||
// Verify no firmware records were created
|
||||
expect(Firmware::count())->toBe(0);
|
||||
|
|
@ -80,10 +80,10 @@ test('it handles connection exception gracefully', function () {
|
|||
|
||||
test('it handles invalid response gracefully', function () {
|
||||
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
|
||||
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 () {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'url' => 'https://example.com/firmware.bin'
|
||||
], 200)
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
(new FirmwarePollJob())->handle();
|
||||
(new FirmwarePollJob)->handle();
|
||||
|
||||
// Verify no firmware records were created
|
||||
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 () {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'version' => '1.0.0'
|
||||
], 200)
|
||||
'version' => '1.0.0',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
(new FirmwarePollJob())->handle();
|
||||
(new FirmwarePollJob)->handle();
|
||||
|
||||
// Verify no firmware records were created
|
||||
expect(Firmware::count())->toBe(0);
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ test('device log casts log_entry to array', function () {
|
|||
'log_entry' => [
|
||||
'message' => 'test message',
|
||||
'level' => 'info',
|
||||
'timestamp' => time()
|
||||
]
|
||||
'timestamp' => time(),
|
||||
],
|
||||
]);
|
||||
|
||||
expect($log->log_entry)->toBeArray()
|
||||
|
|
@ -33,7 +33,7 @@ test('device log casts device_timestamp to datetime', function () {
|
|||
Device::factory()->create();
|
||||
$timestamp = now();
|
||||
$log = DeviceLog::factory()->create([
|
||||
'device_timestamp' => $timestamp
|
||||
'device_timestamp' => $timestamp,
|
||||
]);
|
||||
|
||||
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_timestamp' => now(),
|
||||
'log_entry' => [
|
||||
'message' => 'test message'
|
||||
]
|
||||
'message' => 'test message',
|
||||
],
|
||||
]);
|
||||
|
||||
expect($log->exists)->toBeTrue()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue