Migrate to new test settings interface

This commit is contained in:
Marcus Moore 2023-04-17 17:31:12 -07:00
parent 2d56675ade
commit f6cff90829
No known key found for this signature in database
5 changed files with 44 additions and 14 deletions

View file

@ -11,15 +11,18 @@ use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckoutAccessoryNotification; use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase; use Tests\TestCase;
class AccessoryWebhookTest extends TestCase class AccessoryWebhookTest extends TestCase
{ {
use InteractsWithSettings;
public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled() public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled()
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(), Accessory::factory()->appleBtKeyboard()->create(),
@ -41,7 +44,7 @@ class AccessoryWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(), Accessory::factory()->appleBtKeyboard()->create(),
@ -57,7 +60,7 @@ class AccessoryWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedIn( event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(), Accessory::factory()->appleBtKeyboard()->create(),
@ -79,7 +82,7 @@ class AccessoryWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedIn( event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(), Accessory::factory()->appleBtKeyboard()->create(),

View file

@ -13,10 +13,13 @@ use App\Notifications\CheckoutAssetNotification;
use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase; use Tests\TestCase;
class AssetWebhookTest extends TestCase class AssetWebhookTest extends TestCase
{ {
use InteractsWithSettings;
public function checkoutTargets(): array public function checkoutTargets(): array
{ {
return [ return [
@ -40,7 +43,7 @@ class AssetWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
$this->createAsset(), $this->createAsset(),
@ -63,7 +66,7 @@ class AssetWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
$this->createAsset(), $this->createAsset(),
@ -80,7 +83,7 @@ class AssetWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedIn( event(new CheckoutableCheckedIn(
$this->createAsset(), $this->createAsset(),
@ -103,7 +106,7 @@ class AssetWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedIn( event(new CheckoutableCheckedIn(
$this->createAsset(), $this->createAsset(),

View file

@ -9,15 +9,18 @@ use App\Models\User;
use App\Notifications\CheckoutConsumableNotification; 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\TestCase; use Tests\TestCase;
class ConsumableWebhookTest extends TestCase class ConsumableWebhookTest extends TestCase
{ {
use InteractsWithSettings;
public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled() public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled()
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(), Consumable::factory()->cardstock()->create(),
@ -39,7 +42,7 @@ class ConsumableWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(), Consumable::factory()->cardstock()->create(),

View file

@ -12,10 +12,13 @@ use App\Notifications\CheckinLicenseSeatNotification;
use App\Notifications\CheckoutLicenseSeatNotification; use App\Notifications\CheckoutLicenseSeatNotification;
use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase; use Tests\TestCase;
class LicenseWebhookTest extends TestCase class LicenseWebhookTest extends TestCase
{ {
use InteractsWithSettings;
public function checkoutTargets(): array public function checkoutTargets(): array
{ {
return [ return [
@ -29,7 +32,7 @@ class LicenseWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
LicenseSeat::factory()->create(), LicenseSeat::factory()->create(),
@ -52,7 +55,7 @@ class LicenseWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedOut( event(new CheckoutableCheckedOut(
LicenseSeat::factory()->create(), LicenseSeat::factory()->create(),
@ -69,7 +72,7 @@ class LicenseWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookEnabled()->create(); $this->settings->enableWebhook();
event(new CheckoutableCheckedIn( event(new CheckoutableCheckedIn(
LicenseSeat::factory()->create(), LicenseSeat::factory()->create(),
@ -92,7 +95,7 @@ class LicenseWebhookTest extends TestCase
{ {
Notification::fake(); Notification::fake();
Setting::factory()->withWebhookDisabled()->create(); $this->settings->disableWebhook();
event(new CheckoutableCheckedIn( event(new CheckoutableCheckedIn(
LicenseSeat::factory()->create(), LicenseSeat::factory()->create(),

View file

@ -23,6 +23,24 @@ class Settings
return $this->update(['full_multiple_companies_support' => 1]); return $this->update(['full_multiple_companies_support' => 1]);
} }
public function enableWebhook(): Settings
{
return $this->update([
'webhook_botname' => 'SnipeBot5000',
'webhook_endpoint' => 'https://hooks.slack.com/services/NZ59/Q446/672N',
'webhook_channel' => '#it',
]);
}
public function disableWebhook(): Settings
{
return $this->update([
'webhook_botname' => '',
'webhook_endpoint' => '',
'webhook_channel' => '',
]);
}
/** /**
* @param array $attributes Attributes to modify in the application's settings. * @param array $attributes Attributes to modify in the application's settings.
*/ */