fix: update_firmware flag is only returned once to avoid upgrade loop

chore: fix code style
This commit is contained in:
Benjamin Nussbaum 2025-03-30 10:19:15 +02:00
parent 5367fc8a64
commit 6e5e4cd633
4 changed files with 59 additions and 1 deletions

View file

@ -198,3 +198,48 @@ test('log endpoint requires valid device credentials', function () {
$response->assertNotFound()
->assertJson(['message' => 'Device not found or invalid access token']);
});
test('update_firmware flag is only returned once', function () {
$device = Device::factory()->create([
'mac_address' => '00:11:22:33:44:55',
'api_key' => 'test-api-key',
'proxy_cloud_response' => [
'update_firmware' => true,
'firmware_url' => 'https://example.com/firmware.bin',
],
]);
// First request should return update_firmware as true
$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()
->assertJson([
'update_firmware' => true,
'firmware_url' => 'https://example.com/firmware.bin',
]);
// Second request should return update_firmware as false
$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()
->assertJson([
'update_firmware' => false,
'firmware_url' => 'https://example.com/firmware.bin',
]);
// Verify the proxy_cloud_response was updated
$device->refresh();
expect($device->proxy_cloud_response['update_firmware'])->toBeFalse();
});