Consolidate some slack notification tests

This commit is contained in:
Marcus Moore 2024-02-27 17:07:40 -08:00
parent c08164d864
commit 7d3719bf70
No known key found for this signature in database
4 changed files with 114 additions and 118 deletions

View file

@ -1,50 +0,0 @@
<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;
use App\Models\Component;
use App\Models\User;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ComponentSlackTest extends TestCase
{
use InteractsWithSettings;
public function testComponentCheckoutDoesNotSendSlackNotification()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNothingSent();
}
public function testComponentCheckinDoesNotSendSlackNotification()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNothingSent();
}
}

View file

@ -1,56 +0,0 @@
<?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\Support\InteractsWithSettings;
use Tests\TestCase;
class ConsumableSlackTest extends TestCase
{
use InteractsWithSettings;
public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
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 testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
{
Notification::fake();
$this->settings->disableSlackWebhook();
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace Tests\Feature\Notifications\Webhooks;
use App\Events\CheckoutableCheckedIn;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class SlackNotificationsUponCheckinTest extends TestCase
{
use InteractsWithSettings;
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;
}
);
}
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
{
Notification::fake();
$this->settings->disableSlackWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
}
public function testComponentCheckinDoesNotSendSlackNotification()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNothingSent();
}
public function testConsumableCheckinSendSlackNotificationWhenSettingEnabled()
{
$this->markTestIncomplete();
}
public function testConsumableCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
{
$this->markTestIncomplete();
}
}

View file

@ -1,20 +1,22 @@
<?php
namespace Tests\Feature\Notifications;
namespace Tests\Feature\Notifications\Webhooks;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\Consumable;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutConsumableNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessorySlackTest extends TestCase
class SlackNotificationsUponCheckoutTest extends TestCase
{
use InteractsWithSettings;
@ -56,14 +58,30 @@ class AccessorySlackTest extends TestCase
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
}
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
public function testComponentCheckoutDoesNotSendSlackNotification()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
event(new CheckoutableCheckedOut(
Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNothingSent();
}
public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
@ -71,26 +89,26 @@ class AccessorySlackTest extends TestCase
Notification::assertSentTo(
new AnonymousNotifiable,
CheckinAccessoryNotification::class,
CheckoutConsumableNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
{
Notification::fake();
$this->settings->disableSlackWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
}
}