Update slack_endpoint to webhook_endpoint in test and notification

This commit is contained in:
Marcus Moore 2023-03-22 12:27:36 -07:00
parent f6d0dd0f93
commit 9c4a3ce56a
No known key found for this signature in database
3 changed files with 13 additions and 32 deletions

View file

@ -41,8 +41,8 @@ class CheckoutableListener
if (! $event->checkedOutTo instanceof User) { if (! $event->checkedOutTo instanceof User) {
// @todo: comment // @todo: comment
if (Setting::getSettings() && Setting::getSettings()->slack_endpoint) { if (Setting::getSettings() && Setting::getSettings()->webhook_endpoint) {
Notification::route('slack', Setting::getSettings()->slack_endpoint) Notification::route('slack', Setting::getSettings()->webhook_endpoint)
->notify(new CheckoutAssetNotification( ->notify(new CheckoutAssetNotification(
$event->checkoutable, $event->checkoutable,
$event->checkedOutTo, $event->checkedOutTo,

View file

@ -53,7 +53,7 @@ class CheckoutAssetNotification extends Notification
{ {
$notifyBy = []; $notifyBy = [];
if ((Setting::getSettings()) && (Setting::getSettings()->slack_endpoint != '')) { if ((Setting::getSettings()) && (Setting::getSettings()->webhook_endpoint != '')) {
\Log::debug('use slack'); \Log::debug('use slack');
$notifyBy[] = 'slack'; $notifyBy[] = 'slack';
} }

View file

@ -3,8 +3,6 @@
namespace Tests\Feature\Notifications; namespace Tests\Feature\Notifications;
use App\Models\Asset; use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Location; use App\Models\Location;
use App\Models\Setting; use App\Models\Setting;
use App\Models\User; use App\Models\User;
@ -15,23 +13,15 @@ use Tests\TestCase;
class AssetCheckoutSlackNotificationTest extends TestCase class AssetCheckoutSlackNotificationTest extends TestCase
{ {
private Category $assetLaptopCategory;
private string $slackWebhookUrl = 'https://hooks.slack.com/services/NZ59O2F54K/Q4465WNLM8/672N8MU5JV15RP436WDHRN58'; private string $slackWebhookUrl = 'https://hooks.slack.com/services/NZ59O2F54K/Q4465WNLM8/672N8MU5JV15RP436WDHRN58';
protected function setUp(): void
{
parent::setUp();
$this->assetLaptopCategory = Category::factory()->assetLaptopCategory();
}
public function testNotificationSentToSlackWhenAssetCheckedOutToUserAndSlackNotificationEnabled() public function testNotificationSentToSlackWhenAssetCheckedOutToUserAndSlackNotificationEnabled()
{ {
Notification::fake(); Notification::fake();
Setting::factory()->create(['slack_endpoint' => $this->slackWebhookUrl]); Setting::factory()->create(['webhook_endpoint' => $this->slackWebhookUrl]);
$asset = $this->createAsset(); $asset = Asset::factory()->laptopMbp()->create();
$user = User::factory()->create(); $user = User::factory()->create();
$asset->checkOut( $asset->checkOut(
@ -52,11 +42,11 @@ class AssetCheckoutSlackNotificationTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->create(['slack_endpoint' => $this->slackWebhookUrl]); Setting::factory()->create(['webhook_endpoint' => $this->slackWebhookUrl]);
$assetBeingCheckedOut = $this->createAsset(); $assetBeingCheckedOut = Asset::factory()->laptopMbp()->create();
$assetBeingCheckedOut->checkOut( $assetBeingCheckedOut->checkOut(
$this->createAsset(), Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create()->id User::factory()->superuser()->create()->id
); );
@ -75,9 +65,9 @@ class AssetCheckoutSlackNotificationTest extends TestCase
{ {
Notification::fake(); Notification::fake();
$assetBeingCheckedOut = $this->createAsset(); $assetBeingCheckedOut = Asset::factory()->laptopMbp()->create();
$assetBeingCheckedOut->checkOut( $assetBeingCheckedOut->checkOut(
$this->createAsset(), Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create()->id User::factory()->superuser()->create()->id
); );
@ -91,9 +81,9 @@ class AssetCheckoutSlackNotificationTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->create(['slack_endpoint' => $this->slackWebhookUrl]); Setting::factory()->create(['webhook_endpoint' => $this->slackWebhookUrl]);
$asset = $this->createAsset(); $asset = Asset::factory()->laptopMbp()->create();
$asset->checkOut( $asset->checkOut(
Location::factory()->create(), Location::factory()->create(),
User::factory()->superuser()->create()->id User::factory()->superuser()->create()->id
@ -114,7 +104,7 @@ class AssetCheckoutSlackNotificationTest extends TestCase
{ {
Notification::fake(); Notification::fake();
$asset = $this->createAsset(); $asset = Asset::factory()->laptopMbp()->create();
$asset->checkOut( $asset->checkOut(
Location::factory()->create(), Location::factory()->create(),
User::factory()->superuser()->create()->id User::factory()->superuser()->create()->id
@ -125,13 +115,4 @@ class AssetCheckoutSlackNotificationTest extends TestCase
CheckoutAssetNotification::class, CheckoutAssetNotification::class,
); );
} }
private function createAsset()
{
return Asset::factory()->create([
'model_id' => AssetModel::factory()->create([
'category_id' => $this->assetLaptopCategory->id,
])->id,
]);
}
} }