Skip to content

A free open source IT asset/license management system

Consolidate additional tests

Marcus Moore43cc296582b8
diff --git a/tests/Feature/Notifications/AssetSlackTest.php b/tests/Feature/Notifications/AssetSlackTest.php
deleted file mode 100644
index c6d03df636..0000000000
--- a/tests/Feature/Notifications/AssetSlackTest.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-namespace Tests\Feature\Notifications;
-
-use App\Events\CheckoutableCheckedIn;
-use App\Events\CheckoutableCheckedOut;
-use App\Models\Asset;
-use App\Models\Location;
-use App\Models\Setting;
-use App\Models\User;
-use App\Notifications\CheckinAssetNotification;
-use App\Notifications\CheckoutAssetNotification;
-use Illuminate\Notifications\AnonymousNotifiable;
-use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
-use Tests\TestCase;
-
-class AssetSlackTest extends TestCase
-{
- use InteractsWithSettings;
-
- public function assetCheckoutTargets(): array
- {
- return [
- 'Asset checked out to user' => [fn() => User::factory()->create()],
- 'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
- 'Asset checked out to location' => [fn() => Location::factory()->create()],
- ];
- }
-
- /** @dataProvider assetCheckoutTargets */
- public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->enableSlackWebhook();
-
- event(new CheckoutableCheckedOut(
- Asset::factory()->laptopMbp()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertSentTo(
- new AnonymousNotifiable,
- CheckoutAssetNotification::class,
- function ($notification, $channels, $notifiable) {
- return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
- }
- );
- }
-
- /** @dataProvider assetCheckoutTargets */
- public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->disableSlackWebhook();
-
- event(new CheckoutableCheckedOut(
- Asset::factory()->laptopMbp()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
- }
-
- /** @dataProvider assetCheckoutTargets */
- public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->enableSlackWebhook();
-
- event(new CheckoutableCheckedIn(
- Asset::factory()->laptopMbp()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertSentTo(
- new AnonymousNotifiable,
- CheckinAssetNotification::class,
- function ($notification, $channels, $notifiable) {
- return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
- }
- );
- }
-
- /** @dataProvider assetCheckoutTargets */
- public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->disableSlackWebhook();
-
- event(new CheckoutableCheckedIn(
- Asset::factory()->laptopMbp()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class);
- }
-}
diff --git a/tests/Feature/Notifications/LicenseSlackTest.php b/tests/Feature/Notifications/LicenseSlackTest.php
deleted file mode 100644
index 8ed38c2788..0000000000
--- a/tests/Feature/Notifications/LicenseSlackTest.php
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-
-namespace Tests\Feature\Notifications;
-
-use App\Events\CheckoutableCheckedIn;
-use App\Events\CheckoutableCheckedOut;
-use App\Models\Asset;
-use App\Models\LicenseSeat;
-use App\Models\Setting;
-use App\Models\User;
-use App\Notifications\CheckinLicenseSeatNotification;
-use App\Notifications\CheckoutLicenseSeatNotification;
-use Illuminate\Notifications\AnonymousNotifiable;
-use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
-use Tests\TestCase;
-
-class LicenseSlackTest extends TestCase
-{
- use InteractsWithSettings;
-
- public function licenseCheckoutTargets(): array
- {
- return [
- 'License checked out to user' => [fn() => User::factory()->create()],
- 'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
- ];
- }
-
- /** @dataProvider licenseCheckoutTargets */
- public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->enableSlackWebhook();
-
- event(new CheckoutableCheckedOut(
- LicenseSeat::factory()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertSentTo(
- new AnonymousNotifiable,
- CheckoutLicenseSeatNotification::class,
- function ($notification, $channels, $notifiable) {
- return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
- }
- );
- }
-
- /** @dataProvider licenseCheckoutTargets */
- public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->disableSlackWebhook();
-
- event(new CheckoutableCheckedOut(
- LicenseSeat::factory()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
- }
-
- /** @dataProvider licenseCheckoutTargets */
- public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->enableSlackWebhook();
-
- event(new CheckoutableCheckedIn(
- LicenseSeat::factory()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertSentTo(
- new AnonymousNotifiable,
- CheckinLicenseSeatNotification::class,
- function ($notification, $channels, $notifiable) {
- return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
- }
- );
- }
-
- /** @dataProvider licenseCheckoutTargets */
- public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
- {
- Notification::fake();
-
- $this->settings->disableSlackWebhook();
-
- event(new CheckoutableCheckedIn(
- LicenseSeat::factory()->create(),
- $checkoutTarget(),
- User::factory()->superuser()->create(),
- ''
- ));
-
- Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class);
- }
-}
diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
index 282417d822..2cf697e93f 100644
--- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
@@ -6,9 +6,13 @@ use App\Events\CheckoutableCheckedIn;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
+use App\Models\LicenseSeat;
+use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
+use App\Notifications\CheckinAssetNotification;
+use App\Notifications\CheckinLicenseSeatNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
@@ -18,6 +22,23 @@ class SlackNotificationsUponCheckinTest extends TestCase
{
use InteractsWithSettings;
+ public function assetCheckoutTargets(): array
+ {
+ return [
+ 'Asset checked out to user' => [fn() => User::factory()->create()],
+ 'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
+ 'Asset checked out to location' => [fn() => Location::factory()->create()],
+ ];
+ }
+
+ public function licenseCheckoutTargets(): array
+ {
+ return [
+ 'License checked out to user' => [fn() => User::factory()->create()],
+ 'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
+ ];
+ }
+
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
{
Notification::fake();
@@ -56,6 +77,46 @@ class SlackNotificationsUponCheckinTest extends TestCase
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
}
+ /** @dataProvider assetCheckoutTargets */
+ public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->enableSlackWebhook();
+
+ event(new CheckoutableCheckedIn(
+ Asset::factory()->laptopMbp()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertSentTo(
+ new AnonymousNotifiable,
+ CheckinAssetNotification::class,
+ function ($notification, $channels, $notifiable) {
+ return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
+ }
+ );
+ }
+
+ /** @dataProvider assetCheckoutTargets */
+ public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->disableSlackWebhook();
+
+ event(new CheckoutableCheckedIn(
+ Asset::factory()->laptopMbp()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class);
+ }
+
public function testComponentCheckinDoesNotSendSlackNotification()
{
Notification::fake();
@@ -81,4 +142,44 @@ class SlackNotificationsUponCheckinTest extends TestCase
{
$this->markTestIncomplete();
}
+
+ /** @dataProvider licenseCheckoutTargets */
+ public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->enableSlackWebhook();
+
+ event(new CheckoutableCheckedIn(
+ LicenseSeat::factory()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertSentTo(
+ new AnonymousNotifiable,
+ CheckinLicenseSeatNotification::class,
+ function ($notification, $channels, $notifiable) {
+ return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
+ }
+ );
+ }
+
+ /** @dataProvider licenseCheckoutTargets */
+ public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->disableSlackWebhook();
+
+ event(new CheckoutableCheckedIn(
+ LicenseSeat::factory()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class);
+ }
}
diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
index 3992a6c51b..aeee70c9b4 100644
--- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
@@ -7,10 +7,14 @@ use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\Consumable;
+use App\Models\LicenseSeat;
+use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckoutAccessoryNotification;
+use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CheckoutConsumableNotification;
+use App\Notifications\CheckoutLicenseSeatNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
@@ -20,6 +24,23 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{
use InteractsWithSettings;
+ public function assetCheckoutTargets(): array
+ {
+ return [
+ 'Asset checked out to user' => [fn() => User::factory()->create()],
+ 'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
+ 'Asset checked out to location' => [fn() => Location::factory()->create()],
+ ];
+ }
+
+ public function licenseCheckoutTargets(): array
+ {
+ return [
+ 'License checked out to user' => [fn() => User::factory()->create()],
+ 'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
+ ];
+ }
+
public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled()
{
Notification::fake();
@@ -58,6 +79,46 @@ class SlackNotificationsUponCheckoutTest extends TestCase
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
}
+ /** @dataProvider assetCheckoutTargets */
+ public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->enableSlackWebhook();
+
+ event(new CheckoutableCheckedOut(
+ Asset::factory()->laptopMbp()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertSentTo(
+ new AnonymousNotifiable,
+ CheckoutAssetNotification::class,
+ function ($notification, $channels, $notifiable) {
+ return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
+ }
+ );
+ }
+
+ /** @dataProvider assetCheckoutTargets */
+ public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->disableSlackWebhook();
+
+ event(new CheckoutableCheckedOut(
+ Asset::factory()->laptopMbp()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
+ }
+
public function testComponentCheckoutDoesNotSendSlackNotification()
{
Notification::fake();
@@ -111,4 +172,44 @@ class SlackNotificationsUponCheckoutTest extends TestCase
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
}
+
+ /** @dataProvider licenseCheckoutTargets */
+ public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->enableSlackWebhook();
+
+ event(new CheckoutableCheckedOut(
+ LicenseSeat::factory()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertSentTo(
+ new AnonymousNotifiable,
+ CheckoutLicenseSeatNotification::class,
+ function ($notification, $channels, $notifiable) {
+ return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
+ }
+ );
+ }
+
+ /** @dataProvider licenseCheckoutTargets */
+ public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
+ {
+ Notification::fake();
+
+ $this->settings->disableSlackWebhook();
+
+ event(new CheckoutableCheckedOut(
+ LicenseSeat::factory()->create(),
+ $checkoutTarget(),
+ User::factory()->superuser()->create(),
+ ''
+ ));
+
+ Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
+ }
}