Start to scaffold license checkout notification test

This commit is contained in:
Marcus Moore 2023-03-23 17:18:33 -07:00
parent fc043a35d9
commit fa69a580ab
No known key found for this signature in database
4 changed files with 77 additions and 2 deletions

View file

@ -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;

View file

@ -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(),
];
}
}

View file

@ -61,5 +61,4 @@ class AssetCheckoutWebhookNotificationTest extends TestCase
{
return Asset::factory()->laptopMbp()->create();
}
}

View file

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