From b4dfb1673f7177102133f8c0d72b619d239221b0 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Thu, 8 May 2025 22:28:30 +0200 Subject: [PATCH] chore: add tests --- README.md | 4 +++ tests/Feature/Api/DeviceEndpointsTest.php | 32 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/README.md b/README.md index 9d8c8e4..1b54454 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ This repo is maintained voluntarily by [@bnussbau](https://github.com/bnussbau). Support the development of this package by purchasing a TRMNL device through the referral link: https://usetrmnl.com/?ref=laravel-trmnl. At checkout, use the code `laravel-trmnl` to receive a $15 discount on your purchase. +or + +[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/bnussbau) + ### Hosting Run everywhere, where Docker is supported: Raspberry Pi, VPS, NAS, Container Cloud Service (Cloud Run, ...) diff --git a/tests/Feature/Api/DeviceEndpointsTest.php b/tests/Feature/Api/DeviceEndpointsTest.php index a887cb9..06db54b 100644 --- a/tests/Feature/Api/DeviceEndpointsTest.php +++ b/tests/Feature/Api/DeviceEndpointsTest.php @@ -351,3 +351,35 @@ test('device can mirror another device', function () { ->last_battery_voltage->toBe(3.8) ->last_firmware_version->toBe('1.0.0'); }); + +test('device can fetch current screen data', function () { + $device = Device::factory()->create([ + 'mac_address' => '00:11:22:33:44:55', + 'api_key' => 'test-api-key', + 'current_screen_image' => 'test-image', + ]); + + $response = $this->withHeaders([ + 'access-token' => $device->api_key, + ])->get('/api/current_screen'); + + $response->assertOk() + ->assertJson([ + 'status' => '0', + 'filename' => 'test-image.bmp', + 'refresh_rate' => 900, + 'reset_firmware' => false, + 'update_firmware' => false, + 'firmware_url' => null, + 'special_function' => 'sleep', + ]); +}); + +test('current_screen endpoint requires valid device credentials', function () { + $response = $this->withHeaders([ + 'access-token' => 'invalid-token', + ])->get('/api/current_screen'); + + $response->assertNotFound() + ->assertJson(['message' => 'Device not found or invalid access token']); +});