mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
chore: stricter pint rules
This commit is contained in:
parent
16b2e8436e
commit
e535496a1e
30 changed files with 134 additions and 83 deletions
|
|
@ -128,8 +128,8 @@ class MashupCreateCommand extends Command
|
|||
required: true,
|
||||
default: 'Mashup',
|
||||
validate: fn (string $value) => match (true) {
|
||||
strlen($value) < 1 => 'The name must be at least 2 characters.',
|
||||
strlen($value) > 50 => 'The name must not exceed 50 characters.',
|
||||
mb_strlen($value) < 1 => 'The name must be at least 2 characters.',
|
||||
mb_strlen($value) > 50 => 'The name must not exceed 50 characters.',
|
||||
default => null,
|
||||
}
|
||||
);
|
||||
|
|
@ -149,7 +149,7 @@ class MashupCreateCommand extends Command
|
|||
$selectedPlugins = collect();
|
||||
$availablePlugins = $plugins->mapWithKeys(fn ($plugin) => [$plugin->id => $plugin->name])->toArray();
|
||||
|
||||
for ($i = 0; $i < $requiredCount; $i++) {
|
||||
for ($i = 0; $i < $requiredCount; ++$i) {
|
||||
$position = match ($i) {
|
||||
0 => 'first',
|
||||
1 => 'second',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
|||
|
||||
use App\Jobs\GenerateScreenJob;
|
||||
use Illuminate\Console\Command;
|
||||
use Throwable;
|
||||
|
||||
class ScreenGeneratorCommand extends Command
|
||||
{
|
||||
|
|
@ -31,7 +32,7 @@ class ScreenGeneratorCommand extends Command
|
|||
|
||||
try {
|
||||
$markup = view($view)->render();
|
||||
} catch (\Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
$this->error('Failed to render view: '.$e->getMessage());
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Device;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -67,7 +68,7 @@ class FetchProxyCloudResponses implements ShouldQueue
|
|||
$device->update([
|
||||
'current_screen_image' => $filename,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error("Failed to download and save image for device: {$device->mac_address}", [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
|
@ -95,7 +96,7 @@ class FetchProxyCloudResponses implements ShouldQueue
|
|||
]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error("Failed to fetch proxy cloud response for device: {$device->mac_address}", [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Firmware;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -40,7 +41,7 @@ class FirmwareDownloadJob implements ShouldQueue
|
|||
]);
|
||||
} catch (ConnectionException $e) {
|
||||
Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error('An unexpected error occurred: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Firmware;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -10,6 +11,7 @@ use Illuminate\Http\Client\ConnectionException;
|
|||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Log;
|
||||
|
||||
class FirmwarePollJob implements ShouldQueue
|
||||
{
|
||||
|
|
@ -28,7 +30,7 @@ class FirmwarePollJob implements ShouldQueue
|
|||
$response = Http::get('https://usetrmnl.com/api/firmware/latest')->json();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -48,9 +50,9 @@ class FirmwarePollJob implements ShouldQueue
|
|||
}
|
||||
|
||||
} catch (ConnectionException $e) {
|
||||
\Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Unexpected error in firmware polling: '.$e->getMessage());
|
||||
Log::error('Firmware download failed: '.$e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Log::error('Unexpected error in firmware polling: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ class Device extends Model
|
|||
// Ensure the voltage is within range
|
||||
if ($volts <= $min_volt) {
|
||||
return 0;
|
||||
} elseif ($volts >= $max_volt) {
|
||||
}
|
||||
if ($volts >= $max_volt) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +61,8 @@ class Device extends Model
|
|||
// Ensure the percentage is within range
|
||||
if ($percent <= 0) {
|
||||
return $min_volt;
|
||||
} elseif ($percent >= 100) {
|
||||
}
|
||||
if ($percent >= 100) {
|
||||
return $max_volt;
|
||||
}
|
||||
|
||||
|
|
@ -75,13 +77,16 @@ class Device extends Model
|
|||
$rssi = $this->last_rssi_level;
|
||||
if ($rssi >= 0) {
|
||||
return 0; // No signal (0 bars)
|
||||
} elseif ($rssi <= -80) {
|
||||
return 1; // Weak signal (1 bar)
|
||||
} elseif ($rssi <= -60) {
|
||||
return 2; // Moderate signal (2 bars)
|
||||
} else {
|
||||
return 3; // Strong signal (3 bars)
|
||||
}
|
||||
if ($rssi <= -80) {
|
||||
return 1; // Weak signal (1 bar)
|
||||
}
|
||||
if ($rssi <= -60) {
|
||||
return 2; // Moderate signal (2 bars)
|
||||
}
|
||||
|
||||
return 3; // Strong signal (3 bars)
|
||||
|
||||
}
|
||||
|
||||
public function getUpdateFirmwareAttribute(): bool
|
||||
|
|
@ -161,7 +166,7 @@ class Device extends Model
|
|||
|
||||
public function mirrorDevice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Device::class, 'mirror_device_id');
|
||||
return $this->belongsTo(self::class, 'mirror_device_id');
|
||||
}
|
||||
|
||||
public function updateFirmware(): BelongsTo
|
||||
|
|
|
|||
|
|
@ -90,12 +90,13 @@ class Plugin extends Model
|
|||
'data' => $this->data_payload,
|
||||
])->render(),
|
||||
])->render();
|
||||
} else {
|
||||
}
|
||||
|
||||
return view($this->render_markup_view, [
|
||||
'size' => $size,
|
||||
'data' => $this->data_payload,
|
||||
])->render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return '<p>No render markup yet defined for this plugin.</p>';
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use URL;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -20,7 +21,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
public function boot(): void
|
||||
{
|
||||
if (app()->isProduction() && config('app.force_https')) {
|
||||
\URL::forceScheme('https');
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,14 @@ namespace App\Services;
|
|||
use App\Enums\ImageFormat;
|
||||
use App\Models\Device;
|
||||
use App\Models\Plugin;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Imagick;
|
||||
use ImagickException;
|
||||
use ImagickPixel;
|
||||
use Log;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use RuntimeException;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
use Wnx\SidecarBrowsershot\BrowsershotLambda;
|
||||
|
||||
|
|
@ -26,9 +31,9 @@ class ImageGenerationService
|
|||
BrowsershotLambda::html($markup)
|
||||
->windowSize(800, 480)
|
||||
->save($pngPath);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new \RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
|
@ -36,25 +41,25 @@ class ImageGenerationService
|
|||
->setOption('args', config('app.puppeteer_docker') ? ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'] : [])
|
||||
->windowSize(800, 480)
|
||||
->save($pngPath);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new \RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Failed to generate PNG: '.$e->getMessage());
|
||||
throw new RuntimeException('Failed to generate PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
switch ($device->image_format) {
|
||||
case ImageFormat::BMP3_1BIT_SRGB->value:
|
||||
try {
|
||||
ImageGenerationService::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
self::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
break;
|
||||
case ImageFormat::PNG_8BIT_GRAYSCALE->value:
|
||||
case ImageFormat::PNG_8BIT_256C->value:
|
||||
try {
|
||||
ImageGenerationService::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate, quantize: $device->image_format === ImageFormat::PNG_8BIT_GRAYSCALE);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
self::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate, quantize: $device->image_format === ImageFormat::PNG_8BIT_GRAYSCALE);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
break;
|
||||
case ImageFormat::AUTO->value:
|
||||
|
|
@ -62,33 +67,33 @@ class ImageGenerationService
|
|||
if (isset($device->last_firmware_version)
|
||||
&& version_compare($device->last_firmware_version, '1.5.2', '<')) {
|
||||
try {
|
||||
ImageGenerationService::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
self::convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to BMP: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ImageGenerationService::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate);
|
||||
} catch (\ImagickException $e) {
|
||||
throw new \RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
self::convertToPngImageMagick($pngPath, $device->width, $device->height, $device->rotate);
|
||||
} catch (ImagickException $e) {
|
||||
throw new RuntimeException('Failed to convert image to PNG: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$device->update(['current_screen_image' => $uuid]);
|
||||
\Log::info("Device $device->id: updated with new image: $uuid");
|
||||
Log::info("Device $device->id: updated with new image: $uuid");
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ImagickException
|
||||
* @throws ImagickException
|
||||
*/
|
||||
private static function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
|
||||
{
|
||||
$imagick = new \Imagick($pngPath);
|
||||
$imagick->setImageType(\Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, \Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick = new Imagick($pngPath);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->setImageDepth(1);
|
||||
$imagick->stripImage();
|
||||
$imagick->setFormat('BMP3');
|
||||
|
|
@ -97,20 +102,20 @@ class ImageGenerationService
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \ImagickException
|
||||
* @throws ImagickException
|
||||
*/
|
||||
private static function convertToPngImageMagick(string $pngPath, ?int $width, ?int $height, ?int $rotate, $quantize = true): void
|
||||
{
|
||||
$imagick = new \Imagick($pngPath);
|
||||
$imagick = new Imagick($pngPath);
|
||||
if ($width !== 800 || $height !== 480) {
|
||||
$imagick->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true);
|
||||
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
|
||||
}
|
||||
if ($rotate !== null && $rotate !== 0) {
|
||||
$imagick->rotateImage(new ImagickPixel('black'), $rotate);
|
||||
}
|
||||
$imagick->setImageType(\Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
if ($quantize) {
|
||||
$imagick->quantizeImage(2, \Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
}
|
||||
$imagick->setImageDepth(8);
|
||||
$imagick->stripImage();
|
||||
|
|
@ -152,7 +157,7 @@ class ImageGenerationService
|
|||
) {
|
||||
// TODO cache image per device
|
||||
$plugin->update(['current_image' => null]);
|
||||
\Log::debug('Skip cache as devices with other dimensions exist');
|
||||
Log::debug('Skip cache as devices with other dimensions exist');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ return [
|
|||
* All of your function classes that you'd like to deploy go here.
|
||||
*/
|
||||
'functions' => [
|
||||
\Wnx\SidecarBrowsershot\Functions\BrowsershotFunction::class,
|
||||
Wnx\SidecarBrowsershot\Functions\BrowsershotFunction::class,
|
||||
],
|
||||
];
|
||||
|
|
|
|||
34
pint.json
Normal file
34
pint.json
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"preset": "laravel",
|
||||
"rules": {
|
||||
"array_push": true,
|
||||
"backtick_to_shell_exec": true,
|
||||
"date_time_immutable": true,
|
||||
"lowercase_keywords": true,
|
||||
"lowercase_static_reference": true,
|
||||
"final_internal_class": true,
|
||||
"final_public_method_for_abstract_class": true,
|
||||
"fully_qualified_strict_types": true,
|
||||
"global_namespace_import": {
|
||||
"import_classes": true,
|
||||
"import_constants": true,
|
||||
"import_functions": true
|
||||
},
|
||||
"mb_str_functions": true,
|
||||
"modernize_types_casting": true,
|
||||
"new_with_parentheses": false,
|
||||
"no_superfluous_elseif": true,
|
||||
"no_useless_else": true,
|
||||
"no_multiple_statements_per_line": true,
|
||||
"ordered_interfaces": true,
|
||||
"ordered_traits": true,
|
||||
"protected_to_private": true,
|
||||
"self_accessor": true,
|
||||
"self_static_accessor": true,
|
||||
"strict_comparison": true,
|
||||
"visibility_required": true,
|
||||
"increment_style": {
|
||||
"style": "pre"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ Route::get('/display', function (Request $request) {
|
|||
ImageGenerationService::resetIfNotCacheable($plugin);
|
||||
|
||||
// Check and update stale data if needed
|
||||
if ($plugin->isDataStale() || $plugin->current_image == null) {
|
||||
if ($plugin->isDataStale() || $plugin->current_image === null) {
|
||||
$plugin->updateDataPayload();
|
||||
$markup = $plugin->render();
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ Route::get('/display', function (Request $request) {
|
|||
|
||||
$plugin->refresh();
|
||||
|
||||
if ($plugin->current_image != null) {
|
||||
if ($plugin->current_image !== null) {
|
||||
$playlistItem->update(['last_displayed_at' => now()]);
|
||||
$device->update(['current_screen_image' => $plugin->current_image]);
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ Route::get('/display', function (Request $request) {
|
|||
foreach ($plugins as $plugin) {
|
||||
// Reset cache if Devices with different dimensions exist
|
||||
ImageGenerationService::resetIfNotCacheable($plugin);
|
||||
if ($plugin->isDataStale() || $plugin->current_image == null) {
|
||||
if ($plugin->isDataStale() || $plugin->current_image === null) {
|
||||
$plugin->updateDataPayload();
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ Route::get('/display', function (Request $request) {
|
|||
|
||||
$device->refresh();
|
||||
|
||||
if ($device->current_screen_image != null) {
|
||||
if ($device->current_screen_image !== null) {
|
||||
$playlistItem->update(['last_displayed_at' => now()]);
|
||||
}
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ Route::post('/log', function (Request $request) {
|
|||
|
||||
$logs = $request->json('log.logs_array', []);
|
||||
foreach ($logs as $log) {
|
||||
\Log::info('Device Log', $log);
|
||||
Log::info('Device Log', $log);
|
||||
DeviceLog::create([
|
||||
'device_id' => $device->id,
|
||||
'device_timestamp' => $log['creation_timestamp'] ?? now(),
|
||||
|
|
@ -342,7 +342,7 @@ Route::get('/current_screen', function (Request $request) {
|
|||
});
|
||||
|
||||
Route::post('custom_plugins/{plugin_uuid}', function (string $plugin_uuid) {
|
||||
$plugin = \App\Models\Plugin::where('uuid', $plugin_uuid)->firstOrFail();
|
||||
$plugin = Plugin::where('uuid', $plugin_uuid)->firstOrFail();
|
||||
|
||||
// Check if plugin uses webhook strategy
|
||||
if ($plugin->data_strategy !== 'webhook') {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Schedule;
|
|||
|
||||
Schedule::job(FetchProxyCloudResponses::class, [])->cron(
|
||||
config('services.trmnl.proxy_refresh_cron') ? config('services.trmnl.proxy_refresh_cron') :
|
||||
sprintf('*/%s * * * *', intval(config('services.trmnl.proxy_refresh_minutes', 15)))
|
||||
sprintf('*/%s * * * *', (int) (config('services.trmnl.proxy_refresh_minutes', 15)))
|
||||
);
|
||||
|
||||
Schedule::job(FirmwarePollJob::class)->daily();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use App\Models\User;
|
|||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Storage::fake('public');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use App\Models\Device;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Storage::fake('public');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use App\Models\User;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('login screen can be rendered', function () {
|
||||
$response = $this->get('/login');
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use Illuminate\Auth\Events\Verified;
|
|||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('email verification screen can be rendered', function () {
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use App\Models\User;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('confirm password screen can be rendered', function () {
|
||||
$user = User::factory()->create();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use Illuminate\Auth\Notifications\ResetPassword;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('reset password link screen can be rendered', function () {
|
||||
$response = $this->get('/forgot-password');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('registration screen can be rendered', function () {
|
||||
$response = $this->get('/register');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use App\Models\User;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('guests are redirected to the login page', function () {
|
||||
$response = $this->get('/dashboard');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use App\Models\Device;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('device can be created with basic attributes', function () {
|
||||
$device = Device::factory()->create([
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use App\Models\Device;
|
|||
use App\Models\User;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('device management page can be rendered', function () {
|
||||
$user = User::factory()->create();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use App\Models\Device;
|
|||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Storage::fake('public');
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use App\Jobs\GenerateScreenJob;
|
|||
use App\Models\Device;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Storage::fake('public');
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ test('it keeps only the 50 most recent logs per device', function () {
|
|||
$device2 = Device::factory()->create();
|
||||
|
||||
// Create 60 logs for each device with different timestamps
|
||||
for ($i = 0; $i < 60; $i++) {
|
||||
for ($i = 0; $i < 60; ++$i) {
|
||||
DeviceLog::factory()->create([
|
||||
'device_id' => $device1->id,
|
||||
'device_timestamp' => now()->subMinutes($i),
|
||||
|
|
@ -37,7 +37,7 @@ test('it keeps only the 50 most recent logs per device', function () {
|
|||
$device2Logs = $device2->logs()->orderByDesc('device_timestamp')->get();
|
||||
|
||||
// Check that the timestamps are in descending order
|
||||
for ($i = 0; $i < 49; $i++) {
|
||||
for ($i = 0; $i < 49; ++$i) {
|
||||
expect($device1Logs[$i]->device_timestamp->gt($device1Logs[$i + 1]->device_timestamp))->toBeTrue()
|
||||
->and($device2Logs[$i]->device_timestamp->gt($device2Logs[$i + 1]->device_timestamp))->toBeTrue();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use App\Models\User;
|
|||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('password can be updated', function () {
|
||||
$user = User::factory()->create([
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use App\Models\User;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('profile page is displayed', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ test('device log casts device_timestamp to datetime', function () {
|
|||
'device_timestamp' => $timestamp,
|
||||
]);
|
||||
|
||||
expect($log->device_timestamp)->toBeInstanceOf(\Carbon\Carbon::class)
|
||||
expect($log->device_timestamp)->toBeInstanceOf(Carbon\Carbon::class)
|
||||
->and($log->device_timestamp->timestamp)->toBe($timestamp->timestamp);
|
||||
});
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ test('device log factory creates valid data', function () {
|
|||
$log = DeviceLog::factory()->create();
|
||||
|
||||
expect($log->device_id)->toBeInt()
|
||||
->and($log->device_timestamp)->toBeInstanceOf(\Carbon\Carbon::class)
|
||||
->and($log->device_timestamp)->toBeInstanceOf(Carbon\Carbon::class)
|
||||
->and($log->log_entry)->toBeArray()
|
||||
->and($log->log_entry)->toHaveKeys(['creation_timestamp', 'device_status_stamp', 'log_id', 'log_message', 'log_codeline', 'log_sourcefile', 'additional_info']);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use App\Models\Plugin;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('plugin has required attributes', function () {
|
||||
$plugin = Plugin::factory()->create([
|
||||
|
|
@ -26,7 +26,7 @@ test('plugin automatically generates uuid on creation', function () {
|
|||
});
|
||||
|
||||
test('plugin can have custom uuid', function () {
|
||||
$uuid = \Illuminate\Support\Str::uuid();
|
||||
$uuid = Illuminate\Support\Str::uuid();
|
||||
$plugin = Plugin::factory()->create(['uuid' => $uuid]);
|
||||
|
||||
expect($plugin->uuid)->toBe($uuid);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue