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; + } + ); + } +}