mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
This commit is contained in:
parent
4f251bf37e
commit
42b515e322
21 changed files with 2212 additions and 32 deletions
76
tests/Unit/Notifications/BatteryLowTest.php
Normal file
76
tests/Unit/Notifications/BatteryLowTest.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\User;
|
||||
use App\Notifications\BatteryLow;
|
||||
use App\Notifications\Channels\WebhookChannel;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
test('battery low notification has correct via channels', function () {
|
||||
$device = Device::factory()->create();
|
||||
$notification = new BatteryLow($device);
|
||||
|
||||
expect($notification->via(new User()))->toBe(['mail', WebhookChannel::class]);
|
||||
});
|
||||
|
||||
test('battery low notification creates correct mail message', function () {
|
||||
$device = Device::factory()->create([
|
||||
'name' => 'Test Device',
|
||||
'last_battery_voltage' => 3.0,
|
||||
]);
|
||||
|
||||
$notification = new BatteryLow($device);
|
||||
$mailMessage = $notification->toMail(new User());
|
||||
|
||||
expect($mailMessage)->toBeInstanceOf(MailMessage::class);
|
||||
expect($mailMessage->markdown)->toBe('mail.battery-low');
|
||||
expect($mailMessage->viewData['device'])->toBe($device);
|
||||
});
|
||||
|
||||
test('battery low notification creates correct webhook message', function () {
|
||||
config([
|
||||
'services.webhook.notifications.topic' => 'battery.low',
|
||||
'app.name' => 'Test App',
|
||||
]);
|
||||
|
||||
$device = Device::factory()->create([
|
||||
'name' => 'Test Device',
|
||||
'last_battery_voltage' => 3.0,
|
||||
]);
|
||||
|
||||
$notification = new BatteryLow($device);
|
||||
$webhookMessage = $notification->toWebhook(new User());
|
||||
|
||||
expect($webhookMessage->toArray())->toBe([
|
||||
'query' => null,
|
||||
'data' => [
|
||||
'topic' => 'battery.low',
|
||||
'message' => "Battery below {$device->battery_percent}% on device: Test Device",
|
||||
'device_id' => $device->id,
|
||||
'device_name' => 'Test Device',
|
||||
'battery_percent' => $device->battery_percent,
|
||||
],
|
||||
'headers' => [
|
||||
'User-Agent' => 'Test App',
|
||||
'X-TrmnlByos-Event' => 'battery.low',
|
||||
],
|
||||
'verify' => false,
|
||||
]);
|
||||
});
|
||||
|
||||
test('battery low notification creates correct array representation', function () {
|
||||
$device = Device::factory()->create([
|
||||
'name' => 'Test Device',
|
||||
'last_battery_voltage' => 3.0,
|
||||
]);
|
||||
|
||||
$notification = new BatteryLow($device);
|
||||
$array = $notification->toArray(new User());
|
||||
|
||||
expect($array)->toBe([
|
||||
'device_name' => 'Test Device',
|
||||
'battery_percent' => $device->battery_percent,
|
||||
]);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue