mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Consolidate some slack notification tests
This commit is contained in:
parent
c08164d864
commit
7d3719bf70
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Notifications;
|
|
||||||
|
|
||||||
use App\Events\CheckoutableCheckedIn;
|
|
||||||
use App\Events\CheckoutableCheckedOut;
|
|
||||||
use App\Models\Asset;
|
|
||||||
use App\Models\Component;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Support\Facades\Notification;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ComponentSlackTest extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
use InteractsWithSettings;
|
|
||||||
|
|
||||||
public function testComponentCheckoutDoesNotSendSlackNotification()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
|
|
||||||
$this->settings->enableSlackWebhook();
|
|
||||||
|
|
||||||
event(new CheckoutableCheckedOut(
|
|
||||||
Component::factory()->ramCrucial8()->create(),
|
|
||||||
Asset::factory()->laptopMbp()->create(),
|
|
||||||
User::factory()->superuser()->create(),
|
|
||||||
''
|
|
||||||
));
|
|
||||||
|
|
||||||
Notification::assertNothingSent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testComponentCheckinDoesNotSendSlackNotification()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
|
|
||||||
$this->settings->enableSlackWebhook();
|
|
||||||
|
|
||||||
event(new CheckoutableCheckedIn(
|
|
||||||
Component::factory()->ramCrucial8()->create(),
|
|
||||||
Asset::factory()->laptopMbp()->create(),
|
|
||||||
User::factory()->superuser()->create(),
|
|
||||||
''
|
|
||||||
));
|
|
||||||
|
|
||||||
Notification::assertNothingSent();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Notifications;
|
|
||||||
|
|
||||||
use App\Events\CheckoutableCheckedOut;
|
|
||||||
use App\Models\Consumable;
|
|
||||||
use App\Models\Setting;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Notifications\CheckoutConsumableNotification;
|
|
||||||
use Illuminate\Notifications\AnonymousNotifiable;
|
|
||||||
use Illuminate\Support\Facades\Notification;
|
|
||||||
use Tests\Support\InteractsWithSettings;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ConsumableSlackTest extends TestCase
|
|
||||||
{
|
|
||||||
use InteractsWithSettings;
|
|
||||||
|
|
||||||
public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
|
|
||||||
$this->settings->enableSlackWebhook();
|
|
||||||
|
|
||||||
event(new CheckoutableCheckedOut(
|
|
||||||
Consumable::factory()->cardstock()->create(),
|
|
||||||
User::factory()->create(),
|
|
||||||
User::factory()->superuser()->create(),
|
|
||||||
''
|
|
||||||
));
|
|
||||||
|
|
||||||
Notification::assertSentTo(
|
|
||||||
new AnonymousNotifiable,
|
|
||||||
CheckoutConsumableNotification::class,
|
|
||||||
function ($notification, $channels, $notifiable) {
|
|
||||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
|
|
||||||
$this->settings->disableSlackWebhook();
|
|
||||||
|
|
||||||
event(new CheckoutableCheckedOut(
|
|
||||||
Consumable::factory()->cardstock()->create(),
|
|
||||||
User::factory()->create(),
|
|
||||||
User::factory()->superuser()->create(),
|
|
||||||
''
|
|
||||||
));
|
|
||||||
|
|
||||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?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\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Notifications\CheckinAccessoryNotification;
|
||||||
|
use Illuminate\Notifications\AnonymousNotifiable;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Tests\Support\InteractsWithSettings;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SlackNotificationsUponCheckinTest extends TestCase
|
||||||
|
{
|
||||||
|
use InteractsWithSettings;
|
||||||
|
|
||||||
|
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->settings->enableSlackWebhook();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
Accessory::factory()->appleBtKeyboard()->create(),
|
||||||
|
User::factory()->create(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertSentTo(
|
||||||
|
new AnonymousNotifiable,
|
||||||
|
CheckinAccessoryNotification::class,
|
||||||
|
function ($notification, $channels, $notifiable) {
|
||||||
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->settings->disableSlackWebhook();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
Accessory::factory()->appleBtKeyboard()->create(),
|
||||||
|
User::factory()->create(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testComponentCheckinDoesNotSendSlackNotification()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->settings->enableSlackWebhook();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedIn(
|
||||||
|
Component::factory()->ramCrucial8()->create(),
|
||||||
|
Asset::factory()->laptopMbp()->create(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertNothingSent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConsumableCheckinSendSlackNotificationWhenSettingEnabled()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConsumableCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Notifications;
|
namespace Tests\Feature\Notifications\Webhooks;
|
||||||
|
|
||||||
use App\Events\CheckoutableCheckedIn;
|
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\Component;
|
||||||
|
use App\Models\Consumable;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\CheckinAccessoryNotification;
|
|
||||||
use App\Notifications\CheckoutAccessoryNotification;
|
use App\Notifications\CheckoutAccessoryNotification;
|
||||||
|
use App\Notifications\CheckoutConsumableNotification;
|
||||||
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;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AccessorySlackTest extends TestCase
|
class SlackNotificationsUponCheckoutTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
|
@ -56,14 +58,30 @@ class AccessorySlackTest extends TestCase
|
||||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
|
public function testComponentCheckoutDoesNotSendSlackNotification()
|
||||||
{
|
{
|
||||||
Notification::fake();
|
Notification::fake();
|
||||||
|
|
||||||
$this->settings->enableSlackWebhook();
|
$this->settings->enableSlackWebhook();
|
||||||
|
|
||||||
event(new CheckoutableCheckedIn(
|
event(new CheckoutableCheckedOut(
|
||||||
Accessory::factory()->appleBtKeyboard()->create(),
|
Component::factory()->ramCrucial8()->create(),
|
||||||
|
Asset::factory()->laptopMbp()->create(),
|
||||||
|
User::factory()->superuser()->create(),
|
||||||
|
''
|
||||||
|
));
|
||||||
|
|
||||||
|
Notification::assertNothingSent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->settings->enableSlackWebhook();
|
||||||
|
|
||||||
|
event(new CheckoutableCheckedOut(
|
||||||
|
Consumable::factory()->cardstock()->create(),
|
||||||
User::factory()->create(),
|
User::factory()->create(),
|
||||||
User::factory()->superuser()->create(),
|
User::factory()->superuser()->create(),
|
||||||
''
|
''
|
||||||
|
@ -71,26 +89,26 @@ class AccessorySlackTest extends TestCase
|
||||||
|
|
||||||
Notification::assertSentTo(
|
Notification::assertSentTo(
|
||||||
new AnonymousNotifiable,
|
new AnonymousNotifiable,
|
||||||
CheckinAccessoryNotification::class,
|
CheckoutConsumableNotification::class,
|
||||||
function ($notification, $channels, $notifiable) {
|
function ($notification, $channels, $notifiable) {
|
||||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
|
public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
|
||||||
{
|
{
|
||||||
Notification::fake();
|
Notification::fake();
|
||||||
|
|
||||||
$this->settings->disableSlackWebhook();
|
$this->settings->disableSlackWebhook();
|
||||||
|
|
||||||
event(new CheckoutableCheckedIn(
|
event(new CheckoutableCheckedOut(
|
||||||
Accessory::factory()->appleBtKeyboard()->create(),
|
Consumable::factory()->cardstock()->create(),
|
||||||
User::factory()->create(),
|
User::factory()->create(),
|
||||||
User::factory()->superuser()->create(),
|
User::factory()->superuser()->create(),
|
||||||
''
|
''
|
||||||
));
|
));
|
||||||
|
|
||||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
|
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue