test: mock firmware endpoint

This commit is contained in:
Benjamin Nussbaum 2025-10-01 22:10:36 +02:00
parent 93dacb0baf
commit 50318b8b9d

View file

@ -3,6 +3,8 @@
declare(strict_types=1);
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
uses(RefreshDatabase::class);
@ -14,16 +16,57 @@ test('firmware check command has correct signature', function (): void {
});
test('firmware check command runs without errors', function (): void {
// Mock the firmware API response
Http::fake([
'https://usetrmnl.com/api/firmware/latest' => Http::response([
'version' => '1.0.0',
'url' => 'https://example.com/firmware.bin',
], 200),
]);
$this->artisan('trmnl:firmware:check')
->assertExitCode(0);
// Verify that the firmware was created
expect(App\Models\Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue();
});
test('firmware check command runs with download flag', function (): void {
// Mock the firmware API response
Http::fake([
'https://usetrmnl.com/api/firmware/latest' => Http::response([
'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');
$this->artisan('trmnl:firmware:check', ['--download' => true])
->assertExitCode(0);
// 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');
});
test('firmware check command can run successfully', function (): void {
// Mock the firmware API response
Http::fake([
'https://usetrmnl.com/api/firmware/latest' => Http::response([
'version' => '1.0.0',
'url' => 'https://example.com/firmware.bin',
], 200),
]);
$this->artisan('trmnl:firmware:check')
->assertExitCode(0);
// Verify that the firmware was created
expect(App\Models\Firmware::where('version_tag', '1.0.0')->exists())->toBeTrue();
});