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

94 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;
use Tests\TestCase;
2023-04-05 12:23:11 -07:00
class AccessoryWebhookTest extends TestCase
{
2023-04-05 12:27:18 -07:00
public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled()
{
Notification::fake();
Setting::factory()->withWebhookEnabled()->create();
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;
}
);
}
2023-04-05 12:27:18 -07:00
public function testAccessoryCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled()
{
Notification::fake();
Setting::factory()->withWebhookDisabled()->create();
event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
}
public function testAccessoryCheckinSendsWebhookNotificationWhenSettingEnabled()
{
Notification::fake();
Setting::factory()->withWebhookEnabled()->create();
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;
}
);
}
public function testAccessoryCheckinDoesNotSendWebhookNotificationWhenSettingDisabled()
{
Notification::fake();
Setting::factory()->withWebhookDisabled()->create();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
}
}