snipe-it/tests/Feature/Notifications/AccessorySlackTest.php

97 lines
2.9 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Accessory;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
2023-04-17 17:31:12 -07:00
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
2024-02-27 16:48:17 -08:00
class AccessorySlackTest extends TestCase
{
2023-04-17 17:31:12 -07:00
use InteractsWithSettings;
2024-02-27 16:48:17 -08:00
public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckoutAccessoryNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
2024-02-27 16:48:17 -08:00
public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
{
Notification::fake();
2024-02-27 16:45:49 -08:00
$this->settings->disableSlackWebhook();
event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
}
2024-02-27 16:48:17 -08:00
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckinAccessoryNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
2024-02-27 16:48:17 -08:00
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
{
Notification::fake();
2024-02-27 16:45:49 -08:00
$this->settings->disableSlackWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
}
}