feat(#188): support battery-percent header

This commit is contained in:
Benjamin Nussbaum 2026-02-12 21:48:03 +01:00
parent d9ab052cbc
commit 8400c1eaf1
2 changed files with 37 additions and 2 deletions

View file

@ -725,6 +725,40 @@ test('display endpoint updates last_refreshed_at timestamp', function (): void {
->and($device->last_refreshed_at->diffInSeconds(now()))->toBeLessThan(2);
});
test('display endpoint accepts battery-percent header and updates device', function (): void {
$device = Device::factory()->create([
'mac_address' => '00:11:22:33:44:56',
'api_key' => 'test-api-key-battery',
'last_battery_voltage' => null,
]);
$this->withHeaders([
'id' => $device->mac_address,
'access-token' => $device->api_key,
'battery-percent' => '67',
])->get('/api/display')->assertOk();
$device->refresh();
expect($device->battery_percent)->toEqual(67);
});
test('display endpoint accepts Percent-Charged header and updates device', function (): void {
$device = Device::factory()->create([
'mac_address' => '00:11:22:33:44:57',
'api_key' => 'test-api-key-percent-charged',
'last_battery_voltage' => null,
]);
$this->withHeaders([
'id' => $device->mac_address,
'access-token' => $device->api_key,
'Percent-Charged' => '51',
])->get('/api/display')->assertOk();
$device->refresh();
expect($device->battery_percent)->toEqual(51);
});
test('display endpoint updates last_refreshed_at timestamp for mirrored devices', function (): void {
// Create source device
$sourceDevice = Device::factory()->create([