Skip to content

A free open source IT asset/license management system

Consolidate some slack notification tests

Marcus Moore7d3719bf705e
diff --git a/tests/Feature/Notifications/ComponentSlackTest.php b/tests/Feature/Notifications/ComponentSlackTest.php
deleted file mode 100644
index b9fba83690..0000000000
--- a/tests/Feature/Notifications/ComponentSlackTest.php
+++ /dev/null
@@ -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();
- }
-}
diff --git a/tests/Feature/Notifications/ConsumableSlackTest.php b/tests/Feature/Notifications/ConsumableSlackTest.php
deleted file mode 100644
index 9fd5d0b82a..0000000000
--- a/tests/Feature/Notifications/ConsumableSlackTest.php
+++ /dev/null
@@ -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);
- }
-}
diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
new file mode 100644
index 0000000000..282417d822
--- /dev/null
+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
@@ -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();
+ }
+}
diff --git a/tests/Feature/Notifications/AccessorySlackTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
similarity index 67%
rename from tests/Feature/Notifications/AccessorySlackTest.php
rename to tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
index bd54ed8cb9..3992a6c51b 100644
--- a/tests/Feature/Notifications/AccessorySlackTest.php
+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
@@ -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);
}
}