mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Start to scaffold license checkout notification test
This commit is contained in:
parent
fc043a35d9
commit
fa69a580ab
|
@ -6,13 +6,15 @@ use App\Models\Traits\Acceptable;
|
||||||
use App\Notifications\CheckinLicenseNotification;
|
use App\Notifications\CheckinLicenseNotification;
|
||||||
use App\Notifications\CheckoutLicenseNotification;
|
use App\Notifications\CheckoutLicenseNotification;
|
||||||
use App\Presenters\Presentable;
|
use App\Presenters\Presentable;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
class LicenseSeat extends SnipeModel implements ICompanyableChild
|
class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||||
{
|
{
|
||||||
use CompanyableChildTrait;
|
use CompanyableChildTrait;
|
||||||
use SoftDeletes;
|
use HasFactory;
|
||||||
use Loggable;
|
use Loggable;
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $presenter = \App\Presenters\LicenseSeatPresenter::class;
|
protected $presenter = \App\Presenters\LicenseSeatPresenter::class;
|
||||||
use Presentable;
|
use Presentable;
|
||||||
|
|
21
database/factories/LicenseSeatFactory.php
Normal file
21
database/factories/LicenseSeatFactory.php
Normal 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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,5 +61,4 @@ class AssetCheckoutWebhookNotificationTest extends TestCase
|
||||||
{
|
{
|
||||||
return Asset::factory()->laptopMbp()->create();
|
return Asset::factory()->laptopMbp()->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue