mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 22:37:28 -08:00
Implement tests for webhook notifications on consumable checkout
This commit is contained in:
parent
aefc53cfcf
commit
b2292db3c8
|
@ -0,0 +1,53 @@
|
|||
<?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;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumableCheckoutWebhookNotificationTest extends TestCase
|
||||
{
|
||||
public function testWebhookNotificationsAreSentOnConsumableCheckoutWhenWebhookSettingEnabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
Setting::factory()->withWebhookEnabled()->create();
|
||||
|
||||
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;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function testWebhookNotificationsAreNotSentOnConsumableCheckoutWhenWebhookSettingNotEnabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
Setting::factory()->withWebhookDisabled()->create();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
Consumable::factory()->cardstock()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue