From b156aa74a59cfe474e753ad3cb8665cae2361a8e Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 16:45:49 -0800 Subject: [PATCH 01/33] Update helper name --- tests/Feature/Notifications/AccessoryWebhookTest.php | 4 ++-- tests/Feature/Notifications/AssetWebhookTest.php | 4 ++-- tests/Feature/Notifications/ConsumableWebhookTest.php | 2 +- tests/Feature/Notifications/LicenseWebhookTest.php | 4 ++-- tests/Support/Settings.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Feature/Notifications/AccessoryWebhookTest.php b/tests/Feature/Notifications/AccessoryWebhookTest.php index 2e3ef999b..b6e74feb5 100644 --- a/tests/Feature/Notifications/AccessoryWebhookTest.php +++ b/tests/Feature/Notifications/AccessoryWebhookTest.php @@ -44,7 +44,7 @@ class AccessoryWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( Accessory::factory()->appleBtKeyboard()->create(), @@ -82,7 +82,7 @@ class AccessoryWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( Accessory::factory()->appleBtKeyboard()->create(), diff --git a/tests/Feature/Notifications/AssetWebhookTest.php b/tests/Feature/Notifications/AssetWebhookTest.php index 158bced66..d693ce3fe 100644 --- a/tests/Feature/Notifications/AssetWebhookTest.php +++ b/tests/Feature/Notifications/AssetWebhookTest.php @@ -56,7 +56,7 @@ class AssetWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( $this->createAsset(), @@ -96,7 +96,7 @@ class AssetWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( $this->createAsset(), diff --git a/tests/Feature/Notifications/ConsumableWebhookTest.php b/tests/Feature/Notifications/ConsumableWebhookTest.php index 2815731bd..035573bb4 100644 --- a/tests/Feature/Notifications/ConsumableWebhookTest.php +++ b/tests/Feature/Notifications/ConsumableWebhookTest.php @@ -42,7 +42,7 @@ class ConsumableWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( Consumable::factory()->cardstock()->create(), diff --git a/tests/Feature/Notifications/LicenseWebhookTest.php b/tests/Feature/Notifications/LicenseWebhookTest.php index 24ec53a75..cfb2fca5b 100644 --- a/tests/Feature/Notifications/LicenseWebhookTest.php +++ b/tests/Feature/Notifications/LicenseWebhookTest.php @@ -55,7 +55,7 @@ class LicenseWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( LicenseSeat::factory()->create(), @@ -95,7 +95,7 @@ class LicenseWebhookTest extends TestCase { Notification::fake(); - $this->settings->disableWebhook(); + $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( LicenseSeat::factory()->create(), diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 310485115..2d499838c 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -49,7 +49,7 @@ class Settings ]); } - public function disableWebhook(): Settings + public function disableSlackWebhook(): Settings { return $this->update([ 'webhook_selected' => '', From c08164d864e7b92d7f813eece30c7fc050e3f3ac Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 16:48:17 -0800 Subject: [PATCH 02/33] Update test names --- ...AccessoryWebhookTest.php => AccessorySlackTest.php} | 10 +++++----- .../{AssetWebhookTest.php => AssetSlackTest.php} | 10 +++++----- ...ComponentWebhookTest.php => ComponentSlackTest.php} | 6 +++--- ...nsumableWebhookTest.php => ConsumableSlackTest.php} | 6 +++--- .../{LicenseWebhookTest.php => LicenseSlackTest.php} | 10 +++++----- 5 files changed, 21 insertions(+), 21 deletions(-) rename tests/Feature/Notifications/{AccessoryWebhookTest.php => AccessorySlackTest.php} (86%) rename tests/Feature/Notifications/{AssetWebhookTest.php => AssetSlackTest.php} (87%) rename tests/Feature/Notifications/{ComponentWebhookTest.php => ComponentSlackTest.php} (84%) rename tests/Feature/Notifications/{ConsumableWebhookTest.php => ConsumableSlackTest.php} (86%) rename tests/Feature/Notifications/{LicenseWebhookTest.php => LicenseSlackTest.php} (86%) diff --git a/tests/Feature/Notifications/AccessoryWebhookTest.php b/tests/Feature/Notifications/AccessorySlackTest.php similarity index 86% rename from tests/Feature/Notifications/AccessoryWebhookTest.php rename to tests/Feature/Notifications/AccessorySlackTest.php index b6e74feb5..bd54ed8cb 100644 --- a/tests/Feature/Notifications/AccessoryWebhookTest.php +++ b/tests/Feature/Notifications/AccessorySlackTest.php @@ -14,11 +14,11 @@ use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; -class AccessoryWebhookTest extends TestCase +class AccessorySlackTest extends TestCase { use InteractsWithSettings; - public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled() + public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled() { Notification::fake(); @@ -40,7 +40,7 @@ class AccessoryWebhookTest extends TestCase ); } - public function testAccessoryCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled() + public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() { Notification::fake(); @@ -56,7 +56,7 @@ class AccessoryWebhookTest extends TestCase Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class); } - public function testAccessoryCheckinSendsWebhookNotificationWhenSettingEnabled() + public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled() { Notification::fake(); @@ -78,7 +78,7 @@ class AccessoryWebhookTest extends TestCase ); } - public function testAccessoryCheckinDoesNotSendWebhookNotificationWhenSettingDisabled() + public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled() { Notification::fake(); diff --git a/tests/Feature/Notifications/AssetWebhookTest.php b/tests/Feature/Notifications/AssetSlackTest.php similarity index 87% rename from tests/Feature/Notifications/AssetWebhookTest.php rename to tests/Feature/Notifications/AssetSlackTest.php index d693ce3fe..d0b376c65 100644 --- a/tests/Feature/Notifications/AssetWebhookTest.php +++ b/tests/Feature/Notifications/AssetSlackTest.php @@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; -class AssetWebhookTest extends TestCase +class AssetSlackTest extends TestCase { use InteractsWithSettings; @@ -29,7 +29,7 @@ class AssetWebhookTest extends TestCase } /** @dataProvider targets */ - public function testAssetCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget) + public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -52,7 +52,7 @@ class AssetWebhookTest extends TestCase } /** @dataProvider targets */ - public function testAssetCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget) + public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); @@ -69,7 +69,7 @@ class AssetWebhookTest extends TestCase } /** @dataProvider targets */ - public function testAssetCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget) + public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -92,7 +92,7 @@ class AssetWebhookTest extends TestCase } /** @dataProvider targets */ - public function testAssetCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget) + public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); diff --git a/tests/Feature/Notifications/ComponentWebhookTest.php b/tests/Feature/Notifications/ComponentSlackTest.php similarity index 84% rename from tests/Feature/Notifications/ComponentWebhookTest.php rename to tests/Feature/Notifications/ComponentSlackTest.php index 2e2a53521..b9fba8369 100644 --- a/tests/Feature/Notifications/ComponentWebhookTest.php +++ b/tests/Feature/Notifications/ComponentSlackTest.php @@ -11,12 +11,12 @@ use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; -class ComponentWebhookTest extends TestCase +class ComponentSlackTest extends TestCase { use InteractsWithSettings; - public function testComponentCheckoutDoesNotSendWebhookNotification() + public function testComponentCheckoutDoesNotSendSlackNotification() { Notification::fake(); @@ -32,7 +32,7 @@ class ComponentWebhookTest extends TestCase Notification::assertNothingSent(); } - public function testComponentCheckinDoesNotSendWebhookNotification() + public function testComponentCheckinDoesNotSendSlackNotification() { Notification::fake(); diff --git a/tests/Feature/Notifications/ConsumableWebhookTest.php b/tests/Feature/Notifications/ConsumableSlackTest.php similarity index 86% rename from tests/Feature/Notifications/ConsumableWebhookTest.php rename to tests/Feature/Notifications/ConsumableSlackTest.php index 035573bb4..9fd5d0b82 100644 --- a/tests/Feature/Notifications/ConsumableWebhookTest.php +++ b/tests/Feature/Notifications/ConsumableSlackTest.php @@ -12,11 +12,11 @@ use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; -class ConsumableWebhookTest extends TestCase +class ConsumableSlackTest extends TestCase { use InteractsWithSettings; - public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled() + public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled() { Notification::fake(); @@ -38,7 +38,7 @@ class ConsumableWebhookTest extends TestCase ); } - public function testConsumableCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled() + public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() { Notification::fake(); diff --git a/tests/Feature/Notifications/LicenseWebhookTest.php b/tests/Feature/Notifications/LicenseSlackTest.php similarity index 86% rename from tests/Feature/Notifications/LicenseWebhookTest.php rename to tests/Feature/Notifications/LicenseSlackTest.php index cfb2fca5b..c10fbdf5c 100644 --- a/tests/Feature/Notifications/LicenseWebhookTest.php +++ b/tests/Feature/Notifications/LicenseSlackTest.php @@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; -class LicenseWebhookTest extends TestCase +class LicenseSlackTest extends TestCase { use InteractsWithSettings; @@ -28,7 +28,7 @@ class LicenseWebhookTest extends TestCase } /** @dataProvider targets */ - public function testLicenseCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget) + public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -51,7 +51,7 @@ class LicenseWebhookTest extends TestCase } /** @dataProvider targets */ - public function testLicenseCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget) + public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); @@ -68,7 +68,7 @@ class LicenseWebhookTest extends TestCase } /** @dataProvider targets */ - public function testLicenseCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget) + public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -91,7 +91,7 @@ class LicenseWebhookTest extends TestCase } /** @dataProvider targets */ - public function testLicenseCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget) + public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); From 7d3719bf705e11c4fa63649e279b4f90def1b88a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:07:40 -0800 Subject: [PATCH 03/33] Consolidate some slack notification tests --- .../Notifications/ComponentSlackTest.php | 50 ----------- .../Notifications/ConsumableSlackTest.php | 56 ------------- .../SlackNotificationsUponCheckinTest.php | 84 +++++++++++++++++++ .../SlackNotificationsUponCheckoutTest.php} | 42 +++++++--- 4 files changed, 114 insertions(+), 118 deletions(-) delete mode 100644 tests/Feature/Notifications/ComponentSlackTest.php delete mode 100644 tests/Feature/Notifications/ConsumableSlackTest.php create mode 100644 tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php rename tests/Feature/Notifications/{AccessorySlackTest.php => Webhooks/SlackNotificationsUponCheckoutTest.php} (67%) diff --git a/tests/Feature/Notifications/ComponentSlackTest.php b/tests/Feature/Notifications/ComponentSlackTest.php deleted file mode 100644 index b9fba8369..000000000 --- a/tests/Feature/Notifications/ComponentSlackTest.php +++ /dev/null @@ -1,50 +0,0 @@ -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 9fd5d0b82..000000000 --- a/tests/Feature/Notifications/ConsumableSlackTest.php +++ /dev/null @@ -1,56 +0,0 @@ -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 000000000..282417d82 --- /dev/null +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -0,0 +1,84 @@ +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 bd54ed8cb..3992a6c51 100644 --- a/tests/Feature/Notifications/AccessorySlackTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -1,20 +1,22 @@ 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); } } From 4c1aadd74e6aa43d13e7d96ee833abffa6de8d21 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:09:22 -0800 Subject: [PATCH 04/33] Improve naming and inline helper --- .../Feature/Notifications/AssetSlackTest.php | 25 ++++++++----------- .../Notifications/LicenseSlackTest.php | 10 ++++---- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/Feature/Notifications/AssetSlackTest.php b/tests/Feature/Notifications/AssetSlackTest.php index d0b376c65..c6d03df63 100644 --- a/tests/Feature/Notifications/AssetSlackTest.php +++ b/tests/Feature/Notifications/AssetSlackTest.php @@ -19,16 +19,16 @@ class AssetSlackTest extends TestCase { use InteractsWithSettings; - public function targets(): array + public function assetCheckoutTargets(): array { return [ 'Asset checked out to user' => [fn() => User::factory()->create()], - 'Asset checked out to asset' => [fn() => $this->createAsset()], + 'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()], 'Asset checked out to location' => [fn() => Location::factory()->create()], ]; } - /** @dataProvider targets */ + /** @dataProvider assetCheckoutTargets */ public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -36,7 +36,7 @@ class AssetSlackTest extends TestCase $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( - $this->createAsset(), + Asset::factory()->laptopMbp()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' @@ -51,7 +51,7 @@ class AssetSlackTest extends TestCase ); } - /** @dataProvider targets */ + /** @dataProvider assetCheckoutTargets */ public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); @@ -59,7 +59,7 @@ class AssetSlackTest extends TestCase $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( - $this->createAsset(), + Asset::factory()->laptopMbp()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' @@ -68,7 +68,7 @@ class AssetSlackTest extends TestCase Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); } - /** @dataProvider targets */ + /** @dataProvider assetCheckoutTargets */ public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -76,7 +76,7 @@ class AssetSlackTest extends TestCase $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedIn( - $this->createAsset(), + Asset::factory()->laptopMbp()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' @@ -91,7 +91,7 @@ class AssetSlackTest extends TestCase ); } - /** @dataProvider targets */ + /** @dataProvider assetCheckoutTargets */ public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); @@ -99,7 +99,7 @@ class AssetSlackTest extends TestCase $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( - $this->createAsset(), + Asset::factory()->laptopMbp()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' @@ -107,9 +107,4 @@ class AssetSlackTest extends TestCase Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class); } - - private function createAsset() - { - return Asset::factory()->laptopMbp()->create(); - } } diff --git a/tests/Feature/Notifications/LicenseSlackTest.php b/tests/Feature/Notifications/LicenseSlackTest.php index c10fbdf5c..8ed38c278 100644 --- a/tests/Feature/Notifications/LicenseSlackTest.php +++ b/tests/Feature/Notifications/LicenseSlackTest.php @@ -19,7 +19,7 @@ class LicenseSlackTest extends TestCase { use InteractsWithSettings; - public function targets(): array + public function licenseCheckoutTargets(): array { return [ 'License checked out to user' => [fn() => User::factory()->create()], @@ -27,7 +27,7 @@ class LicenseSlackTest extends TestCase ]; } - /** @dataProvider targets */ + /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -50,7 +50,7 @@ class LicenseSlackTest extends TestCase ); } - /** @dataProvider targets */ + /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); @@ -67,7 +67,7 @@ class LicenseSlackTest extends TestCase Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class); } - /** @dataProvider targets */ + /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { Notification::fake(); @@ -90,7 +90,7 @@ class LicenseSlackTest extends TestCase ); } - /** @dataProvider targets */ + /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { Notification::fake(); From 43cc296582b84b2385c1f8615285074ea8a1139a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:14:35 -0800 Subject: [PATCH 05/33] Consolidate additional tests --- .../Feature/Notifications/AssetSlackTest.php | 110 ------------------ .../Notifications/LicenseSlackTest.php | 109 ----------------- .../SlackNotificationsUponCheckinTest.php | 101 ++++++++++++++++ .../SlackNotificationsUponCheckoutTest.php | 101 ++++++++++++++++ 4 files changed, 202 insertions(+), 219 deletions(-) delete mode 100644 tests/Feature/Notifications/AssetSlackTest.php delete mode 100644 tests/Feature/Notifications/LicenseSlackTest.php diff --git a/tests/Feature/Notifications/AssetSlackTest.php b/tests/Feature/Notifications/AssetSlackTest.php deleted file mode 100644 index c6d03df63..000000000 --- a/tests/Feature/Notifications/AssetSlackTest.php +++ /dev/null @@ -1,110 +0,0 @@ - [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 8ed38c278..000000000 --- a/tests/Feature/Notifications/LicenseSlackTest.php +++ /dev/null @@ -1,109 +0,0 @@ - [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 282417d82..2cf697e93 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 3992a6c51..aeee70c9b 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); + } } From 2ea883aa1575bb09951f12b4c9ff1a82c70b9ea2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:23:30 -0800 Subject: [PATCH 06/33] Move Notification::fake() to setUp method --- .../SlackNotificationsUponCheckinTest.php | 21 ++++++---------- .../SlackNotificationsUponCheckoutTest.php | 25 ++++++------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index 2cf697e93..feb4cd26d 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -22,6 +22,13 @@ class SlackNotificationsUponCheckinTest extends TestCase { use InteractsWithSettings; + protected function setUp(): void + { + parent::setUp(); + + Notification::fake(); + } + public function assetCheckoutTargets(): array { return [ @@ -41,8 +48,6 @@ class SlackNotificationsUponCheckinTest extends TestCase public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled() { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedIn( @@ -63,8 +68,6 @@ class SlackNotificationsUponCheckinTest extends TestCase public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled() { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( @@ -80,8 +83,6 @@ class SlackNotificationsUponCheckinTest extends TestCase /** @dataProvider assetCheckoutTargets */ public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedIn( @@ -103,8 +104,6 @@ class SlackNotificationsUponCheckinTest extends TestCase /** @dataProvider assetCheckoutTargets */ public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( @@ -119,8 +118,6 @@ class SlackNotificationsUponCheckinTest extends TestCase public function testComponentCheckinDoesNotSendSlackNotification() { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedIn( @@ -146,8 +143,6 @@ class SlackNotificationsUponCheckinTest extends TestCase /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedIn( @@ -169,8 +164,6 @@ class SlackNotificationsUponCheckinTest extends TestCase /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedIn( diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index aeee70c9b..4f8b1da22 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -24,6 +24,13 @@ class SlackNotificationsUponCheckoutTest extends TestCase { use InteractsWithSettings; + protected function setUp(): void + { + parent::setUp(); + + Notification::fake(); + } + public function assetCheckoutTargets(): array { return [ @@ -43,8 +50,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled() { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -65,8 +70,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -82,8 +85,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase /** @dataProvider assetCheckoutTargets */ public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -105,8 +106,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase /** @dataProvider assetCheckoutTargets */ public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -121,8 +120,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase public function testComponentCheckoutDoesNotSendSlackNotification() { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -137,8 +134,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled() { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -159,8 +154,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -176,8 +169,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { - Notification::fake(); - $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( @@ -199,8 +190,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { - Notification::fake(); - $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( From bf32ab177ff68b2bbe4acbbabc923fe7ed850c76 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:37:07 -0800 Subject: [PATCH 07/33] Improve readability by extracting fireCheckInEvent method --- .../SlackNotificationsUponCheckinTest.php | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index feb4cd26d..e73d62a1c 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -13,6 +13,7 @@ use App\Models\User; use App\Notifications\CheckinAccessoryNotification; use App\Notifications\CheckinAssetNotification; use App\Notifications\CheckinLicenseSeatNotification; +use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; @@ -50,12 +51,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -70,12 +69,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class); } @@ -85,12 +82,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -106,12 +101,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class); } @@ -120,12 +113,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Component::factory()->ramCrucial8()->create(), Asset::factory()->laptopMbp()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNothingSent(); } @@ -145,12 +136,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( LicenseSeat::factory()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -166,13 +155,21 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( LicenseSeat::factory()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class); } + + private function fireCheckInEvent(Model $checkoutable, Model $target) + { + event(new CheckoutableCheckedIn( + $checkoutable, + $target, + User::factory()->superuser()->create(), + '' + )); + } } From bd4d3aa52bae2d4f92e60abfbf12b459b8c92f97 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:44:19 -0800 Subject: [PATCH 08/33] Improve readability by extracting additional helpers --- .../SlackNotificationsUponCheckinTest.php | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index e73d62a1c..8d8bf3a6e 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -56,13 +56,7 @@ class SlackNotificationsUponCheckinTest extends TestCase User::factory()->create(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckinAccessoryNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckinAccessoryNotification::class); } public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled() @@ -74,7 +68,7 @@ class SlackNotificationsUponCheckinTest extends TestCase User::factory()->create(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class); + $this->assertNoSlackNotificationSent(CheckinAccessoryNotification::class); } /** @dataProvider assetCheckoutTargets */ @@ -87,13 +81,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $checkoutTarget(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckinAssetNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckinAssetNotification::class); } /** @dataProvider assetCheckoutTargets */ @@ -106,7 +94,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $checkoutTarget(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class); + $this->assertNoSlackNotificationSent(CheckinAssetNotification::class); } public function testComponentCheckinDoesNotSendSlackNotification() @@ -141,13 +129,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $checkoutTarget(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckinLicenseSeatNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckinLicenseSeatNotification::class); } /** @dataProvider licenseCheckoutTargets */ @@ -160,7 +142,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $checkoutTarget(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class); + $this->assertNoSlackNotificationSent(CheckinLicenseSeatNotification::class); } private function fireCheckInEvent(Model $checkoutable, Model $target) @@ -172,4 +154,20 @@ class SlackNotificationsUponCheckinTest extends TestCase '' )); } + + private function assertSlackNotificationSent(string $notificationClass) + { + Notification::assertSentTo( + new AnonymousNotifiable, + $notificationClass, + function ($notification, $channels, $notifiable) { + return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; + } + ); + } + + private function assertNoSlackNotificationSent(string $notificationClass) + { + Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class); + } } From 9a93ad2e06efc2020224c50b15df63dd632303f8 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:46:27 -0800 Subject: [PATCH 09/33] Remove unneeded factory state --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index 8d8bf3a6e..be6b9f811 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -52,7 +52,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckInEvent( - Accessory::factory()->appleBtKeyboard()->create(), + Accessory::factory()->create(), User::factory()->create(), ); @@ -64,7 +64,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->settings->disableSlackWebhook(); $this->fireCheckInEvent( - Accessory::factory()->appleBtKeyboard()->create(), + Accessory::factory()->create(), User::factory()->create(), ); From 15b8140bffc5dbd113ebaac26bcf74f0da1a448a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:48:17 -0800 Subject: [PATCH 10/33] Fix test helper --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index be6b9f811..c03d9a30a 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -168,6 +168,6 @@ class SlackNotificationsUponCheckinTest extends TestCase private function assertNoSlackNotificationSent(string $notificationClass) { - Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class); + Notification::assertNotSentTo(new AnonymousNotifiable, $notificationClass); } } From cd579a04dd3add300e5edcd7c4e26ffebe5b4e6e Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:52:18 -0800 Subject: [PATCH 11/33] Improve readability by extracting fireCheckOutEvent method --- .../SlackNotificationsUponCheckoutTest.php | 65 +++++++++---------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index 4f8b1da22..7e3097f6d 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -15,6 +15,7 @@ use App\Notifications\CheckoutAccessoryNotification; use App\Notifications\CheckoutAssetNotification; use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutLicenseSeatNotification; +use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; @@ -52,12 +53,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -72,12 +71,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class); } @@ -87,12 +84,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -108,12 +103,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); } @@ -122,12 +115,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Component::factory()->ramCrucial8()->create(), Asset::factory()->laptopMbp()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNothingSent(); } @@ -136,12 +127,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Consumable::factory()->cardstock()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -156,12 +145,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( Consumable::factory()->cardstock()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class); } @@ -171,12 +158,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( LicenseSeat::factory()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -192,13 +177,21 @@ class SlackNotificationsUponCheckoutTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedOut( + $this->fireCheckOutEvent( LicenseSeat::factory()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class); } + + private function fireCheckOutEvent(Model $checkoutable, Model $target) + { + event(new CheckoutableCheckedOut( + $checkoutable, + $target, + User::factory()->superuser()->create(), + '', + )); + } } From d20844fefa68cf324dab9579949e886552b7ce4f Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:57:12 -0800 Subject: [PATCH 12/33] Improve readability by extracting additional helpers --- .../SlackNotificationsUponCheckoutTest.php | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index 7e3097f6d..739c7e96b 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -58,13 +58,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase User::factory()->create(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckoutAccessoryNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckoutAccessoryNotification::class); } public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() @@ -76,7 +70,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase User::factory()->create(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class); + $this->assertNoSlackNotificationSent(CheckoutAccessoryNotification::class); } /** @dataProvider assetCheckoutTargets */ @@ -89,13 +83,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $checkoutTarget(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckoutAssetNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckoutAssetNotification::class); } /** @dataProvider assetCheckoutTargets */ @@ -108,7 +96,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $checkoutTarget(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); + $this->assertNoSlackNotificationSent(CheckoutAssetNotification::class); } public function testComponentCheckoutDoesNotSendSlackNotification() @@ -132,13 +120,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase User::factory()->create(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckoutConsumableNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckoutConsumableNotification::class); } public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() @@ -150,7 +132,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase User::factory()->create(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class); + $this->assertNoSlackNotificationSent(CheckoutConsumableNotification::class); } /** @dataProvider licenseCheckoutTargets */ @@ -163,13 +145,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $checkoutTarget(), ); - Notification::assertSentTo( - new AnonymousNotifiable, - CheckoutLicenseSeatNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); + $this->assertSlackNotificationSent(CheckoutLicenseSeatNotification::class); } /** @dataProvider licenseCheckoutTargets */ @@ -182,7 +158,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $checkoutTarget(), ); - Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class); + $this->assertNoSlackNotificationSent(CheckoutLicenseSeatNotification::class); } private function fireCheckOutEvent(Model $checkoutable, Model $target) @@ -194,4 +170,20 @@ class SlackNotificationsUponCheckoutTest extends TestCase '', )); } + + private function assertSlackNotificationSent(string $notificationClass) + { + Notification::assertSentTo( + new AnonymousNotifiable, + $notificationClass, + function ($notification, $channels, $notifiable) { + return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; + } + ); + } + + private function assertNoSlackNotificationSent(string $notificationClass) + { + Notification::assertNotSentTo(new AnonymousNotifiable, $notificationClass); + } } From 8978dff054ac0d32913b5d7e73249d8016785579 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 18:01:08 -0800 Subject: [PATCH 13/33] Consolidate helpers into trait --- .../SlackNotificationsUponCheckinTest.php | 20 ++------------ .../SlackNotificationsUponCheckoutTest.php | 20 ++------------ .../AssertsAgainstSlackNotifications.php | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 36 deletions(-) create mode 100644 tests/Support/AssertsAgainstSlackNotifications.php diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index c03d9a30a..372f212c0 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -8,19 +8,19 @@ 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\Database\Eloquent\Model; -use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; +use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\InteractsWithSettings; use Tests\TestCase; class SlackNotificationsUponCheckinTest extends TestCase { + use AssertsAgainstSlackNotifications; use InteractsWithSettings; protected function setUp(): void @@ -154,20 +154,4 @@ class SlackNotificationsUponCheckinTest extends TestCase '' )); } - - private function assertSlackNotificationSent(string $notificationClass) - { - Notification::assertSentTo( - new AnonymousNotifiable, - $notificationClass, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); - } - - private function assertNoSlackNotificationSent(string $notificationClass) - { - Notification::assertNotSentTo(new AnonymousNotifiable, $notificationClass); - } } diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index 739c7e96b..58570f90e 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -9,20 +9,20 @@ 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\Database\Eloquent\Model; -use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; +use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\InteractsWithSettings; use Tests\TestCase; class SlackNotificationsUponCheckoutTest extends TestCase { + use AssertsAgainstSlackNotifications; use InteractsWithSettings; protected function setUp(): void @@ -170,20 +170,4 @@ class SlackNotificationsUponCheckoutTest extends TestCase '', )); } - - private function assertSlackNotificationSent(string $notificationClass) - { - Notification::assertSentTo( - new AnonymousNotifiable, - $notificationClass, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); - } - - private function assertNoSlackNotificationSent(string $notificationClass) - { - Notification::assertNotSentTo(new AnonymousNotifiable, $notificationClass); - } } diff --git a/tests/Support/AssertsAgainstSlackNotifications.php b/tests/Support/AssertsAgainstSlackNotifications.php new file mode 100644 index 000000000..11e6beea2 --- /dev/null +++ b/tests/Support/AssertsAgainstSlackNotifications.php @@ -0,0 +1,26 @@ +routes['slack'] === Setting::getSettings()->webhook_endpoint; + } + ); + } + + public function assertNoSlackNotificationSent(string $notificationClass) + { + Notification::assertNotSentTo(new AnonymousNotifiable, $notificationClass); + } +} From 03b7891edc6d9af615240f6405c6248970280613 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 18:03:53 -0800 Subject: [PATCH 14/33] Remove unneeded factory states --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 6 +++--- .../SlackNotificationsUponCheckoutTest.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index 372f212c0..b352574ff 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -77,7 +77,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckInEvent( - Asset::factory()->laptopMbp()->create(), + Asset::factory()->create(), $checkoutTarget(), ); @@ -90,7 +90,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->settings->disableSlackWebhook(); $this->fireCheckInEvent( - Asset::factory()->laptopMbp()->create(), + Asset::factory()->create(), $checkoutTarget(), ); @@ -102,7 +102,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckInEvent( - Component::factory()->ramCrucial8()->create(), + Component::factory()->create(), Asset::factory()->laptopMbp()->create(), ); diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index 58570f90e..91d291784 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -54,7 +54,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( - Accessory::factory()->appleBtKeyboard()->create(), + Accessory::factory()->create(), User::factory()->create(), ); @@ -66,7 +66,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( - Accessory::factory()->appleBtKeyboard()->create(), + Accessory::factory()->create(), User::factory()->create(), ); @@ -79,7 +79,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( - Asset::factory()->laptopMbp()->create(), + Asset::factory()->create(), $checkoutTarget(), ); @@ -92,7 +92,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( - Asset::factory()->laptopMbp()->create(), + Asset::factory()->create(), $checkoutTarget(), ); @@ -104,7 +104,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( - Component::factory()->ramCrucial8()->create(), + Component::factory()->create(), Asset::factory()->laptopMbp()->create(), ); @@ -116,7 +116,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( - Consumable::factory()->cardstock()->create(), + Consumable::factory()->create(), User::factory()->create(), ); @@ -128,7 +128,7 @@ class SlackNotificationsUponCheckoutTest extends TestCase $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( - Consumable::factory()->cardstock()->create(), + Consumable::factory()->create(), User::factory()->create(), ); From 551354b1bbc91737d12f40249723e39369ead2ae Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 18:05:18 -0800 Subject: [PATCH 15/33] Add group annotation for tests --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 3 +++ .../Webhooks/SlackNotificationsUponCheckoutTest.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index b352574ff..324beda75 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -18,6 +18,9 @@ use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\InteractsWithSettings; use Tests\TestCase; +/** + * @group notifications + */ class SlackNotificationsUponCheckinTest extends TestCase { use AssertsAgainstSlackNotifications; diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index 91d291784..fd628d35e 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -20,6 +20,9 @@ use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\InteractsWithSettings; use Tests\TestCase; +/** + * @group notifications + */ class SlackNotificationsUponCheckoutTest extends TestCase { use AssertsAgainstSlackNotifications; From a2e70dd6b2509476b68ff0d518f33bb05f7de37e Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Fri, 8 Mar 2024 14:04:21 +0000 Subject: [PATCH 16/33] Fix [sc-25008] - correct and improve legacy language warnings The legacy language warning was misfiring when a user's language didn't match the APP_LOCALE from .env. Additionally, we weren't properly warning when the legacy-language came from Settings or from the user themselves. Both of which should be impossible but still probably not a bad idea to warn on it, anyways --- app/Http/Middleware/CheckLocale.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Http/Middleware/CheckLocale.php b/app/Http/Middleware/CheckLocale.php index 3c525d172..d0dbcffaa 100644 --- a/app/Http/Middleware/CheckLocale.php +++ b/app/Http/Middleware/CheckLocale.php @@ -8,6 +8,12 @@ use \App\Helpers\Helper; class CheckLocale { + private function warn_legacy_locale($language, $source) + { + if ($language != Helper::mapLegacyLocale($language)) { + \Log::warning("$source $language and should be updated to be ".Helper::mapLegacyLocale($language)); + } + } /** * Handle the locale for the user, default to settings otherwise. * @@ -22,24 +28,23 @@ class CheckLocale // Default app settings from config $language = config('app.locale'); + $this->warn_legacy_locale($language, "APP_LOCALE in .env is set to"); if ($settings = Setting::getSettings()) { // User's preference if (($request->user()) && ($request->user()->locale)) { $language = $request->user()->locale; + $this->warn_legacy_locale($language, "username ".$request->user()->username." (".$request->user()->id.") has a language"); // App setting preference } elseif ($settings->locale != '') { $language = $settings->locale; + $this->warn_legacy_locale($language, "App Settings is set to"); } } - - if (config('app.locale') != Helper::mapLegacyLocale($language)) { - \Log::warning('Your current APP_LOCALE in your .env is set to "'.config('app.locale').'" and should be updated to be "'.Helper::mapLegacyLocale($language).'" in '.base_path().'/.env. Translations may display unexpectedly until this is updated.'); - } - + \App::setLocale(Helper::mapLegacyLocale($language)); return $next($request); } From 9359809b4fd2f186180083b32b2893c8cd4ab924 Mon Sep 17 00:00:00 2001 From: MrM <11910225+mauro-miatello@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:09:46 +0100 Subject: [PATCH 17/33] Hide / Show encrypted values in web ui added a span element to hide encrypted values --- resources/views/hardware/view.blade.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 72a260394..a32503d7e 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -410,12 +410,13 @@
@if (($field->field_encrypted=='1') && ($asset->{$field->db_column_name()}!='')) - + @endif @if ($field->isFieldDecryptable($asset->{$field->db_column_name()} )) @can('assets.view.encrypted_custom_fields') - + ******** + @if (($field->format=='URL') && ($asset->{$field->db_column_name()}!='')) {{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }} @elseif (($field->format=='DATE') && ($asset->{$field->db_column_name()}!='')) @@ -427,7 +428,7 @@ - @else + @else {{ strtoupper(trans('admin/custom_fields/general.encrypted')) }} @endcan From 8abd359b5b5ed69949beea2fc38f4b0d3d085b58 Mon Sep 17 00:00:00 2001 From: MrM <11910225+mauro-miatello@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:18:54 +0100 Subject: [PATCH 18/33] Script to hide / show encrypted values in web ui added a function to show/hide encrypted values with a simple trick because ClipboardJS can't copy display:none element's value --- resources/views/layouts/default.blade.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 95a82ce41..216632ccf 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -964,8 +964,7 @@ var clickedElement = $(e.trigger); // Get the target element selector from data attribute var targetSelector = clickedElement.data('data-clipboard-target'); - // Find the target element - var targetEl = $(targetSelector); + // Show the alert that the content was copied clickedElement.tooltip('hide').attr('data-original-title', '{{ trans('general.copied') }}').tooltip('show'); }); @@ -979,6 +978,23 @@ }); + function showHideEncValue(e) { + // Use element id to find the text element to hide / show + var targetElement = e.id+"-to-show"; + var hiddenElement = e.id+"-to-hide"; + if($(e).hasClass('fa-lock')) { + $(e).removeClass('fa-lock').addClass('fa-unlock'); + // Show the encrypted custom value and hide the element with asterisks + document.getElementById(targetElement).style.fontSize = "100%"; + document.getElementById(hiddenElement).style.display = "none"; + } else { + $(e).removeClass('fa-unlock').addClass('fa-lock'); + // ClipboardJS can't copy display:none elements so use a trick to hide the value + document.getElementById(targetElement).style.fontSize = "0px"; + document.getElementById(hiddenElement).style.display = ""; + } + } + $(function () { // Invoke Bootstrap 3's tooltip From 717b26c834eb3ca9832094f671e297d87698bb87 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 11 Mar 2024 15:53:59 -0700 Subject: [PATCH 19/33] fixes z-index of date-picker --- resources/assets/less/overrides.less | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/assets/less/overrides.less b/resources/assets/less/overrides.less index 5e1695342..f651826dd 100644 --- a/resources/assets/less/overrides.less +++ b/resources/assets/less/overrides.less @@ -887,4 +887,7 @@ input[type="radio"]:checked::before { .separator:not(:empty)::after { margin-left: .25em; +} +.datepicker.dropdown-menu { + z-index: 1030 !important; } \ No newline at end of file From f07b0b6bd7a884c32017103ca44c428d4f021b5c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 11 Mar 2024 15:54:59 -0700 Subject: [PATCH 20/33] removed important --- resources/assets/less/overrides.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/less/overrides.less b/resources/assets/less/overrides.less index f651826dd..8ac35a797 100644 --- a/resources/assets/less/overrides.less +++ b/resources/assets/less/overrides.less @@ -889,5 +889,5 @@ input[type="radio"]:checked::before { margin-left: .25em; } .datepicker.dropdown-menu { - z-index: 1030 !important; + z-index: 1030; } \ No newline at end of file From bf0bd06f206ad182fcc91f903be3378deb7e4e2c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 11 Mar 2024 15:56:53 -0700 Subject: [PATCH 21/33] put important back --- resources/assets/less/overrides.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/less/overrides.less b/resources/assets/less/overrides.less index 8ac35a797..f651826dd 100644 --- a/resources/assets/less/overrides.less +++ b/resources/assets/less/overrides.less @@ -889,5 +889,5 @@ input[type="radio"]:checked::before { margin-left: .25em; } .datepicker.dropdown-menu { - z-index: 1030; + z-index: 1030 !important; } \ No newline at end of file From 592385cb07f5f6af11efc97eff5b9de179fda8f5 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 13 Mar 2024 11:58:03 -0700 Subject: [PATCH 22/33] Remove mediconesystems/livewire-datatables package --- composer.json | 1 - composer.lock | 542 +------------------------------------------------- 2 files changed, 1 insertion(+), 542 deletions(-) diff --git a/composer.json b/composer.json index 0ff2cd999..5fff16c1a 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,6 @@ "league/flysystem-aws-s3-v3": "^1.0", "league/flysystem-cached-adapter": "^1.1", "livewire/livewire": "^2.4", - "mediconesystems/livewire-datatables": "^0.5.0", "neitanod/forceutf8": "^2.0", "nesbot/carbon": "^2.32", "nunomaduro/collision": "^5.4", diff --git a/composer.lock b/composer.lock index 9798d74e0..127254236 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9cca85cd0074df9154765b1ab52f83fa", + "content-hash": "0536c48de3ba12fdeb01bac07fcd7172", "packages": [ { "name": "alek13/slack", @@ -2165,57 +2165,6 @@ }, "time": "2019-12-30T22:54:17+00:00" }, - { - "name": "ezyang/htmlpurifier", - "version": "v4.14.0", - "source": { - "type": "git", - "url": "https://github.com/ezyang/htmlpurifier.git", - "reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/12ab42bd6e742c70c0a52f7b82477fcd44e64b75", - "reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75", - "shasum": "" - }, - "require": { - "php": ">=5.2" - }, - "type": "library", - "autoload": { - "files": [ - "library/HTMLPurifier.composer.php" - ], - "psr-0": { - "HTMLPurifier": "library/" - }, - "exclude-from-classmap": [ - "/library/HTMLPurifier/Language/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-2.1-or-later" - ], - "authors": [ - { - "name": "Edward Z. Yang", - "email": "admin@htmlpurifier.org", - "homepage": "http://ezyang.com" - } - ], - "description": "Standards compliant HTML filter written in PHP", - "homepage": "http://htmlpurifier.org/", - "keywords": [ - "html" - ], - "support": { - "issues": "https://github.com/ezyang/htmlpurifier/issues", - "source": "https://github.com/ezyang/htmlpurifier/tree/v4.14.0" - }, - "time": "2021-12-25T01:21:49+00:00" - }, { "name": "facade/flare-client-php", "version": "1.9.1", @@ -5133,268 +5082,6 @@ ], "time": "2022-06-19T02:54:20+00:00" }, - { - "name": "maatwebsite/excel", - "version": "3.1.40", - "source": { - "type": "git", - "url": "https://github.com/SpartnerNL/Laravel-Excel.git", - "reference": "8a54972e3d616c74687c3cbff15765555761885c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/8a54972e3d616c74687c3cbff15765555761885c", - "reference": "8a54972e3d616c74687c3cbff15765555761885c", - "shasum": "" - }, - "require": { - "ext-json": "*", - "illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0", - "php": "^7.0|^8.0", - "phpoffice/phpspreadsheet": "^1.18" - }, - "require-dev": { - "orchestra/testbench": "^6.0|^7.0", - "predis/predis": "^1.1" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Maatwebsite\\Excel\\ExcelServiceProvider" - ], - "aliases": { - "Excel": "Maatwebsite\\Excel\\Facades\\Excel" - } - } - }, - "autoload": { - "psr-4": { - "Maatwebsite\\Excel\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Patrick Brouwers", - "email": "patrick@spartner.nl" - } - ], - "description": "Supercharged Excel exports and imports in Laravel", - "keywords": [ - "PHPExcel", - "batch", - "csv", - "excel", - "export", - "import", - "laravel", - "php", - "phpspreadsheet" - ], - "support": { - "issues": "https://github.com/SpartnerNL/Laravel-Excel/issues", - "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.40" - }, - "funding": [ - { - "url": "https://laravel-excel.com/commercial-support", - "type": "custom" - }, - { - "url": "https://github.com/patrickbrouwers", - "type": "github" - } - ], - "time": "2022-05-02T13:50:01+00:00" - }, - { - "name": "maennchen/zipstream-php", - "version": "2.2.1", - "source": { - "type": "git", - "url": "https://github.com/maennchen/ZipStream-PHP.git", - "reference": "211e9ba1530ea5260b45d90c9ea252f56ec52729" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/211e9ba1530ea5260b45d90c9ea252f56ec52729", - "reference": "211e9ba1530ea5260b45d90c9ea252f56ec52729", - "shasum": "" - }, - "require": { - "myclabs/php-enum": "^1.5", - "php": "^7.4 || ^8.0", - "psr/http-message": "^1.0", - "symfony/polyfill-mbstring": "^1.0" - }, - "require-dev": { - "ext-zip": "*", - "guzzlehttp/guzzle": "^6.5.3 || ^7.2.0", - "mikey179/vfsstream": "^1.6", - "php-coveralls/php-coveralls": "^2.4", - "phpunit/phpunit": "^8.5.8 || ^9.4.2", - "vimeo/psalm": "^4.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "ZipStream\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Paul Duncan", - "email": "pabs@pablotron.org" - }, - { - "name": "Jonatan Männchen", - "email": "jonatan@maennchen.ch" - }, - { - "name": "Jesse Donat", - "email": "donatj@gmail.com" - }, - { - "name": "András Kolesár", - "email": "kolesar@kolesar.hu" - } - ], - "description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.", - "keywords": [ - "stream", - "zip" - ], - "support": { - "issues": "https://github.com/maennchen/ZipStream-PHP/issues", - "source": "https://github.com/maennchen/ZipStream-PHP/tree/2.2.1" - }, - "funding": [ - { - "url": "https://github.com/maennchen", - "type": "github" - }, - { - "url": "https://opencollective.com/zipstream", - "type": "open_collective" - } - ], - "time": "2022-05-18T15:52:06+00:00" - }, - { - "name": "markbaker/complex", - "version": "3.0.1", - "source": { - "type": "git", - "url": "https://github.com/MarkBaker/PHPComplex.git", - "reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/ab8bc271e404909db09ff2d5ffa1e538085c0f22", - "reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "phpcompatibility/php-compatibility": "^9.0", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.3", - "squizlabs/php_codesniffer": "^3.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "Complex\\": "classes/src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mark Baker", - "email": "mark@lange.demon.co.uk" - } - ], - "description": "PHP Class for working with complex numbers", - "homepage": "https://github.com/MarkBaker/PHPComplex", - "keywords": [ - "complex", - "mathematics" - ], - "support": { - "issues": "https://github.com/MarkBaker/PHPComplex/issues", - "source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.1" - }, - "time": "2021-06-29T15:32:53+00:00" - }, - { - "name": "markbaker/matrix", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/MarkBaker/PHPMatrix.git", - "reference": "c66aefcafb4f6c269510e9ac46b82619a904c576" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/c66aefcafb4f6c269510e9ac46b82619a904c576", - "reference": "c66aefcafb4f6c269510e9ac46b82619a904c576", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "phpcompatibility/php-compatibility": "^9.0", - "phpdocumentor/phpdocumentor": "2.*", - "phploc/phploc": "^4.0", - "phpmd/phpmd": "2.*", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.3", - "sebastian/phpcpd": "^4.0", - "squizlabs/php_codesniffer": "^3.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "Matrix\\": "classes/src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mark Baker", - "email": "mark@demon-angel.eu" - } - ], - "description": "PHP Class for working with matrices", - "homepage": "https://github.com/MarkBaker/PHPMatrix", - "keywords": [ - "mathematics", - "matrix", - "vector" - ], - "support": { - "issues": "https://github.com/MarkBaker/PHPMatrix/issues", - "source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.0" - }, - "time": "2021-07-01T19:01:15+00:00" - }, { "name": "masterminds/html5", "version": "2.8.1", @@ -5528,69 +5215,6 @@ }, "time": "2021-12-27T18:49:48+00:00" }, - { - "name": "mediconesystems/livewire-datatables", - "version": "v0.5.4", - "source": { - "type": "git", - "url": "https://github.com/MedicOneSystems/livewire-datatables.git", - "reference": "bf6f24d529208e6bdec58276e92792719c73c827" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/MedicOneSystems/livewire-datatables/zipball/bf6f24d529208e6bdec58276e92792719c73c827", - "reference": "bf6f24d529208e6bdec58276e92792719c73c827", - "shasum": "" - }, - "require": { - "illuminate/support": "^7.0|^8.0", - "livewire/livewire": "^1.2|^2.0", - "maatwebsite/excel": "^3.1", - "php": "^7.2.5|^8.0" - }, - "require-dev": { - "laravel/legacy-factories": "^1.0.4", - "orchestra/testbench": "^4.0|5.0|6.0", - "phpunit/phpunit": "^8.0|9.0" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Mediconesystems\\LivewireDatatables\\LivewireDatatablesServiceProvider" - ], - "aliases": { - "LivewireDatatables": "Mediconesystems\\LivewireDatatables\\LivewireDatatablesFacade" - } - } - }, - "autoload": { - "psr-4": { - "Mediconesystems\\LivewireDatatables\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mark Salmon", - "email": "mark.salmon@mediconesystems.com", - "role": "Developer" - } - ], - "homepage": "https://github.com/mediconesystems/livewire-datatables", - "keywords": [ - "livewire-datatables", - "mediconesystems" - ], - "support": { - "issues": "https://github.com/MedicOneSystems/livewire-datatables/issues", - "source": "https://github.com/MedicOneSystems/livewire-datatables/tree/v0.5.4" - }, - "time": "2021-08-09T20:37:55+00:00" - }, { "name": "monolog/monolog", "version": "2.7.0", @@ -5761,66 +5385,6 @@ }, "time": "2023-08-25T10:54:48+00:00" }, - { - "name": "myclabs/php-enum", - "version": "1.8.3", - "source": { - "type": "git", - "url": "https://github.com/myclabs/php-enum.git", - "reference": "b942d263c641ddb5190929ff840c68f78713e937" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/php-enum/zipball/b942d263c641ddb5190929ff840c68f78713e937", - "reference": "b942d263c641ddb5190929ff840c68f78713e937", - "shasum": "" - }, - "require": { - "ext-json": "*", - "php": "^7.3 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.5", - "squizlabs/php_codesniffer": "1.*", - "vimeo/psalm": "^4.6.2" - }, - "type": "library", - "autoload": { - "psr-4": { - "MyCLabs\\Enum\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP Enum contributors", - "homepage": "https://github.com/myclabs/php-enum/graphs/contributors" - } - ], - "description": "PHP Enum implementation", - "homepage": "http://github.com/myclabs/php-enum", - "keywords": [ - "enum" - ], - "support": { - "issues": "https://github.com/myclabs/php-enum/issues", - "source": "https://github.com/myclabs/php-enum/tree/1.8.3" - }, - "funding": [ - { - "url": "https://github.com/mnapoli", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum", - "type": "tidelift" - } - ], - "time": "2021-07-05T08:18:36+00:00" - }, { "name": "neitanod/forceutf8", "version": "v2.0.4", @@ -6960,110 +6524,6 @@ }, "time": "2022-03-15T21:29:03+00:00" }, - { - "name": "phpoffice/phpspreadsheet", - "version": "1.24.1", - "source": { - "type": "git", - "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", - "reference": "69991111e05fca3ff7398e1e7fca9ebed33efec6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/69991111e05fca3ff7398e1e7fca9ebed33efec6", - "reference": "69991111e05fca3ff7398e1e7fca9ebed33efec6", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "ext-dom": "*", - "ext-fileinfo": "*", - "ext-gd": "*", - "ext-iconv": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-simplexml": "*", - "ext-xml": "*", - "ext-xmlreader": "*", - "ext-xmlwriter": "*", - "ext-zip": "*", - "ext-zlib": "*", - "ezyang/htmlpurifier": "^4.13", - "maennchen/zipstream-php": "^2.1", - "markbaker/complex": "^3.0", - "markbaker/matrix": "^3.0", - "php": "^7.3 || ^8.0", - "psr/http-client": "^1.0", - "psr/http-factory": "^1.0", - "psr/simple-cache": "^1.0 || ^2.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "dev-master", - "dompdf/dompdf": "^1.0 || ^2.0", - "friendsofphp/php-cs-fixer": "^3.2", - "jpgraph/jpgraph": "^4.0", - "mpdf/mpdf": "8.1.1", - "phpcompatibility/php-compatibility": "^9.3", - "phpstan/phpstan": "^1.1", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^8.5 || ^9.0", - "squizlabs/php_codesniffer": "^3.7", - "tecnickcom/tcpdf": "^6.4" - }, - "suggest": { - "dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)", - "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers", - "mpdf/mpdf": "Option for rendering PDF with PDF Writer", - "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)" - }, - "type": "library", - "autoload": { - "psr-4": { - "PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Maarten Balliauw", - "homepage": "https://blog.maartenballiauw.be" - }, - { - "name": "Mark Baker", - "homepage": "https://markbakeruk.net" - }, - { - "name": "Franck Lefevre", - "homepage": "https://rootslabs.net" - }, - { - "name": "Erik Tilt" - }, - { - "name": "Adrien Crivelli" - } - ], - "description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", - "homepage": "https://github.com/PHPOffice/PhpSpreadsheet", - "keywords": [ - "OpenXML", - "excel", - "gnumeric", - "ods", - "php", - "spreadsheet", - "xls", - "xlsx" - ], - "support": { - "issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues", - "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.24.1" - }, - "time": "2022-07-18T19:50:48+00:00" - }, { "name": "phpoption/phpoption", "version": "1.8.1", From 01d5d4c2c8c03283e58ab8f55277d0f0c9edadfd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 13 Mar 2024 16:37:50 -0700 Subject: [PATCH 23/33] Improve data provider name --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index 324beda75..2ccbb47e7 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -33,7 +33,7 @@ class SlackNotificationsUponCheckinTest extends TestCase Notification::fake(); } - public function assetCheckoutTargets(): array + public function assetCheckInTargets(): array { return [ 'Asset checked out to user' => [fn() => User::factory()->create()], @@ -42,7 +42,7 @@ class SlackNotificationsUponCheckinTest extends TestCase ]; } - public function licenseCheckoutTargets(): array + public function licenseCheckInTargets(): array { return [ 'License checked out to user' => [fn() => User::factory()->create()], @@ -74,7 +74,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->assertNoSlackNotificationSent(CheckinAccessoryNotification::class); } - /** @dataProvider assetCheckoutTargets */ + /** @dataProvider assetCheckInTargets */ public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { $this->settings->enableSlackWebhook(); @@ -87,7 +87,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->assertSlackNotificationSent(CheckinAssetNotification::class); } - /** @dataProvider assetCheckoutTargets */ + /** @dataProvider assetCheckInTargets */ public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { $this->settings->disableSlackWebhook(); @@ -122,7 +122,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->markTestIncomplete(); } - /** @dataProvider licenseCheckoutTargets */ + /** @dataProvider licenseCheckInTargets */ public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { $this->settings->enableSlackWebhook(); @@ -135,7 +135,7 @@ class SlackNotificationsUponCheckinTest extends TestCase $this->assertSlackNotificationSent(CheckinLicenseSeatNotification::class); } - /** @dataProvider licenseCheckoutTargets */ + /** @dataProvider licenseCheckInTargets */ public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { $this->settings->disableSlackWebhook(); From 8aed26aab112bcc6401b04a7aba61253de735d48 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 13 Mar 2024 16:56:54 -0700 Subject: [PATCH 24/33] Remove unneeded test cases --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index 2ccbb47e7..5397aae19 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -112,16 +112,6 @@ class SlackNotificationsUponCheckinTest extends TestCase Notification::assertNothingSent(); } - public function testConsumableCheckinSendSlackNotificationWhenSettingEnabled() - { - $this->markTestIncomplete(); - } - - public function testConsumableCheckinDoesNotSendSlackNotificationWhenSettingDisabled() - { - $this->markTestIncomplete(); - } - /** @dataProvider licenseCheckInTargets */ public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { From 4cd4a936d8c28fe4af95f3b732446e0a909eddd2 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 14 Mar 2024 15:43:47 +0000 Subject: [PATCH 25/33] Updated dev assets Signed-off-by: snipe --- public/css/build/app.css | 3 +++ public/css/build/overrides.css | 3 +++ public/css/dist/all.css | 6 ++++++ public/mix-manifest.json | 6 +++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/css/build/app.css b/public/css/build/app.css index 23a455db6..f6e9fd680 100644 --- a/public/css/build/app.css +++ b/public/css/build/app.css @@ -1142,4 +1142,7 @@ input[type="radio"]:checked::before { .separator:not(:empty)::after { margin-left: 0.25em; } +.datepicker.dropdown-menu { + z-index: 1030 !important; +} diff --git a/public/css/build/overrides.css b/public/css/build/overrides.css index 1630ba1df..f32d3051d 100644 --- a/public/css/build/overrides.css +++ b/public/css/build/overrides.css @@ -775,4 +775,7 @@ input[type="radio"]:checked::before { .separator:not(:empty)::after { margin-left: 0.25em; } +.datepicker.dropdown-menu { + z-index: 1030 !important; +} diff --git a/public/css/dist/all.css b/public/css/dist/all.css index a05999fad..e8d849619 100644 --- a/public/css/dist/all.css +++ b/public/css/dist/all.css @@ -22642,6 +22642,9 @@ input[type="radio"]:checked::before { .separator:not(:empty)::after { margin-left: 0.25em; } +.datepicker.dropdown-menu { + z-index: 1030 !important; +} .select2-container { @@ -23903,4 +23906,7 @@ input[type="radio"]:checked::before { .separator:not(:empty)::after { margin-left: 0.25em; } +.datepicker.dropdown-menu { + z-index: 1030 !important; +} diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 468a57769..8fbfa4fbc 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,8 +1,8 @@ { "/js/build/app.js": "/js/build/app.js?id=ea5f3edebafdb29b616d23fa89106080", "/css/dist/skins/skin-blue.css": "/css/dist/skins/skin-blue.css?id=f677207c6cf9678eb539abecb408c374", - "/css/build/overrides.css": "/css/build/overrides.css?id=9a69d65b9f2b35e6d17c6a72e76424d5", - "/css/build/app.css": "/css/build/app.css?id=5a516232bc9f1488514577cf3c8108eb", + "/css/build/overrides.css": "/css/build/overrides.css?id=742bf17cd1ed6feaa90756beeb09d749", + "/css/build/app.css": "/css/build/app.css?id=1e755f4e7a6968ee5d46747a4ffeca47", "/css/build/AdminLTE.css": "/css/build/AdminLTE.css?id=dc383f8560a8d4adb51d44fb4043e03b", "/css/dist/skins/skin-orange.css": "/css/dist/skins/skin-orange.css?id=6f0563e726c2fe4fab4026daaa5bfdf2", "/css/dist/skins/skin-orange-dark.css": "/css/dist/skins/skin-orange-dark.css?id=e6e53eef152bba01a4c666a4d8b01117", @@ -18,7 +18,7 @@ "/css/dist/skins/skin-green.css": "/css/dist/skins/skin-green.css?id=0a82a6ae6bb4e58fe62d162c4fb50397", "/css/dist/skins/skin-contrast.css": "/css/dist/skins/skin-contrast.css?id=da6c7997d9de2f8329142399f0ce50da", "/css/dist/skins/skin-red.css": "/css/dist/skins/skin-red.css?id=44bf834f2110504a793dadec132a5898", - "/css/dist/all.css": "/css/dist/all.css?id=ebd6663d2f61487038c9947111be2c73", + "/css/dist/all.css": "/css/dist/all.css?id=da500d5249cf6336c9f8d6c1969f9180", "/css/dist/signature-pad.css": "/css/dist/signature-pad.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/dist/signature-pad.min.css": "/css/dist/signature-pad.min.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/webfonts/fa-brands-400.ttf": "/css/webfonts/fa-brands-400.ttf?id=69e5d8e4e818f05fd882cceb758d1eba", From 07c5264b4143a9c1b6a8c72976f719bf288c04c0 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 11:17:47 -0700 Subject: [PATCH 26/33] Organize email check in notifications test --- .../Notifications/AssetWebhookTest.php | 163 ------------------ .../EmailNotificationsUponCheckinTest.php | 64 +++++++ 2 files changed, 64 insertions(+), 163 deletions(-) delete mode 100644 tests/Feature/Notifications/AssetWebhookTest.php create mode 100644 tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php diff --git a/tests/Feature/Notifications/AssetWebhookTest.php b/tests/Feature/Notifications/AssetWebhookTest.php deleted file mode 100644 index 95218f98e..000000000 --- a/tests/Feature/Notifications/AssetWebhookTest.php +++ /dev/null @@ -1,163 +0,0 @@ - [fn() => User::factory()->create()], - 'Asset checked out to asset' => [fn() => $this->createAsset()], - 'Asset checked out to location' => [fn() => Location::factory()->create()], - ]; - } - - /** @dataProvider targets */ - public function testAssetCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget) - { - Notification::fake(); - - $this->settings->enableSlackWebhook(); - - event(new CheckoutableCheckedOut( - $this->createAsset(), - $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); - - Notification::assertSentTo( - new AnonymousNotifiable, - CheckoutAssetNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); - } - - /** @dataProvider targets */ - public function testAssetCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget) - { - Notification::fake(); - - $this->settings->disableWebhook(); - - event(new CheckoutableCheckedOut( - $this->createAsset(), - $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); - - Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); - } - - /** @dataProvider targets */ - public function testAssetCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget) - { - Notification::fake(); - - $this->settings->enableSlackWebhook(); - - event(new CheckoutableCheckedIn( - $this->createAsset(), - $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); - - Notification::assertSentTo( - new AnonymousNotifiable, - CheckinAssetNotification::class, - function ($notification, $channels, $notifiable) { - return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; - } - ); - } - - /** @dataProvider targets */ - public function testAssetCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget) - { - Notification::fake(); - - $this->settings->disableWebhook(); - - event(new CheckoutableCheckedIn( - $this->createAsset(), - $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); - - Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class); - } - - public function testCheckInEmailSentToUserIfSettingEnabled() - { - Notification::fake(); - - $user = User::factory()->create(); - $asset = Asset::factory()->assignedToUser($user)->create(); - - $asset->model->category->update(['checkin_email' => true]); - - event(new CheckoutableCheckedIn( - $asset, - $user, - User::factory()->checkinAssets()->create(), - '' - )); - - Notification::assertSentTo( - [$user], - function (CheckinAssetNotification $notification, $channels) { - return in_array('mail', $channels); - }, - ); - } - - public function testCheckInEmailNotSentToUserIfSettingDisabled() - { - Notification::fake(); - - $user = User::factory()->create(); - $asset = Asset::factory()->assignedToUser($user)->create(); - - $asset->model->category->update(['checkin_email' => false]); - - event(new CheckoutableCheckedIn( - $asset, - $user, - User::factory()->checkinAssets()->create(), - '' - )); - - Notification::assertNotSentTo( - [$user], - function (CheckinAssetNotification $notification, $channels) { - return in_array('mail', $channels); - } - ); - } - - private function createAsset() - { - return Asset::factory()->laptopMbp()->create(); - } -} diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php new file mode 100644 index 000000000..1892e2cdc --- /dev/null +++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php @@ -0,0 +1,64 @@ +create(); + $asset = Asset::factory()->assignedToUser($user)->create(); + + $asset->model->category->update(['checkin_email' => true]); + + event(new CheckoutableCheckedIn( + $asset, + $user, + User::factory()->checkinAssets()->create(), + '' + )); + + Notification::assertSentTo( + [$user], + function (CheckinAssetNotification $notification, $channels) { + return in_array('mail', $channels); + }, + ); + } + + public function testCheckInEmailNotSentToUserIfSettingDisabled() + { + Notification::fake(); + + $user = User::factory()->create(); + $asset = Asset::factory()->assignedToUser($user)->create(); + + $asset->model->category->update(['checkin_email' => false]); + + event(new CheckoutableCheckedIn( + $asset, + $user, + User::factory()->checkinAssets()->create(), + '' + )); + + Notification::assertNotSentTo( + [$user], + function (CheckinAssetNotification $notification, $channels) { + return in_array('mail', $channels); + } + ); + } +} From 02f6aa6161c116576519a562c70023969792dfab Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 11:19:36 -0700 Subject: [PATCH 27/33] Add group tag for new test case --- .../Notifications/Email/EmailNotificationsUponCheckinTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php index 1892e2cdc..35345fac2 100644 --- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php @@ -10,6 +10,9 @@ use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; use Tests\TestCase; +/** + * @group notifications + */ class EmailNotificationsUponCheckinTest extends TestCase { use InteractsWithSettings; From dbc79655b00719d5ee178ca5cd9158695945e6d3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 12:02:56 -0700 Subject: [PATCH 28/33] Cleanup --- .../EmailNotificationsUponCheckinTest.php | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php index 35345fac2..dbe79c572 100644 --- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php @@ -17,24 +17,24 @@ class EmailNotificationsUponCheckinTest extends TestCase { use InteractsWithSettings; + protected function setUp(): void + { + parent::setUp(); + + Notification::fake(); + } + public function testCheckInEmailSentToUserIfSettingEnabled() { - Notification::fake(); - $user = User::factory()->create(); $asset = Asset::factory()->assignedToUser($user)->create(); $asset->model->category->update(['checkin_email' => true]); - event(new CheckoutableCheckedIn( - $asset, - $user, - User::factory()->checkinAssets()->create(), - '' - )); + $this->fireCheckInEvent($asset, $user); Notification::assertSentTo( - [$user], + $user, function (CheckinAssetNotification $notification, $channels) { return in_array('mail', $channels); }, @@ -43,25 +43,28 @@ class EmailNotificationsUponCheckinTest extends TestCase public function testCheckInEmailNotSentToUserIfSettingDisabled() { - Notification::fake(); - $user = User::factory()->create(); $asset = Asset::factory()->assignedToUser($user)->create(); $asset->model->category->update(['checkin_email' => false]); + $this->fireCheckInEvent($asset, $user); + + Notification::assertNotSentTo( + $user, + function (CheckinAssetNotification $notification, $channels) { + return in_array('mail', $channels); + } + ); + } + + private function fireCheckInEvent($asset, $user): void + { event(new CheckoutableCheckedIn( $asset, $user, User::factory()->checkinAssets()->create(), '' )); - - Notification::assertNotSentTo( - [$user], - function (CheckinAssetNotification $notification, $channels) { - return in_array('mail', $channels); - } - ); } } From 485f11c9455ba6345c785dac691e7d16298baaa1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 12:56:49 -0700 Subject: [PATCH 29/33] Move trait usage to parent TestCase --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 2 -- .../Webhooks/SlackNotificationsUponCheckoutTest.php | 2 -- tests/TestCase.php | 2 ++ 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index 5397aae19..b6bb7801a 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -14,7 +14,6 @@ use App\Notifications\CheckinAssetNotification; use App\Notifications\CheckinLicenseSeatNotification; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Notification; -use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\InteractsWithSettings; use Tests\TestCase; @@ -23,7 +22,6 @@ use Tests\TestCase; */ class SlackNotificationsUponCheckinTest extends TestCase { - use AssertsAgainstSlackNotifications; use InteractsWithSettings; protected function setUp(): void diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index fd628d35e..550f7c5b1 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -16,7 +16,6 @@ use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutLicenseSeatNotification; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Notification; -use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\InteractsWithSettings; use Tests\TestCase; @@ -25,7 +24,6 @@ use Tests\TestCase; */ class SlackNotificationsUponCheckoutTest extends TestCase { - use AssertsAgainstSlackNotifications; use InteractsWithSettings; protected function setUp(): void diff --git a/tests/TestCase.php b/tests/TestCase.php index 03f273ad6..535f9a3e2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,12 +6,14 @@ use App\Http\Middleware\SecurityHeaders; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use RuntimeException; +use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\CustomTestMacros; use Tests\Support\InteractsWithAuthentication; use Tests\Support\InteractsWithSettings; abstract class TestCase extends BaseTestCase { + use AssertsAgainstSlackNotifications; use CreatesApplication; use CustomTestMacros; use InteractsWithAuthentication; From 451281d8339d8e2495fae9ed83d411e1f68bc392 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 13:11:27 -0700 Subject: [PATCH 30/33] Delete test cases with only commented code --- tests/Unit/ImporterTest.php | 739 --------------------------------- tests/Unit/PermissionsTest.php | 510 ----------------------- 2 files changed, 1249 deletions(-) delete mode 100644 tests/Unit/ImporterTest.php delete mode 100644 tests/Unit/PermissionsTest.php diff --git a/tests/Unit/ImporterTest.php b/tests/Unit/ImporterTest.php deleted file mode 100644 index b3d5da8b3..000000000 --- a/tests/Unit/ImporterTest.php +++ /dev/null @@ -1,739 +0,0 @@ -signIn(); -// $csv = <<<'EOT' -// Full Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier,Weight -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan,35 -// EOT; - -// $this->initializeCustomFields(); -// $this->import(new AssetImporter($csv)); - -// $this->tester->seeRecord('users', [ -// 'first_name' => 'Bonnie', -// 'last_name' => 'Nelson', -// 'email' => 'bnelson0@cdbaby.com', -// ]); -// $this->tester->seeRecord('categories', [ -// 'name' => 'quam', -// ]); - -// $this->tester->seeRecord('models', [ -// 'name' => 'massa id', -// 'model_number' => 6377018600094472, -// ]); - -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Linkbridge', -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'Daping', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Alpha', -// ]); - -// $this->tester->seeRecord('status_labels', [ -// 'name' => 'Undeployable', -// ]); - -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Blogspan', -// ]); - -// $this->tester->seeRecord('assets', [ -// 'name' => 'eget nunc donec quis', -// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', -// 'asset_tag' => '970882174-8', -// 'notes' => 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', -// 'purchase_date' => '2016-04-05 00:00:01', -// 'purchase_cost' => 133289.59, 'warranty_months' => 14, -// '_snipeit_weight_2' => 35, -// ]); -// } - -// public function testImportCheckoutToLocation() -// { -// $this->signIn(); - -// // Testing in order: -// // * Asset to user, no checkout type defined (default to user). -// // * Asset to user, explicit user checkout type (Checkout to user) -// // * Asset to location, location does not exist to begin with -// // * Asset to preexisting location. -// $csv = <<<'EOT' -// Full Name,Email,Username,Checkout Location,Checkout Type,item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier,Weight -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,,,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan,35 -// Mildred Gibson,mgibson2@wiley.com,mgibson2,,user,morbi quis tortor id,nunc nisl duis,convallis tortor risus,Lajo,374622546776765,2837ab20-8f0d-4935-8a52-226392f2b1b0,710141467-2,Shekou,In congue. Etiam justo. Etiam pretium iaculis justo.,2015-08-09,233.57,Konklab,Lost,,, -// ,,,Planet Earth,location,dictumst maecenas ut,sem praesent,accumsan felis,Layo,30052522651756,4751495c-cee0-4961-b788-94a545b5643e,998233705-X,Dante Delgado,,2016-04-16,261.79,,Archived,15,Ntag, -// ,,,Daping,location,viverra diam vitae,semper sapien,dapibus dolor vel,Flashset,3559785746335392,e287bb64-ff4f-434c-88ab-210ad433c77b,927820758-6,Achiaman,,2016-03-05,675.3,,Archived,22,Meevee, -// EOT; - -// $this->import(new AssetImporter($csv)); - -// $user = User::where('username', 'bnelson0')->firstOrFail(); - -// $this->tester->seeRecord('assets', [ -// 'asset_tag' => '970882174-8', -// 'assigned_type' => User::class, -// 'assigned_to' => $user->id, -// ]); - -// $user = User::where('username', 'mgibson2')->firstOrFail(); -// $this->tester->seeRecord('assets', [ -// 'asset_tag' => '710141467-2', -// 'assigned_type' => User::class, -// 'assigned_to' => $user->id, -// ]); - -// $location = Location::where('name', 'Planet Earth')->firstOrFail(); -// $this->tester->seeRecord('assets', [ -// 'asset_tag' => '998233705-X', -// 'assigned_type' => Location::class, -// 'assigned_to' => $location->id, -// ]); - -// $location = Location::where('name', 'Daping')->firstOrFail(); -// $this->tester->seeRecord('assets', [ -// 'asset_tag' => '927820758-6', -// 'assigned_type' => Location::class, -// 'assigned_to' => $location->id, -// ]); -// } - -// public function testUpdateAssetIncludingCustomFields() -// { -// $this->signIn(); -// $csv = <<<'EOT' -// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier,weight -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan,95 -// EOT; - -// $this->initializeCustomFields(); -// $this->import(new AssetImporter($csv)); - -// $updatedCSV = <<<'EOT' -// item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier -// A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative -// EOT; -// $importer = new AssetImporter($updatedCSV); -// $importer->setUserId(1) -// ->setUpdating(true) -// ->setUsernameFormat('firstname.lastname') -// ->import(); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'some other category', -// ]); - -// $this->tester->seeRecord('models', [ -// 'name' => 'Another Model', -// 'model_number' => 356, -// ]); - -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Linkbridge 32', -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'New Location', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Another Company', -// ]); - -// $this->tester->seeRecord('status_labels', [ -// 'name' => 'Ready To Go', -// ]); - -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Not Creative', -// ]); - -// $this->tester->seeRecord('assets', [ -// 'name' => 'A new name', -// 'serial' => '67433477', -// 'asset_tag' => '970882174-8', -// 'notes' => 'I have no notes', -// 'purchase_date' => '2018-04-05 00:00:01', -// 'purchase_cost' => 25.59, -// 'warranty_months' => 18, -// '_snipeit_weight_2' => 95, -// ]); -// } - -// public function testAssetModelNumber4359() -// { -// // As per bug #4359 -// // 1) Create model with blank model # and custom field. -// // 2 ) Update custom fields with a csv not including model # -// // 3 ) Not updated. NULL vs. empty issue. -// $this->signIn(); -// $csv = <<<'EOT' -// Name,Email,Username,item Name,Category,Model name,Manufacturer,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan -// EOT; - -// // Need to do this manually... -// $customField = \App\Models\CustomField::factory()->create(['name' => 'Weight']); -// $customFieldSet = \App\Models\CustomFieldset::factory()->create(['name' => 'Default']); -// $customFieldSet->fields()->attach($customField, [ -// 'required' => false, -// 'order' => 'asc', ]); - -// \App\Models\Category::factory()->assetLaptopCategory()->create([ -// 'name' => 'quam', -// ]); - -// \App\Models\Manufacturer::factory()->apple()->create([ -// 'name' => 'Linkbridge', -// ]); - -// $am = \App\Models\AssetModel::factory()->create([ -// 'name' => 'massa id', -// 'fieldset_id' => $customFieldSet->id, -// 'category_id' => 1, -// 'manufacturer_id' => 1, -// 'model_number' => null, -// ]); - -// $this->import(new AssetImporter($csv)); -// $updatedCSV = <<<'EOT' -// Serial,Asset Tag,weight -// 67433477,970882174-8,115 -// EOT; -// $importer = new AssetImporter($updatedCSV); -// $importer->setUserId(1) -// ->setUpdating(true) -// ->setUsernameFormat('firstname.lastname') -// ->import(); - -// $this->tester->seeRecord('assets', [ -// 'asset_tag' => '970882174-8', -// '_snipeit_weight_2' => 115, -// ]); -// } - -// public function initializeCustomFields() -// { -// $customField = \App\Models\CustomField::factory()->create(['name' => 'Weight']); -// $customFieldSet = \App\Models\CustomFieldset::factory()->create(['name' => 'Default']); -// $customFieldSet->fields()->attach($customField, [ -// 'required' => false, -// 'order' => 'asc', ]); - -// $am = \App\Models\AssetModel::factory()->create([ -// 'name' => 'massa id', -// 'fieldset_id' => $customFieldSet->id, -// ]); -// } - -// public function testCustomMappingImport() -// { -// $this->signIn(); -// $csv = <<<'EOT' -// Full Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier -// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan -// EOT; - -// $customFieldMap = [ -// 'asset_tag' => 'Asset', -// 'category' => 'Cat', -// 'company' => 'comp', -// 'item_name' => 'object name', -// 'expiration_date' => 'expiration date', -// 'location' => 'loc', -// 'notes' => 'Some Notes', -// 'asset_model' => 'model name', -// ]; - -// $this->import(new AssetImporter($csv), $customFieldMap); -// // Did we create a user? -// $this->tester->seeRecord('users', [ -// 'first_name' => 'Bonnie', -// 'last_name' => 'Nelson', -// 'email' => 'bnelson0@cdbaby.com', -// ]); -// // Grab the user record for use in asserting assigned_to -// $createdUser = $this->tester->grabRecord('users', [ -// 'first_name' => 'Bonnie', -// 'last_name' => 'Nelson', -// 'email' => 'bnelson0@cdbaby.com', -// ]); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'quam', -// ]); - -// $this->tester->seeRecord('models', [ -// 'name' => 'massa id', -// 'model_number' => 6377018600094472, -// ]); - -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Linkbridge', -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'Daping', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Alpha', -// ]); - -// $this->tester->seeRecord('status_labels', [ -// 'name' => 'Undeployable', -// ]); - -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Blogspan', -// ]); - -// $this->tester->seeRecord('assets', [ -// 'name' => 'eget nunc donec quis', -// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', -// 'asset_tag' => '970882174-8', -// 'notes' => 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', -// 'purchase_date' => '2016-04-05 00:00:01', -// 'purchase_cost' => 133289.59, -// 'warranty_months' => 14, -// 'assigned_to' => $createdUser['id'], -// 'assigned_type' => User::class, -// ]); -// } - -// public function testDefaultAccessoryImport() -// { -// $csv = <<<'EOT' -// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity -// Walter Carter,09/01/2006,,metus. Vivamus,Macromedia,J935H60W,Customers,False,278 -// EOT; -// $this->import(new AccessoryImporter($csv)); -// $this->tester->seeRecord('accessories', [ -// 'name' => 'Walter Carter', -// 'purchase_date' => '2006-09-01 00:00:01', -// 'order_number' => 'J935H60W', -// 'requestable' => 0, -// 'qty' => 278, -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'metus. Vivamus', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Macromedia', -// ]); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'Customers', -// ]); -// } - -// public function testDefaultAccessoryUpdate() -// { -// $csv = <<<'EOT' -// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity -// Walter Carter,09/01/2006,,metus. Vivamus,Macromedia,J935H60W,Customers,False,278 -// EOT; -// $this->import(new AccessoryImporter($csv)); -// $this->tester->seeNumRecords(1, 'accessories'); - -// $updatedCSV = <<<'EOT' -// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity -// Walter Carter,09/01/2015,350,metus. Vivamus,Macromedia,35GGH,Customers,True,12 -// EOT; -// $importer = new AccessoryImporter($updatedCSV); -// $importer->setUserId(1) -// ->setUpdating(true) -// ->import(); -// // At this point we should still only have one record. -// $this->tester->seeNumRecords(1, 'accessories'); -// // But instead these. -// $this->tester->seeRecord('accessories', [ -// 'name' => 'Walter Carter', -// 'purchase_date' => '2015-09-01 00:00:01', -// 'order_number' => '35GGH', -// 'requestable' => 1, -// 'qty' => 12, -// ]); -// } - -// public function testCustomAccessoryImport() -// { -// $csv = <<<'EOT' -// Name,Pur Date,Cost,Loc,Comp,Order Num,Cat,Request,Quan -// Walter Carter,09/01/2006,,metus. Vivamus,Macromedia,J935H60W,Customers,False,278 -// EOT; - -// $customFieldMap = [ -// 'category' => 'Cat', -// 'company' => 'Comp', -// 'item_name' => 'Name', -// 'location' => 'Loc', -// 'purchase_date' => 'Pur Date', -// 'purchase_cost' => 'Cost', -// 'order_number' => 'Order Num', -// 'requestable' => 'Request', -// 'quantity' => 'Quan', -// ]; -// $this->import(new AccessoryImporter($csv), $customFieldMap); -// // dd($this->tester->grabRecord('accessories')); -// $this->tester->seeRecord('accessories', [ -// 'name' => 'Walter Carter', -// 'purchase_date' => '2006-09-01 00:00:01', -// 'order_number' => 'J935H60W', -// 'requestable' => 0, -// 'qty' => 278, -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'metus. Vivamus', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Macromedia', -// ]); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'Customers', -// ]); -// } - -// public function testDefaultConsumableImport() -// { -// $csv = <<<'EOT' -// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity,Item Number,Model Number -// eget,01/03/2011,$85.91,mauris blandit mattis.,Lycos,T295T06V,Triamterene/Hydrochlorothiazide,No,322,3305,30123 -// EOT; -// $this->import(new ConsumableImporter($csv)); -// $this->tester->seeRecord('consumables', [ -// 'name' => 'eget', -// 'purchase_date' => '2011-01-03 00:00:01', -// 'purchase_cost' => 85.91, -// 'order_number' => 'T295T06V', -// 'requestable' => 0, -// 'qty' => 322, -// 'item_no' => 3305, -// 'model_number' => 30123, -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'mauris blandit mattis.', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Lycos', -// ]); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'Triamterene/Hydrochlorothiazide', -// ]); -// } - -// public function testDefaultConsumableUpdate() -// { -// $csv = <<<'EOT' -// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity -// eget,01/03/2011,85.91,mauris blandit mattis.,Lycos,T295T06V,Triamterene/Hydrochlorothiazide,No,322 -// EOT; -// $this->import(new ConsumableImporter($csv)); -// $this->tester->seeNumRecords(1, 'consumables'); - -// $updatedCSV = <<<'EOT' -// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity -// eget,12/05/2016,35.45,mauris blandit mattis.,Lycos,3666FF,New Cat,Yes,15 -// EOT; -// $importer = new ConsumableImporter($updatedCSV); -// $importer->setUserId(1) -// ->setUpdating(true) -// ->import(); -// // At this point we should still only have one record. -// $this->tester->seeNumRecords(1, 'consumables'); -// // But instead these. -// $this->tester->seeRecord('consumables', [ -// 'name' => 'eget', -// 'purchase_date' => '2016-12-05 00:00:01', -// 'purchase_cost' => 35.45, -// 'order_number' => '3666FF', -// 'requestable' => 1, -// 'qty' => 15, -// ]); -// } - -// public function testCustomConsumableImport() -// { -// $csv = <<<'EOT' -// Name,pur Date,Pur Cost,Loc,Comp,Order Num,Kat,Request,Quan -// eget,01/03/2011,85.91,mauris blandit mattis.,Lycos,T295T06V,Triamterene/Hydrochlorothiazide,No,322 -// EOT; - -// $customFieldMap = [ -// 'category' => 'Kat', -// 'company' => 'Comp', -// 'item_name' => 'Name', -// 'location' => 'Loc', -// 'purchase_date' => 'Pur date', -// 'purchase_cost' => 'Pur Cost', -// 'order_number' => 'Order Num', -// 'requestable' => 'Request', -// 'quantity' => 'Quan', -// ]; -// $this->import(new ConsumableImporter($csv), $customFieldMap); -// $this->tester->seeRecord('consumables', [ -// 'name' => 'eget', -// 'purchase_date' => '2011-01-03 00:00:01', -// 'purchase_cost' => 85.91, -// 'order_number' => 'T295T06V', -// 'requestable' => 0, -// 'qty' => 322, -// ]); - -// $this->tester->seeRecord('locations', [ -// 'name' => 'mauris blandit mattis.', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Lycos', -// ]); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'Triamterene/Hydrochlorothiazide', -// ]); -// } - -// public function testDefaultLicenseImport() -// { -// $this->signIn(); -// $csv = <<<'EOT' -// Full Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes,asset tag -// Helen Anderson,cspencer0@privacy.gov.au,cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.,test 1 -// EOT; - -// // Force create an asset to match the checkout -// $testAsset = $this->createValidAsset(['asset_tag' => 'test 1']); -// $this->import(new LicenseImporter($csv)); -// // dd($this->tester->grabRecord('licenses')); - -// // Did we create a user? -// $this->tester->seeRecord('users', [ -// 'first_name' => 'Helen', -// 'last_name' => 'Anderson', -// 'email' => 'cspencer0@privacy.gov.au', -// ]); -// // Grab the user record for use in asserting assigned_to -// $createdUser = $this->tester->grabRecord('users', [ -// 'first_name' => 'Helen', -// 'last_name' => 'Anderson', -// 'email' => 'cspencer0@privacy.gov.au', -// ]); -// $this->tester->seeRecord('licenses', [ -// 'name' => 'Argentum Malachite Athletes Foot Relief', -// 'purchase_date' => '2012-07-13 00:00:01', -// 'seats' => 80, -// 'license_email' => 'cspencer0@gov.uk', -// 'order_number' => '386436062-5', -// 'license_name' => 'Cynthia Spencer', -// 'expiration_date' => '2016-01-27', -// 'maintained' => 0, -// 'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.', -// 'purchase_cost' => 79.66, -// 'purchase_order' => '53008', -// 'reassignable' => 0, -// 'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c', -// ]); -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Beer, Leannon and Lubowitz', -// ]); - -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Hegmann, Mohr and Cremin', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Haag, Schmidt and Farrell', -// ]); - -// $this->tester->seeRecord('categories', [ -// 'name' => 'Graphics Software', -// ]); - -// $this->tester->seeNumRecords(80, 'license_seats'); -// $this->tester->seeRecord('license_seats', [ -// 'assigned_to' => $createdUser['id'], -// 'license_id' => \App\Models\License::where('serial', '1aa5b0eb-79c5-40b2-8943-5472a6893c3c')->first()->id, -// 'asset_id' => $testAsset->id, -// ]); -// } - -// public function testDefaultLicenseUpdate() -// { -// $csv = <<<'EOT' -// Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes -// Helen Anderson,cspencer0@privacy.gov.au,cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus. -// EOT; -// $this->import(new LicenseImporter($csv)); -// $this->tester->seeNumRecords(1, 'licenses'); - -// $updatedCSV = <<<'EOT' -// Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes -// Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",05/15/2019,$1865.34,63 ar,18334,A Legend,Legendary@gov.uk,04/27/2016,yes,true,64,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus. -// EOT; -// $importer = new LicenseImporter($updatedCSV); -// $importer->setUserId(1) -// ->setUpdating(true) -// ->import(); -// // At this point we should still only have one record. -// $this->tester->seeNumRecords(1, 'licenses'); -// // But instead these. - -// \Log::debug($this->tester->grabRecord('licenses')); -// $this->tester->seeRecord('licenses', [ -// 'name' => 'Argentum Malachite Athletes Foot Relief', -// 'purchase_date' => '2019-05-15 00:00:01', -// 'seats' => 64, -// 'license_email' => 'Legendary@gov.uk', -// 'order_number' => '18334', -// 'license_name' => 'A Legend', -// 'expiration_date' => '2016-04-27', -// 'maintained' => 1, -// 'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.', -// 'purchase_cost' => 1865.34, -// 'purchase_order' => '63 ar', -// 'reassignable' => 1, -// 'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c', -// ]); -// // License seats are soft deleted -// $this->tester->seeNumRecords(64, 'license_seats', ['deleted_at' => null]); -// } - -// public function testCustomLicenseImport() -// { -// $csv = <<<'EOT' -// Name,Email,Username,Object name,serial num,manuf,pur date,pur cost,purc order,order num,Licensed To,Licensed Email,expire date,maint,reass,seat,comp,supplier,category,note -// Helen Anderson,cspencer0@privacy.gov.au,cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Custom Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus. -// EOT; - -// $customFieldMap = [ -// 'company' => 'Comp', -// 'expiration_date' => 'expire date', -// 'item_name' => 'Object Name', -// 'license_email' => 'licensed email', -// 'license_name' => 'licensed to', -// 'maintained' => 'maint', -// 'manufacturer' => 'manuf', -// 'notes' => 'note', -// 'order_number' => 'Order Num', -// 'purchase_cost' => 'Pur Cost', -// 'purchase_date' => 'Pur date', -// 'purchase_order' => 'Purc Order', -// 'quantity' => 'Quan', -// 'reassignable' => 'reass', -// 'requestable' => 'Request', -// 'seats' => 'seat', -// 'serial' => 'serial num', -// 'category' => 'category', -// ]; -// $this->import(new LicenseImporter($csv), $customFieldMap); -// $this->tester->seeRecord('licenses', [ -// 'name' => 'Argentum Malachite Athletes Foot Relief', -// 'purchase_date' => '2012-07-13 00:00:01', -// 'seats' => 80, -// 'license_email' => 'cspencer0@gov.uk', -// 'order_number' => '386436062-5', -// 'license_name' => 'Cynthia Spencer', -// 'expiration_date' => '2016-01-27', -// 'maintained' => 0, -// 'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.', -// 'purchase_cost' => 79.66, -// 'purchase_order' => '53008', -// 'reassignable' => 0, -// 'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c', -// ]); - -// $this->tester->seeRecord('manufacturers', [ -// 'name' => 'Beer, Leannon and Lubowitz', -// ]); - -// $this->tester->seeRecord('suppliers', [ -// 'name' => 'Hegmann, Mohr and Cremin', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Haag, Schmidt and Farrell', -// ]); - -// $this->tester->seeNumRecords(80, 'license_seats'); -// } - -// public function testDefaultUserImport() -// { -// Notification::fake(); -// $this->signIn(); -// $csv = <<<'EOT' -// First Name,Last Name,email,Username,Location,Phone Number,Job Title,Employee Number,Company,Department,activated -// Blanche,O'Collopy,bocollopy0@livejournal.com,bocollopy0,Hinapalanan,63-(199)661-2186,Clinical Specialist,7080919053,Morar-Ward,Management,1 -// Jessie,Primo,,jprimo1,Korenovsk,7-(885)578-0266,Paralegal,6284292031,Jast-Stiedemann,1 - -// EOT; -// $user_importer = new UserImporter($csv); -// $user_importer->sendWelcome(); -// $this->import($user_importer); - -// $this->tester->seeRecord('users', [ -// 'first_name' => 'Blanche', -// 'last_name' => "O'Collopy", -// 'email' => 'bocollopy0@livejournal.com', -// 'username' => 'bocollopy0', -// 'phone' => '63-(199)661-2186', -// 'jobtitle' => 'Clinical Specialist', -// 'employee_num' => '7080919053', -// ]); - -// $this->tester->seeRecord('companies', [ -// 'name' => 'Morar-Ward', -// ]); - -// $this->tester->seeRecord('departments', [ -// 'name' => 'Management', -// ]); - -// Notification::assertSentTo(User::find(2), \App\Notifications\WelcomeNotification::class); -// Notification::assertNotSentTo(User::find(3), \App\Notifications\WelcomeNotification::class); -// } - -// private function import($importer, $mappings = null) -// { -// if ($mappings) { -// $importer->setFieldMappings($mappings); -// } -// $importer->setUserId(1) -// ->setUpdating(false) -// ->setUsernameFormat('firstname.lastname') -// ->import(); -// } -} diff --git a/tests/Unit/PermissionsTest.php b/tests/Unit/PermissionsTest.php deleted file mode 100644 index e788585dd..000000000 --- a/tests/Unit/PermissionsTest.php +++ /dev/null @@ -1,510 +0,0 @@ -noHardware = [ - // 'assets.view' => false, - // 'assets.create' => false, - // 'assets.edit' => false, - // 'assets.delete' => false, - // ]; - - // $this->noLicenses = [ - // 'licenses.view' => false, - // 'licenses.create' => false, - // 'licenses.edit' => false, - // 'licenses.delete' => false, - // ]; - - // $this->noAccessories = [ - // 'accessories.view' => false, - // 'accessories.create' => false, - // 'accessories.edit' => false, - // 'accessories.delete' => false, - // ]; - - // $this->noConsumables = [ - // 'consumables.view' => false, - // 'consumables.create' => false, - // 'consumables.edit' => false, - // 'consumables.delete' => false, - // ]; - - // $this->noComponents = [ - // 'components.view' => false, - // 'components.create' => false, - // 'components.edit' => false, - // 'components.delete' => false, - // ]; - - // $this->noUsers = [ - // 'users.view' => false, - // 'users.create' => false, - // 'users.edit' => false, - // 'users.delete' => false, - // ]; - // } - - // private $noHardware; - // private $noLicenses; - // private $noAccessories; - // private $noConsumables; - // private $noComponents; - // private $noUsers; - - // // tests - - // /** - // * @test - // */ - // public function a_user_with_no_permissions_sees_nothing() - // { - // $u = \App\Models\User::factory()->create(); - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - // // $permissions = $this->noHardware; - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_view_asset_permissions_can_view_assets() - // { - // $u = \App\Models\User::factory()->viewAssets()->create(); - // $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'assets.view' => true, - // 'assets.create' => false, - // 'assets.edit' => false, - // 'assets.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_create_asset_permissions_can_create_assets() - // { - // $u = \App\Models\User::factory()->createAssets()->create(); - // $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'assets.view' => false, - // 'assets.create' => true, - // 'assets.edit' => false, - // 'assets.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_edit_assets_permissions_can_edit_assets() - // { - // $u = \App\Models\User::factory()->editAssets()->create(); - - // $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'assets.view' => false, - // 'assets.create' => false, - // 'assets.edit' => true, - // 'assets.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_delete_assets_permissions_can_delete_assets() - // { - // $u = \App\Models\User::factory()->deleteAssets()->create(); - // $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - // $permissions = array_merge($permissions, [ - // 'assets.view' => false, - // 'assets.create' => false, - // 'assets.edit' => false, - // 'assets.delete' => true, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_view_licenses_permissions_can_view_licenses() - // { - // $u = \App\Models\User::factory()->viewLicenses()->create(); - // $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'licenses.view' => true, - // 'licenses.create' => false, - // 'licenses.edit' => false, - // 'licenses.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_create_licenses_permissions_can_create_licenses() - // { - // $u = \App\Models\User::factory()->createLicenses()->create(); - // $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'licenses.view' => false, - // 'licenses.create' => true, - // 'licenses.edit' => false, - // 'licenses.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_edit_licenses_permissions_can_edit_licenses() - // { - // $u = \App\Models\User::factory()->editLicenses()->create(); - // $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'licenses.view' => false, - // 'licenses.create' => false, - // 'licenses.edit' => true, - // 'licenses.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_delete_licenses_permissions_can_delete_licenses() - // { - // $u = \App\Models\User::factory()->deleteLicenses()->create(); - // $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'licenses.view' => false, - // 'licenses.create' => false, - // 'licenses.edit' => false, - // 'licenses.delete' => true, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_view_accessories_permissions_can_view_accessories() - // { - // $u = \App\Models\User::factory()->viewAccessories()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'accessories.view' => true, - // 'accessories.create' => false, - // 'accessories.edit' => false, - // 'accessories.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_create_accessories_permissions_can_create_accessories() - // { - // $u = \App\Models\User::factory()->createAccessories()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'accessories.view' => false, - // 'accessories.create' => true, - // 'accessories.edit' => false, - // 'accessories.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_edit_accessories_permissions_can_edit_accessories() - // { - // $u = \App\Models\User::factory()->editAccessories()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'accessories.view' => false, - // 'accessories.create' => false, - // 'accessories.edit' => true, - // 'accessories.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_delete_accessories_permissions_can_delete_accessories() - // { - // $u = \App\Models\User::factory()->deleteAccessories()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'accessories.view' => false, - // 'accessories.create' => false, - // 'accessories.edit' => false, - // 'accessories.delete' => true, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_view_consumables_permissions_can_view_consumables() - // { - // $u = \App\Models\User::factory()->viewConsumables()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'consumables.view' => true, - // 'consumables.create' => false, - // 'consumables.edit' => false, - // 'consumables.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_create_consumables_permissions_can_create_consumables() - // { - // $u = \App\Models\User::factory()->createConsumables()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'consumables.view' => false, - // 'consumables.create' => true, - // 'consumables.edit' => false, - // 'consumables.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_edit_consumables_permissions_can_edit_consumables() - // { - // $u = \App\Models\User::factory()->editConsumables()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'consumables.view' => false, - // 'consumables.create' => false, - // 'consumables.edit' => true, - // 'consumables.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_delete_consumables_permissions_can_delete_consumables() - // { - // $u = \App\Models\User::factory()->deleteConsumables()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'consumables.view' => false, - // 'consumables.create' => false, - // 'consumables.edit' => false, - // 'consumables.delete' => true, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_view_users_permissions_can_view_users() - // { - // $u = \App\Models\User::factory()->viewUsers()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents; - - // $permissions = array_merge($permissions, [ - // 'users.view' => true, - // 'users.create' => false, - // 'users.edit' => false, - // 'users.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_create_users_permissions_can_create_users() - // { - // $u = \App\Models\User::factory()->createUsers()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents; - - // $permissions = array_merge($permissions, [ - // 'users.view' => false, - // 'users.create' => true, - // 'users.edit' => false, - // 'users.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_edit_users_permissions_can_edit_users() - // { - // $u = \App\Models\User::factory()->editUsers()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents; - - // $permissions = array_merge($permissions, [ - // 'users.view' => false, - // 'users.create' => false, - // 'users.edit' => true, - // 'users.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_delete_users_permissions_can_delete_users() - // { - // $u = \App\Models\User::factory()->deleteUsers()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents; - - // $permissions = array_merge($permissions, [ - // 'users.view' => false, - // 'users.create' => false, - // 'users.edit' => false, - // 'users.delete' => true, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_view_components_permissions_can_view_components() - // { - // $u = \App\Models\User::factory()->viewComponents()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'components.view' => true, - // 'components.create' => false, - // 'components.edit' => false, - // 'components.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_create_components_permissions_can_create_components() - // { - // $u = \App\Models\User::factory()->createComponents()->create(); - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'components.view' => false, - // 'components.create' => true, - // 'components.edit' => false, - // 'components.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_edit_components_permissions_can_edit_components() - // { - // $u = \App\Models\User::factory()->editComponents()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'components.view' => false, - // 'components.create' => false, - // 'components.edit' => true, - // 'components.delete' => false, - // ]); - // $this->hitRoutes($permissions, $u); - // } - - // /** - // * @test - // */ - // public function a_user_with_delete_components_permissions_can_delete_components() - // { - // $u = \App\Models\User::factory()->deleteComponents()->create(); - - // $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers; - - // $permissions = array_merge($permissions, [ - // 'components.view' => false, - // 'components.create' => false, - // 'components.edit' => false, - // 'components.delete' => true, - // ]); - // // dd($u); - // $this->hitRoutes($permissions, $u); - // } - - // private function hitRoutes(array $routes, User $user) - // { - // foreach ($routes as $route => $expectation) { - // $this->assertEquals($user->hasAccess($route), $expectation); - // } - // } -} From 1afb724606b74618337712da42801e2d4a9ef9a0 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 13:11:43 -0700 Subject: [PATCH 31/33] Remove commented (and old) test cases --- tests/Unit/CategoryTest.php | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index c74597b1b..e5c98a67a 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -60,34 +60,4 @@ class CategoryTest extends TestCase $this->assertCount(5, $category->models); $this->assertEquals(10, $category->itemCount()); } - - - // public function testACategoryCanHaveAccessories() - // { - // $category = Category::factory()->assetDesktopCategory()->create(); - // Accessory::factory()->count(5)->appleBtKeyboard()->create( - // [ - // 'category_id' => $category->id - // ] - // ); - - // $this->assertCount(5, $category->accessories); - // $this->assertEquals(5, $category->itemCount()); - // } - - // public function testACategoryCanHaveConsumables() - // { - // $category = $this->createValidCategory('consumable-paper-category'); - // \App\Models\Consumable::factory()->count(5)->cardstock()->create(['category_id' => $category->id]); - // $this->assertCount(5, $category->consumables); - // $this->assertEquals(5, $category->itemCount()); - // } - - // public function testACategoryCanHaveComponents() - // { - // $category = $this->createValidCategory('component-ram-category'); - // \App\Models\Component::factory()->count(5)->ramCrucial4()->create(['category_id' => $category->id]); - // $this->assertCount(5, $category->components); - // $this->assertEquals(5, $category->itemCount()); - // } } From 948dc3c974eece8042ee47b953e49a5dca5414dd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 13:11:53 -0700 Subject: [PATCH 32/33] Remove duplicate trait --- tests/Feature/Api/Users/UpdateUserApiTest.php | 4 ---- tests/Unit/AssetTest.php | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Feature/Api/Users/UpdateUserApiTest.php b/tests/Feature/Api/Users/UpdateUserApiTest.php index 81c115464..0786b171e 100644 --- a/tests/Feature/Api/Users/UpdateUserApiTest.php +++ b/tests/Feature/Api/Users/UpdateUserApiTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Users; use App\Models\User; use Tests\Support\InteractsWithSettings; use Tests\TestCase; -use Tests\Support\InteractsWithAuthentication; - class UpdateUserApiTest extends TestCase { use InteractsWithSettings; - use InteractsWithAuthentication; public function testApiUsersCanBeActivatedWithNumber() { @@ -64,5 +61,4 @@ class UpdateUserApiTest extends TestCase $this->assertEquals(0, $user->refresh()->activated); } - } diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index 7670d1075..d3d9a9011 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -23,6 +23,7 @@ class AssetTest extends TestCase $this->assertModelExists($b); } + public function testAutoIncrementCollision() { $this->settings->enableAutoIncrement(); From d0d4d14787e8e5cb57622499b28c8ce3436dd916 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 18 Mar 2024 12:29:00 +0000 Subject: [PATCH 33/33] Make sure the category is still valid before displaying on view assets Signed-off-by: snipe --- resources/views/account/view-assets.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index e8d068576..48c94f683 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -521,7 +521,7 @@ @else ------------ @endcan - {{ $license->category->name }} + {{ ($license->category) ? $license->category->name : trans('general.deleted') }} @endforeach