Improve readability by extracting fireCheckOutEvent method

This commit is contained in:
Marcus Moore 2024-02-27 17:52:18 -08:00
parent 15b8140bff
commit cd579a04dd
No known key found for this signature in database

View file

@ -15,6 +15,7 @@ use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutAssetNotification; use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseSeatNotification; use App\Notifications\CheckoutLicenseSeatNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings; use Tests\Support\InteractsWithSettings;
@ -52,12 +53,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->enableSlackWebhook(); $this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Accessory::factory()->appleBtKeyboard()->create(), Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(), User::factory()->create(),
User::factory()->superuser()->create(), );
''
));
Notification::assertSentTo( Notification::assertSentTo(
new AnonymousNotifiable, new AnonymousNotifiable,
@ -72,12 +71,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->disableSlackWebhook(); $this->settings->disableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Accessory::factory()->appleBtKeyboard()->create(), Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(), User::factory()->create(),
User::factory()->superuser()->create(), );
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
} }
@ -87,12 +84,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->enableSlackWebhook(); $this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Asset::factory()->laptopMbp()->create(), Asset::factory()->laptopMbp()->create(),
$checkoutTarget(), $checkoutTarget(),
User::factory()->superuser()->create(), );
''
));
Notification::assertSentTo( Notification::assertSentTo(
new AnonymousNotifiable, new AnonymousNotifiable,
@ -108,12 +103,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->disableSlackWebhook(); $this->settings->disableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Asset::factory()->laptopMbp()->create(), Asset::factory()->laptopMbp()->create(),
$checkoutTarget(), $checkoutTarget(),
User::factory()->superuser()->create(), );
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
} }
@ -122,12 +115,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->enableSlackWebhook(); $this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Component::factory()->ramCrucial8()->create(), Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(), Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(), );
''
));
Notification::assertNothingSent(); Notification::assertNothingSent();
} }
@ -136,12 +127,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->enableSlackWebhook(); $this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Consumable::factory()->cardstock()->create(), Consumable::factory()->cardstock()->create(),
User::factory()->create(), User::factory()->create(),
User::factory()->superuser()->create(), );
''
));
Notification::assertSentTo( Notification::assertSentTo(
new AnonymousNotifiable, new AnonymousNotifiable,
@ -156,12 +145,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->disableSlackWebhook(); $this->settings->disableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
Consumable::factory()->cardstock()->create(), Consumable::factory()->cardstock()->create(),
User::factory()->create(), User::factory()->create(),
User::factory()->superuser()->create(), );
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
} }
@ -171,12 +158,10 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->enableSlackWebhook(); $this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
LicenseSeat::factory()->create(), LicenseSeat::factory()->create(),
$checkoutTarget(), $checkoutTarget(),
User::factory()->superuser()->create(), );
''
));
Notification::assertSentTo( Notification::assertSentTo(
new AnonymousNotifiable, new AnonymousNotifiable,
@ -192,13 +177,21 @@ class SlackNotificationsUponCheckoutTest extends TestCase
{ {
$this->settings->disableSlackWebhook(); $this->settings->disableSlackWebhook();
event(new CheckoutableCheckedOut( $this->fireCheckOutEvent(
LicenseSeat::factory()->create(), LicenseSeat::factory()->create(),
$checkoutTarget(), $checkoutTarget(),
User::factory()->superuser()->create(), );
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
} }
private function fireCheckOutEvent(Model $checkoutable, Model $target)
{
event(new CheckoutableCheckedOut(
$checkoutable,
$target,
User::factory()->superuser()->create(),
'',
));
}
} }