A free open source IT asset/license management system
Start to scaffold license checkout notification test
Marcus Moorefa69a580ab47
diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.phpindex 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.phpnew file mode 100644index 0000000000..c4d43f89b3--- /dev/null+++ b/database/factories/LicenseSeatFactory.php@@ -0,0 +1,21 @@+<?php++namespace Database\Factories;++use App\Models\License;+use Illuminate\Database\Eloquent\Factories\Factory;++class LicenseSeatFactory extends Factory+{+ /**+ * Define the model's default state.+ *+ * @return array+ */+ public function definition()+ {+ return [+ 'license_id' => License::factory(),+ ];+ }+}diff --git a/tests/Feature/Notifications/AssetCheckoutWebhookNotificationTest.php b/tests/Feature/Notifications/AssetCheckoutWebhookNotificationTest.phpindex 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.phpnew file mode 100644index 0000000000..6fd7d22cfc--- /dev/null+++ b/tests/Feature/Notifications/LicenseCheckoutWebhookNotificationTest.php@@ -0,0 +1,53 @@+<?php++namespace Tests\Feature\Notifications;++use App\Events\CheckoutableCheckedOut;+use App\Models\Asset;+use App\Models\LicenseSeat;+use App\Models\Setting;+use App\Models\User;+use App\Notifications\CheckoutLicenseSeatNotification;+use Illuminate\Notifications\AnonymousNotifiable;+use Illuminate\Support\Facades\Notification;+use Tests\TestCase;++class LicenseCheckoutWebhookNotificationTest extends TestCase+{+ public function checkoutTargets()+ {+ return [+ 'License checked out to user' => [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;+ }+ );+ }+}