From fa69a580ab470e222f89129da5e39e77a74de7f5 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 23 Mar 2023 17:18:33 -0700 Subject: [PATCH] Start to scaffold license checkout notification test --- app/Models/LicenseSeat.php | 4 +- database/factories/LicenseSeatFactory.php | 21 ++++++++ .../AssetCheckoutWebhookNotificationTest.php | 1 - ...LicenseCheckoutWebhookNotificationTest.php | 53 +++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 database/factories/LicenseSeatFactory.php create mode 100644 tests/Feature/Notifications/LicenseCheckoutWebhookNotificationTest.php diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.php index 2207edd02c..d2a99d3c56 100755 --- a/app/Models/LicenseSeat.php +++ b/app/Models/LicenseSeat.php @@ -6,13 +6,15 @@ use App\Models\Traits\Acceptable; use App\Notifications\CheckinLicenseNotification; use App\Notifications\CheckoutLicenseNotification; use App\Presenters\Presentable; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; class LicenseSeat extends SnipeModel implements ICompanyableChild { use CompanyableChildTrait; - use SoftDeletes; + use HasFactory; use Loggable; + use SoftDeletes; protected $presenter = \App\Presenters\LicenseSeatPresenter::class; use Presentable; diff --git a/database/factories/LicenseSeatFactory.php b/database/factories/LicenseSeatFactory.php new file mode 100644 index 0000000000..c4d43f89b3 --- /dev/null +++ b/database/factories/LicenseSeatFactory.php @@ -0,0 +1,21 @@ + License::factory(), + ]; + } +} diff --git a/tests/Feature/Notifications/AssetCheckoutWebhookNotificationTest.php b/tests/Feature/Notifications/AssetCheckoutWebhookNotificationTest.php index 4683d6f306..57a6fcfb98 100644 --- a/tests/Feature/Notifications/AssetCheckoutWebhookNotificationTest.php +++ b/tests/Feature/Notifications/AssetCheckoutWebhookNotificationTest.php @@ -61,5 +61,4 @@ class AssetCheckoutWebhookNotificationTest extends TestCase { return Asset::factory()->laptopMbp()->create(); } - } diff --git a/tests/Feature/Notifications/LicenseCheckoutWebhookNotificationTest.php b/tests/Feature/Notifications/LicenseCheckoutWebhookNotificationTest.php new file mode 100644 index 0000000000..6fd7d22cfc --- /dev/null +++ b/tests/Feature/Notifications/LicenseCheckoutWebhookNotificationTest.php @@ -0,0 +1,53 @@ + [fn() => User::factory()->create()], + 'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()], + ]; + } + + /** @dataProvider checkoutTargets */ + public function testWebhookNotificationsAreSentOnLicenseCheckoutWhenWebhookSettingEnabled($checkoutTarget) + { + Notification::fake(); + + Setting::factory()->withWebhookEnabled()->create(); + + $checkoutTarget = $checkoutTarget(); + + $licenseSeat = LicenseSeat::factory()->create(); + + // @todo: this has to go through the LicenseCheckoutController::store() method + // @todo: to have the CheckoutableCheckedOut fire... + // @todo: either change this to go through controller + // @todo: or move that functionality to the model? + // $licenseSeat->checkOut( + // $checkoutTarget, + // User::factory()->superuser()->create()->id + // ); + + Notification::assertSentTo( + new AnonymousNotifiable, + CheckoutLicenseSeatNotification::class, + function ($notification, $channels, $notifiable) { + return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; + } + ); + } +}