mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Add tests for sending webhooks on asset and license seat checkin
This commit is contained in:
parent
3054d633b0
commit
5b4d5cadf4
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Notifications;
|
namespace Tests\Feature\Notifications;
|
||||||
|
|
||||||
|
use App\Events\CheckoutableCheckedIn;
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\CheckinAssetNotification;
|
||||||
use App\Notifications\CheckoutAssetNotification;
|
use App\Notifications\CheckoutAssetNotification;
|
||||||
use Illuminate\Notifications\AnonymousNotifiable;
|
use Illuminate\Notifications\AnonymousNotifiable;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
@ -15,7 +17,7 @@ use Tests\TestCase;
|
||||||
|
|
||||||
class AssetWebhookTest extends TestCase
|
class AssetWebhookTest extends TestCase
|
||||||
{
|
{
|
||||||
public function checkoutTargets()
|
public function checkoutTargets(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Asset checked out to user' => [fn() => User::factory()->create()],
|
'Asset checked out to user' => [fn() => User::factory()->create()],
|
||||||
|
@ -73,6 +75,46 @@ class AssetWebhookTest extends TestCase
|
||||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @dataProvider checkoutTargets */
|
||||||
|
public function testAssetCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
Setting::factory()->withWebhookEnabled()->create();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
$this->createAsset(),
|
||||||
|
$checkoutTarget(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertSentTo(
|
||||||
|
new AnonymousNotifiable,
|
||||||
|
CheckinAssetNotification::class,
|
||||||
|
function ($notification, $channels, $notifiable) {
|
||||||
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @dataProvider checkoutTargets */
|
||||||
|
public function testAssetCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
Setting::factory()->withWebhookDisabled()->create();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
$this->createAsset(),
|
||||||
|
$checkoutTarget(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
private function createAsset()
|
private function createAsset()
|
||||||
{
|
{
|
||||||
return Asset::factory()->laptopMbp()->create();
|
return Asset::factory()->laptopMbp()->create();
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Notifications;
|
namespace Tests\Feature\Notifications;
|
||||||
|
|
||||||
|
use App\Events\CheckoutableCheckedIn;
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\LicenseSeat;
|
use App\Models\LicenseSeat;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\CheckinLicenseSeatNotification;
|
||||||
use App\Notifications\CheckoutLicenseSeatNotification;
|
use App\Notifications\CheckoutLicenseSeatNotification;
|
||||||
use Illuminate\Notifications\AnonymousNotifiable;
|
use Illuminate\Notifications\AnonymousNotifiable;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
@ -14,7 +16,7 @@ use Tests\TestCase;
|
||||||
|
|
||||||
class LicenseWebhookTest extends TestCase
|
class LicenseWebhookTest extends TestCase
|
||||||
{
|
{
|
||||||
public function checkoutTargets()
|
public function checkoutTargets(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'License checked out to user' => [fn() => User::factory()->create()],
|
'License checked out to user' => [fn() => User::factory()->create()],
|
||||||
|
@ -61,4 +63,44 @@ class LicenseWebhookTest extends TestCase
|
||||||
|
|
||||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @dataProvider checkoutTargets */
|
||||||
|
public function testLicenseCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
Setting::factory()->withWebhookEnabled()->create();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
LicenseSeat::factory()->create(),
|
||||||
|
$checkoutTarget(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertSentTo(
|
||||||
|
new AnonymousNotifiable,
|
||||||
|
CheckinLicenseSeatNotification::class,
|
||||||
|
function ($notification, $channels, $notifiable) {
|
||||||
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @dataProvider checkoutTargets */
|
||||||
|
public function testLicenseCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
Setting::factory()->withWebhookDisabled()->create();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
LicenseSeat::factory()->create(),
|
||||||
|
$checkoutTarget(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue