mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
feat: show last refresh time for Device instead of last updated
This commit is contained in:
parent
f0b7180edd
commit
0ec6c27a53
6 changed files with 106 additions and 2 deletions
|
|
@ -647,3 +647,53 @@ test('plugins in playlist are rendered in order', function () {
|
|||
expect($thirdResponse['filename'])
|
||||
->not->toBe($secondResponse['filename']);
|
||||
})->skipOnGitHubActions();
|
||||
|
||||
test('display endpoint updates last_refreshed_at timestamp', function () {
|
||||
$device = Device::factory()->create([
|
||||
'mac_address' => '00:11:22:33:44:55',
|
||||
'api_key' => 'test-api-key',
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'id' => $device->mac_address,
|
||||
'access-token' => $device->api_key,
|
||||
'rssi' => -70,
|
||||
'battery_voltage' => 3.8,
|
||||
'fw-version' => '1.0.0',
|
||||
])->get('/api/display');
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$device->refresh();
|
||||
expect($device->last_refreshed_at)->not->toBeNull()
|
||||
->and($device->last_refreshed_at->diffInSeconds(now()))->toBeLessThan(2);
|
||||
});
|
||||
|
||||
test('display endpoint updates last_refreshed_at timestamp for mirrored devices', function () {
|
||||
// Create source device
|
||||
$sourceDevice = Device::factory()->create([
|
||||
'mac_address' => '00:11:22:33:44:55',
|
||||
'api_key' => 'source-api-key',
|
||||
]);
|
||||
|
||||
// Create mirroring device
|
||||
$mirrorDevice = Device::factory()->create([
|
||||
'mac_address' => 'AA:BB:CC:DD:EE:FF',
|
||||
'api_key' => 'mirror-api-key',
|
||||
'mirror_device_id' => $sourceDevice->id,
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'id' => $mirrorDevice->mac_address,
|
||||
'access-token' => $mirrorDevice->api_key,
|
||||
'rssi' => -70,
|
||||
'battery_voltage' => 3.8,
|
||||
'fw-version' => '1.0.0',
|
||||
])->get('/api/display');
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$mirrorDevice->refresh();
|
||||
expect($mirrorDevice->last_refreshed_at)->not->toBeNull()
|
||||
->and($mirrorDevice->last_refreshed_at->diffInSeconds(now()))->toBeLessThan(2);
|
||||
});
|
||||
|
|
|
|||
24
tests/Feature/DeviceConfigureTest.php
Normal file
24
tests/Feature/DeviceConfigureTest.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use function Pest\Laravel\actingAs;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('configure view displays last_refreshed_at timestamp', function () {
|
||||
$user = User::factory()->create();
|
||||
$device = Device::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'last_refreshed_at' => now()->subMinutes(5),
|
||||
]);
|
||||
|
||||
$response = actingAs($user)
|
||||
->get(route('devices.configure', $device));
|
||||
|
||||
$response->assertOk()
|
||||
->assertSee('5 minutes ago');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue