ok
This commit is contained in:
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications\Webhooks;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Component;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAccessoryNotification;
|
||||
use App\Notifications\CheckinAssetNotification;
|
||||
use App\Notifications\CheckinLicenseSeatNotification;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @group notifications
|
||||
*/
|
||||
class SlackNotificationsUponCheckinTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Notification::fake();
|
||||
}
|
||||
|
||||
public function assetCheckInTargets(): array
|
||||
{
|
||||
return [
|
||||
'Asset checked out to user' => [fn() => User::factory()->create()],
|
||||
'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
|
||||
'Asset checked out to location' => [fn() => Location::factory()->create()],
|
||||
];
|
||||
}
|
||||
|
||||
public function licenseCheckInTargets(): array
|
||||
{
|
||||
return [
|
||||
'License checked out to user' => [fn() => User::factory()->create()],
|
||||
'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
|
||||
];
|
||||
}
|
||||
|
||||
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
Accessory::factory()->create(),
|
||||
User::factory()->create(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckinAccessoryNotification::class);
|
||||
}
|
||||
|
||||
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
Accessory::factory()->create(),
|
||||
User::factory()->create(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckinAccessoryNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider assetCheckInTargets */
|
||||
public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
Asset::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckinAssetNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider assetCheckInTargets */
|
||||
public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
Asset::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckinAssetNotification::class);
|
||||
}
|
||||
|
||||
public function testComponentCheckinDoesNotSendSlackNotification()
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
Component::factory()->create(),
|
||||
Asset::factory()->laptopMbp()->create(),
|
||||
);
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
/** @dataProvider licenseCheckInTargets */
|
||||
public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckinLicenseSeatNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider licenseCheckInTargets */
|
||||
public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckInEvent(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckinLicenseSeatNotification::class);
|
||||
}
|
||||
|
||||
private function fireCheckInEvent(Model $checkoutable, Model $target)
|
||||
{
|
||||
event(new CheckoutableCheckedIn(
|
||||
$checkoutable,
|
||||
$target,
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications\Webhooks;
|
||||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Component;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckoutAccessoryNotification;
|
||||
use App\Notifications\CheckoutAssetNotification;
|
||||
use App\Notifications\CheckoutConsumableNotification;
|
||||
use App\Notifications\CheckoutLicenseSeatNotification;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @group notifications
|
||||
*/
|
||||
class SlackNotificationsUponCheckoutTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Notification::fake();
|
||||
}
|
||||
|
||||
public function assetCheckoutTargets(): array
|
||||
{
|
||||
return [
|
||||
'Asset checked out to user' => [fn() => User::factory()->create()],
|
||||
'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
|
||||
'Asset checked out to location' => [fn() => Location::factory()->create()],
|
||||
];
|
||||
}
|
||||
|
||||
public function licenseCheckoutTargets(): array
|
||||
{
|
||||
return [
|
||||
'License checked out to user' => [fn() => User::factory()->create()],
|
||||
'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
|
||||
];
|
||||
}
|
||||
|
||||
public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled()
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Accessory::factory()->create(),
|
||||
User::factory()->create(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckoutAccessoryNotification::class);
|
||||
}
|
||||
|
||||
public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Accessory::factory()->create(),
|
||||
User::factory()->create(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckoutAccessoryNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider assetCheckoutTargets */
|
||||
public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Asset::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckoutAssetNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider assetCheckoutTargets */
|
||||
public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Asset::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckoutAssetNotification::class);
|
||||
}
|
||||
|
||||
public function testComponentCheckoutDoesNotSendSlackNotification()
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Component::factory()->create(),
|
||||
Asset::factory()->laptopMbp()->create(),
|
||||
);
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled()
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Consumable::factory()->create(),
|
||||
User::factory()->create(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckoutConsumableNotification::class);
|
||||
}
|
||||
|
||||
public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
Consumable::factory()->create(),
|
||||
User::factory()->create(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckoutConsumableNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider licenseCheckoutTargets */
|
||||
public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->enableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertSlackNotificationSent(CheckoutLicenseSeatNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider licenseCheckoutTargets */
|
||||
public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
$this->settings->disableSlackWebhook();
|
||||
|
||||
$this->fireCheckOutEvent(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
);
|
||||
|
||||
$this->assertNoSlackNotificationSent(CheckoutLicenseSeatNotification::class);
|
||||
}
|
||||
|
||||
private function fireCheckOutEvent(Model $checkoutable, Model $target)
|
||||
{
|
||||
event(new CheckoutableCheckedOut(
|
||||
$checkoutable,
|
||||
$target,
|
||||
User::factory()->superuser()->create(),
|
||||
'',
|
||||
));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user