mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: add api endpoint /devices
This commit is contained in:
parent
8d7a53b888
commit
fd18cf5246
2 changed files with 57 additions and 0 deletions
|
|
@ -422,3 +422,45 @@ test('current_screen endpoint requires valid device credentials', function () {
|
|||
$response->assertNotFound()
|
||||
->assertJson(['message' => 'Device not found or invalid access token']);
|
||||
});
|
||||
|
||||
test('authenticated user can fetch their devices', function () {
|
||||
$user = User::factory()->create();
|
||||
$devices = Device::factory()->count(2)->create([
|
||||
'user_id' => $user->id,
|
||||
'last_battery_voltage' => 3.72,
|
||||
'last_rssi_level' => -63,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/devices');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => [
|
||||
'id',
|
||||
'name',
|
||||
'friendly_id',
|
||||
'mac_address',
|
||||
'battery_voltage',
|
||||
'rssi'
|
||||
]
|
||||
]
|
||||
])
|
||||
->assertJsonCount(2, 'data');
|
||||
|
||||
// Verify the first device's data
|
||||
$response->assertJson([
|
||||
'data' => [
|
||||
[
|
||||
'id' => $devices[0]->id,
|
||||
'name' => $devices[0]->name,
|
||||
'friendly_id' => $devices[0]->friendly_id,
|
||||
'mac_address' => $devices[0]->mac_address,
|
||||
'battery_voltage' => 3.72,
|
||||
'rssi' => -63
|
||||
]
|
||||
]
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue