Files

79 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2025-09-23 23:56:11 +02:00
<?php
declare(strict_types=1);
use Illuminate\Foundation\Testing\RefreshDatabase;
2025-10-01 22:10:36 +02:00
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
2025-09-23 23:56:11 +02:00
uses(RefreshDatabase::class);
2025-09-24 20:31:32 +02:00
test('firmware check command has correct signature', function (): void {
2025-09-23 23:56:11 +02:00
$command = $this->app->make(App\Console\Commands\FirmwareCheckCommand::class);
expect($command->getName())->toBe('trmnl:firmware:check');
expect($command->getDescription())->toBe('Checks for the latest firmware and downloads it if flag --download is passed.');
});
2025-09-24 20:31:32 +02:00
test('firmware check command runs without errors', function (): void {
2025-10-01 22:10:36 +02:00
// Mock the firmware API response
2026-01-28 12:10:29 +01:00
$baseUrl = config('services.trmnl.base_url');
2025-10-01 22:10:36 +02:00
Http::fake([
2026-01-28 12:10:29 +01:00
$baseUrl.'/api/firmware/latest' => Http::response([
2025-10-01 22:10:36 +02:00
'version' => '1.0.0',
'url' => 'https://example.com/firmware.bin',
], 200),
]);
2025-09-23 23:56:11 +02:00
$this->artisan('trmnl:firmware:check')
->assertExitCode(0);
2025-10-01 22:10:36 +02:00
// Verify that the firmware was created
expect(App\Models\Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue();
2025-09-23 23:56:11 +02:00
});
2025-09-24 20:31:32 +02:00
test('firmware check command runs with download flag', function (): void {
2025-10-01 22:10:36 +02:00
// Mock the firmware API response
2026-01-28 12:10:29 +01:00
$baseUrl = config('services.trmnl.base_url');
2025-10-01 22:10:36 +02:00
Http::fake([
2026-01-28 12:10:29 +01:00
$baseUrl.'/api/firmware/latest' => Http::response([
2025-10-01 22:10:36 +02:00
'version' => '1.0.0',
'url' => 'https://example.com/firmware.bin',
], 200),
'https://example.com/firmware.bin' => Http::response('fake firmware content', 200),
]);
// Mock storage to prevent actual file operations
Storage::fake('public');
2025-09-23 23:56:11 +02:00
$this->artisan('trmnl:firmware:check', ['--download' => true])
->assertExitCode(0);
2025-10-01 22:10:36 +02:00
// Verify that the firmware was created and marked as latest
expect(App\Models\Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue();
// Verify that the firmware was downloaded (storage_location should be set)
$firmware = App\Models\Firmware::where('version_tag', '1.0.0')->first();
expect($firmware->storage_location)->toBe('firmwares/FW1.0.0.bin');
2025-09-23 23:56:11 +02:00
});
2025-09-24 20:31:32 +02:00
test('firmware check command can run successfully', function (): void {
2025-10-01 22:10:36 +02:00
// Mock the firmware API response
2026-01-28 12:10:29 +01:00
$baseUrl = config('services.trmnl.base_url');
2025-10-01 22:10:36 +02:00
Http::fake([
2026-01-28 12:10:29 +01:00
$baseUrl.'/api/firmware/latest' => Http::response([
2025-10-01 22:10:36 +02:00
'version' => '1.0.0',
'url' => 'https://example.com/firmware.bin',
], 200),
]);
2025-09-23 23:56:11 +02:00
$this->artisan('trmnl:firmware:check')
->assertExitCode(0);
2025-10-01 22:10:36 +02:00
// Verify that the firmware was created
expect(App\Models\Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue();
2025-09-23 23:56:11 +02:00
});