mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 07:27:47 +00:00
This commit is contained in:
parent
c67a182cf2
commit
b4b6286172
89 changed files with 672 additions and 666 deletions
|
|
@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
|||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('it keeps only the 50 most recent logs per device', function () {
|
||||
test('it keeps only the 50 most recent logs per device', function (): void {
|
||||
// Create two devices
|
||||
$device1 = Device::factory()->create();
|
||||
$device2 = Device::factory()->create();
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ beforeEach(function (): void {
|
|||
DeviceModel::truncate();
|
||||
});
|
||||
|
||||
test('fetch device models job can be dispatched', function () {
|
||||
test('fetch device models job can be dispatched', function (): void {
|
||||
$job = new FetchDeviceModelsJob();
|
||||
expect($job)->toBeInstanceOf(FetchDeviceModelsJob::class);
|
||||
});
|
||||
|
||||
test('fetch device models job handles successful api response', function () {
|
||||
test('fetch device models job handles successful api response', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => [
|
||||
|
|
@ -65,7 +65,7 @@ test('fetch device models job handles successful api response', function () {
|
|||
expect($deviceModel->source)->toBe('api');
|
||||
});
|
||||
|
||||
test('fetch device models job handles multiple device models', function () {
|
||||
test('fetch device models job handles multiple device models', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => [
|
||||
|
|
@ -114,7 +114,7 @@ test('fetch device models job handles multiple device models', function () {
|
|||
expect(DeviceModel::where('name', 'model-2')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
test('fetch device models job handles empty data array', function () {
|
||||
test('fetch device models job handles empty data array', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => [],
|
||||
|
|
@ -131,7 +131,7 @@ test('fetch device models job handles empty data array', function () {
|
|||
expect(DeviceModel::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('fetch device models job handles missing data field', function () {
|
||||
test('fetch device models job handles missing data field', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'message' => 'No data available',
|
||||
|
|
@ -148,7 +148,7 @@ test('fetch device models job handles missing data field', function () {
|
|||
expect(DeviceModel::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('fetch device models job handles non-array data', function () {
|
||||
test('fetch device models job handles non-array data', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => 'invalid-data',
|
||||
|
|
@ -165,7 +165,7 @@ test('fetch device models job handles non-array data', function () {
|
|||
expect(DeviceModel::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('fetch device models job handles api failure', function () {
|
||||
test('fetch device models job handles api failure', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'error' => 'Internal Server Error',
|
||||
|
|
@ -185,9 +185,9 @@ test('fetch device models job handles api failure', function () {
|
|||
expect(DeviceModel::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('fetch device models job handles network exception', function () {
|
||||
test('fetch device models job handles network exception', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => function () {
|
||||
'usetrmnl.com/api/models' => function (): void {
|
||||
throw new Exception('Network connection failed');
|
||||
},
|
||||
]);
|
||||
|
|
@ -202,7 +202,7 @@ test('fetch device models job handles network exception', function () {
|
|||
expect(DeviceModel::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('fetch device models job handles device model with missing name', function () {
|
||||
test('fetch device models job handles device model with missing name', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => [
|
||||
|
|
@ -228,7 +228,7 @@ test('fetch device models job handles device model with missing name', function
|
|||
expect(DeviceModel::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('fetch device models job handles device model with partial data', function () {
|
||||
test('fetch device models job handles device model with partial data', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => [
|
||||
|
|
@ -263,7 +263,7 @@ test('fetch device models job handles device model with partial data', function
|
|||
expect($deviceModel->source)->toBe('api');
|
||||
});
|
||||
|
||||
test('fetch device models job updates existing device model', function () {
|
||||
test('fetch device models job updates existing device model', function (): void {
|
||||
// Create an existing device model
|
||||
$existingModel = DeviceModel::factory()->create([
|
||||
'name' => 'existing-model',
|
||||
|
|
@ -309,7 +309,7 @@ test('fetch device models job updates existing device model', function () {
|
|||
expect($existingModel->source)->toBe('api');
|
||||
});
|
||||
|
||||
test('fetch device models job handles processing exception for individual model', function () {
|
||||
test('fetch device models job handles processing exception for individual model', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/models' => Http::response([
|
||||
'data' => [
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ use App\Models\Firmware;
|
|||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
Storage::fake('public');
|
||||
Storage::disk('public')->makeDirectory('/firmwares');
|
||||
});
|
||||
|
||||
test('it creates firmwares directory if it does not exist', function () {
|
||||
test('it creates firmwares directory if it does not exist', function (): void {
|
||||
$firmware = Firmware::factory()->create([
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
'version_tag' => '1.0.0',
|
||||
|
|
@ -26,7 +26,7 @@ test('it creates firmwares directory if it does not exist', function () {
|
|||
expect(Storage::disk('public')->exists('firmwares'))->toBeTrue();
|
||||
});
|
||||
|
||||
test('it downloads firmware and updates storage location', function () {
|
||||
test('it downloads firmware and updates storage location', function (): void {
|
||||
Http::fake([
|
||||
'https://example.com/firmware.bin' => Http::response('fake firmware content', 200),
|
||||
]);
|
||||
|
|
@ -42,7 +42,7 @@ test('it downloads firmware and updates storage location', function () {
|
|||
expect($firmware->fresh()->storage_location)->toBe('firmwares/FW1.0.0.bin');
|
||||
});
|
||||
|
||||
test('it handles connection exception gracefully', function () {
|
||||
test('it handles connection exception gracefully', function (): void {
|
||||
$firmware = Firmware::factory()->create([
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
'version_tag' => '1.0.0',
|
||||
|
|
@ -50,7 +50,7 @@ test('it handles connection exception gracefully', function () {
|
|||
]);
|
||||
|
||||
Http::fake([
|
||||
'https://example.com/firmware.bin' => function () {
|
||||
'https://example.com/firmware.bin' => function (): void {
|
||||
throw new Illuminate\Http\Client\ConnectionException('Connection failed');
|
||||
},
|
||||
]);
|
||||
|
|
@ -65,7 +65,7 @@ test('it handles connection exception gracefully', function () {
|
|||
expect($firmware->fresh()->storage_location)->toBeNull();
|
||||
});
|
||||
|
||||
test('it handles general exception gracefully', function () {
|
||||
test('it handles general exception gracefully', function (): void {
|
||||
$firmware = Firmware::factory()->create([
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
'version_tag' => '1.0.0',
|
||||
|
|
@ -73,7 +73,7 @@ test('it handles general exception gracefully', function () {
|
|||
]);
|
||||
|
||||
Http::fake([
|
||||
'https://example.com/firmware.bin' => function () {
|
||||
'https://example.com/firmware.bin' => function (): void {
|
||||
throw new Exception('Unexpected error');
|
||||
},
|
||||
]);
|
||||
|
|
@ -88,7 +88,7 @@ test('it handles general exception gracefully', function () {
|
|||
expect($firmware->fresh()->storage_location)->toBeNull();
|
||||
});
|
||||
|
||||
test('it handles firmware with special characters in version tag', function () {
|
||||
test('it handles firmware with special characters in version tag', function (): void {
|
||||
Http::fake([
|
||||
'https://example.com/firmware.bin' => Http::response('fake firmware content', 200),
|
||||
]);
|
||||
|
|
@ -103,7 +103,7 @@ test('it handles firmware with special characters in version tag', function () {
|
|||
expect($firmware->fresh()->storage_location)->toBe('firmwares/FW1.0.0-beta.bin');
|
||||
});
|
||||
|
||||
test('it handles firmware with long version tag', function () {
|
||||
test('it handles firmware with long version tag', function (): void {
|
||||
Http::fake([
|
||||
'https://example.com/firmware.bin' => Http::response('fake firmware content', 200),
|
||||
]);
|
||||
|
|
@ -118,7 +118,7 @@ test('it handles firmware with long version tag', function () {
|
|||
expect($firmware->fresh()->storage_location)->toBe('firmwares/FW1.0.0.1234.5678.90.bin');
|
||||
});
|
||||
|
||||
test('it creates firmwares directory even when it already exists', function () {
|
||||
test('it creates firmwares directory even when it already exists', function (): void {
|
||||
$firmware = Firmware::factory()->create([
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
'version_tag' => '1.0.0',
|
||||
|
|
@ -138,7 +138,7 @@ test('it creates firmwares directory even when it already exists', function () {
|
|||
expect($firmware->fresh()->storage_location)->toBe('firmwares/FW1.0.0.bin');
|
||||
});
|
||||
|
||||
test('it handles http error response', function () {
|
||||
test('it handles http error response', function (): void {
|
||||
$firmware = Firmware::factory()->create([
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
'version_tag' => '1.0.0',
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ use App\Models\Firmware;
|
|||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
Http::preventStrayRequests();
|
||||
});
|
||||
|
||||
test('it creates new firmware record when polling', function () {
|
||||
test('it creates new firmware record when polling', function (): void {
|
||||
Http::fake([
|
||||
'https://usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'version' => '1.0.0',
|
||||
|
|
@ -25,7 +25,7 @@ test('it creates new firmware record when polling', function () {
|
|||
->latest->toBeTrue();
|
||||
});
|
||||
|
||||
test('it updates existing firmware record when polling', function () {
|
||||
test('it updates existing firmware record when polling', function (): void {
|
||||
$existingFirmware = Firmware::factory()->create([
|
||||
'version_tag' => '1.0.0',
|
||||
'url' => 'https://old-url.com/firmware.bin',
|
||||
|
|
@ -46,7 +46,7 @@ test('it updates existing firmware record when polling', function () {
|
|||
->latest->toBeTrue();
|
||||
});
|
||||
|
||||
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 (): void {
|
||||
$oldFirmware = Firmware::factory()->create([
|
||||
'version_tag' => '1.0.0',
|
||||
'latest' => true,
|
||||
|
|
@ -65,9 +65,9 @@ test('it marks previous firmware as not latest when new version is found', funct
|
|||
->and(Firmware::where('version_tag', '1.1.0')->first()->latest)->toBeTrue();
|
||||
});
|
||||
|
||||
test('it handles connection exception gracefully', function () {
|
||||
test('it handles connection exception gracefully', function (): void {
|
||||
Http::fake([
|
||||
'https://usetrmnl.com/api/firmware/latest' => function () {
|
||||
'https://usetrmnl.com/api/firmware/latest' => function (): void {
|
||||
throw new ConnectionException('Connection failed');
|
||||
},
|
||||
]);
|
||||
|
|
@ -78,7 +78,7 @@ test('it handles connection exception gracefully', function () {
|
|||
expect(Firmware::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('it handles invalid response gracefully', function () {
|
||||
test('it handles invalid response gracefully', function (): void {
|
||||
Http::fake([
|
||||
'https://usetrmnl.com/api/firmware/latest' => Http::response(null, 200),
|
||||
]);
|
||||
|
|
@ -89,7 +89,7 @@ test('it handles invalid response gracefully', function () {
|
|||
expect(Firmware::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('it handles missing version in response gracefully', function () {
|
||||
test('it handles missing version in response gracefully', function (): void {
|
||||
Http::fake([
|
||||
'https://usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'url' => 'https://example.com/firmware.bin',
|
||||
|
|
@ -102,7 +102,7 @@ test('it handles missing version in response gracefully', function () {
|
|||
expect(Firmware::count())->toBe(0);
|
||||
});
|
||||
|
||||
test('it handles missing url in response gracefully', function () {
|
||||
test('it handles missing url in response gracefully', function (): void {
|
||||
Http::fake([
|
||||
'https://usetrmnl.com/api/firmware/latest' => Http::response([
|
||||
'version' => '1.0.0',
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use App\Models\User;
|
|||
use App\Notifications\BatteryLow;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
test('it sends battery low notification when battery is below threshold', function () {
|
||||
test('it sends battery low notification when battery is below threshold', function (): void {
|
||||
Notification::fake();
|
||||
|
||||
config(['app.notifications.battery_low.warn_at_percent' => 20]);
|
||||
|
|
@ -29,7 +29,7 @@ test('it sends battery low notification when battery is below threshold', functi
|
|||
expect($device->battery_notification_sent)->toBeTrue();
|
||||
});
|
||||
|
||||
test('it does not send notification when battery is above threshold', function () {
|
||||
test('it does not send notification when battery is above threshold', function (): void {
|
||||
Notification::fake();
|
||||
|
||||
config(['app.notifications.battery_low.warn_at_percent' => 20]);
|
||||
|
|
@ -50,7 +50,7 @@ test('it does not send notification when battery is above threshold', function (
|
|||
expect($device->battery_notification_sent)->toBeFalse();
|
||||
});
|
||||
|
||||
test('it does not send notification when already sent', function () {
|
||||
test('it does not send notification when already sent', function (): void {
|
||||
Notification::fake();
|
||||
|
||||
config(['app.notifications.battery_low.warn_at_percent' => 20]);
|
||||
|
|
@ -68,7 +68,7 @@ test('it does not send notification when already sent', function () {
|
|||
Notification::assertNotSentTo($user, BatteryLow::class);
|
||||
});
|
||||
|
||||
test('it resets notification flag when battery is above threshold', function () {
|
||||
test('it resets notification flag when battery is above threshold', function (): void {
|
||||
Notification::fake();
|
||||
|
||||
config(['app.notifications.battery_low.warn_at_percent' => 20]);
|
||||
|
|
@ -89,7 +89,7 @@ test('it resets notification flag when battery is above threshold', function ()
|
|||
expect($device->battery_notification_sent)->toBeFalse();
|
||||
});
|
||||
|
||||
test('it skips devices without associated user', function () {
|
||||
test('it skips devices without associated user', function (): void {
|
||||
Notification::fake();
|
||||
|
||||
config(['app.notifications.battery_low.warn_at_percent' => 20]);
|
||||
|
|
@ -106,7 +106,7 @@ test('it skips devices without associated user', function () {
|
|||
Notification::assertNothingSent();
|
||||
});
|
||||
|
||||
test('it processes multiple devices correctly', function () {
|
||||
test('it processes multiple devices correctly', function (): void {
|
||||
Notification::fake();
|
||||
|
||||
config(['app.notifications.battery_low.warn_at_percent' => 20]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue