Test the event instead of the checkout

This commit is contained in:
Marcus Moore 2023-03-30 15:38:00 -07:00
parent 2cbc6276f7
commit 158e1544cd
No known key found for this signature in database

View file

@ -2,12 +2,14 @@
namespace Tests\Feature\Notifications; namespace Tests\Feature\Notifications;
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\CheckoutAssetNotification; use App\Notifications\CheckoutAssetNotification;
use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Tests\TestCase; use Tests\TestCase;
@ -22,6 +24,15 @@ class AssetCheckoutWebhookNotificationTest extends TestCase
]; ];
} }
public function testAssetCheckoutFiresCheckoutEvent()
{
Event::fake([CheckoutableCheckedOut::class]);
$this->createAsset()->checkOut(User::factory()->create(), User::factory()->create());
Event::assertDispatched(CheckoutableCheckedOut::class);
}
/** @dataProvider checkoutTargets */ /** @dataProvider checkoutTargets */
public function testWebhookNotificationsAreSentOnAssetCheckoutWhenWebhookSettingEnabled($checkoutTarget) public function testWebhookNotificationsAreSentOnAssetCheckoutWhenWebhookSettingEnabled($checkoutTarget)
{ {
@ -29,10 +40,12 @@ class AssetCheckoutWebhookNotificationTest extends TestCase
Setting::factory()->withWebhookEnabled()->create(); Setting::factory()->withWebhookEnabled()->create();
$this->createAsset()->checkOut( event(new CheckoutableCheckedOut(
$this->createAsset(),
$checkoutTarget(), $checkoutTarget(),
User::factory()->superuser()->create()->id User::factory()->superuser()->create(),
); ''
));
Notification::assertSentTo( Notification::assertSentTo(
new AnonymousNotifiable, new AnonymousNotifiable,
@ -48,10 +61,12 @@ class AssetCheckoutWebhookNotificationTest extends TestCase
{ {
Notification::fake(); Notification::fake();
$this->createAsset()->checkOut( event(new CheckoutableCheckedOut(
$this->createAsset(),
$checkoutTarget(), $checkoutTarget(),
User::factory()->superuser()->create()->id User::factory()->superuser()->create(),
); ''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
} }