2023-03-23 17:18:33 -07:00
|
|
|
<?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();
|
|
|
|
|
2023-03-27 14:09:21 -07:00
|
|
|
event(new CheckoutableCheckedOut(
|
|
|
|
LicenseSeat::factory()->create(),
|
|
|
|
$checkoutTarget(),
|
|
|
|
User::factory()->superuser()->create(),
|
|
|
|
''
|
|
|
|
));
|
2023-03-23 17:18:33 -07:00
|
|
|
|
|
|
|
Notification::assertSentTo(
|
|
|
|
new AnonymousNotifiable,
|
|
|
|
CheckoutLicenseSeatNotification::class,
|
|
|
|
function ($notification, $channels, $notifiable) {
|
|
|
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|