2023-03-30 16:58:16 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Notifications;
|
|
|
|
|
2023-04-05 12:36:24 -07:00
|
|
|
use App\Events\CheckoutableCheckedIn;
|
2023-03-30 16:58:16 -07:00
|
|
|
use App\Events\CheckoutableCheckedOut;
|
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Setting;
|
|
|
|
use App\Models\User;
|
2023-04-05 12:36:24 -07:00
|
|
|
use App\Notifications\CheckinAccessoryNotification;
|
2023-03-30 16:58:16 -07:00
|
|
|
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;
|
2023-03-30 16:58:16 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2023-04-05 12:23:11 -07:00
|
|
|
class AccessoryWebhookTest extends TestCase
|
2023-03-30 16:58:16 -07:00
|
|
|
{
|
2023-04-17 17:31:12 -07:00
|
|
|
use InteractsWithSettings;
|
|
|
|
|
2023-04-05 12:27:18 -07:00
|
|
|
public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled()
|
2023-03-30 16:58:16 -07:00
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
2024-02-14 18:17:34 -08:00
|
|
|
$this->settings->enableSlackWebhook();
|
2023-03-30 16:58:16 -07:00
|
|
|
|
|
|
|
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()
|
2023-03-30 16:58:16 -07:00
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
2023-04-17 17:31:12 -07:00
|
|
|
$this->settings->disableWebhook();
|
2023-03-30 16:58:16 -07:00
|
|
|
|
|
|
|
event(new CheckoutableCheckedOut(
|
|
|
|
Accessory::factory()->appleBtKeyboard()->create(),
|
|
|
|
User::factory()->create(),
|
|
|
|
User::factory()->superuser()->create(),
|
|
|
|
''
|
|
|
|
));
|
|
|
|
|
|
|
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
|
|
|
|
}
|
2023-04-05 12:36:24 -07:00
|
|
|
|
|
|
|
public function testAccessoryCheckinSendsWebhookNotificationWhenSettingEnabled()
|
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
2024-02-14 18:17:34 -08:00
|
|
|
$this->settings->enableSlackWebhook();
|
2023-04-05 12:36:24 -07:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2023-04-17 17:31:12 -07:00
|
|
|
$this->settings->disableWebhook();
|
2023-04-05 12:36:24 -07:00
|
|
|
|
|
|
|
event(new CheckoutableCheckedIn(
|
|
|
|
Accessory::factory()->appleBtKeyboard()->create(),
|
|
|
|
User::factory()->create(),
|
|
|
|
User::factory()->superuser()->create(),
|
|
|
|
''
|
|
|
|
));
|
|
|
|
|
|
|
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
|
|
|
|
}
|
2023-03-30 16:58:16 -07:00
|
|
|
}
|