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

57 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedOut;
use App\Models\Consumable;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckoutConsumableNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
2023-04-17 17:31:12 -07:00
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
2023-04-05 12:23:11 -07:00
class ConsumableWebhookTest extends TestCase
{
2023-04-17 17:31:12 -07:00
use InteractsWithSettings;
2023-04-05 12:27:18 -07:00
public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled()
{
Notification::fake();
2023-04-17 17:31:12 -07:00
$this->settings->enableWebhook();
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckoutConsumableNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
2023-04-05 12:27:18 -07:00
public function testConsumableCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled()
{
Notification::fake();
2023-04-17 17:31:12 -07:00
$this->settings->disableWebhook();
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
}
}