mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Use factory state for webhook settings
This commit is contained in:
parent
9c4a3ce56a
commit
66224765ea
|
@ -43,4 +43,13 @@ class SettingFactory extends Factory
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withWebhookEnabled()
|
||||||
|
{
|
||||||
|
return $this->state(fn() => [
|
||||||
|
'webhook_botname' => 'SnipeBot5000',
|
||||||
|
'webhook_endpoint' => 'https://hooks.slack.com/services/NZ59/Q446/672N',
|
||||||
|
'webhook_channel' => '#it',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,11 @@ use Tests\TestCase;
|
||||||
|
|
||||||
class AssetCheckoutSlackNotificationTest extends TestCase
|
class AssetCheckoutSlackNotificationTest extends TestCase
|
||||||
{
|
{
|
||||||
private string $slackWebhookUrl = 'https://hooks.slack.com/services/NZ59O2F54K/Q4465WNLM8/672N8MU5JV15RP436WDHRN58';
|
|
||||||
|
|
||||||
public function testNotificationSentToSlackWhenAssetCheckedOutToUserAndSlackNotificationEnabled()
|
public function testNotificationSentToSlackWhenAssetCheckedOutToUserAndSlackNotificationEnabled()
|
||||||
{
|
{
|
||||||
Notification::fake();
|
Notification::fake();
|
||||||
|
|
||||||
Setting::factory()->create(['webhook_endpoint' => $this->slackWebhookUrl]);
|
Setting::factory()->withWebhookEnabled()->create();
|
||||||
|
|
||||||
$asset = Asset::factory()->laptopMbp()->create();
|
$asset = Asset::factory()->laptopMbp()->create();
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
|
@ -42,7 +40,7 @@ class AssetCheckoutSlackNotificationTest extends TestCase
|
||||||
{
|
{
|
||||||
Notification::fake();
|
Notification::fake();
|
||||||
|
|
||||||
Setting::factory()->create(['webhook_endpoint' => $this->slackWebhookUrl]);
|
Setting::factory()->withWebhookEnabled()->create();
|
||||||
|
|
||||||
$assetBeingCheckedOut = Asset::factory()->laptopMbp()->create();
|
$assetBeingCheckedOut = Asset::factory()->laptopMbp()->create();
|
||||||
$assetBeingCheckedOut->checkOut(
|
$assetBeingCheckedOut->checkOut(
|
||||||
|
@ -56,7 +54,7 @@ class AssetCheckoutSlackNotificationTest extends TestCase
|
||||||
new AnonymousNotifiable,
|
new AnonymousNotifiable,
|
||||||
CheckoutAssetNotification::class,
|
CheckoutAssetNotification::class,
|
||||||
function ($notification, $channels, $notifiable) {
|
function ($notification, $channels, $notifiable) {
|
||||||
return $notifiable->routes['slack'] === $this->slackWebhookUrl;
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +79,7 @@ class AssetCheckoutSlackNotificationTest extends TestCase
|
||||||
{
|
{
|
||||||
Notification::fake();
|
Notification::fake();
|
||||||
|
|
||||||
Setting::factory()->create(['webhook_endpoint' => $this->slackWebhookUrl]);
|
Setting::factory()->withWebhookEnabled()->create();
|
||||||
|
|
||||||
$asset = Asset::factory()->laptopMbp()->create();
|
$asset = Asset::factory()->laptopMbp()->create();
|
||||||
$asset->checkOut(
|
$asset->checkOut(
|
||||||
|
@ -95,7 +93,7 @@ class AssetCheckoutSlackNotificationTest extends TestCase
|
||||||
new AnonymousNotifiable,
|
new AnonymousNotifiable,
|
||||||
CheckoutAssetNotification::class,
|
CheckoutAssetNotification::class,
|
||||||
function ($notification, $channels, $notifiable) {
|
function ($notification, $channels, $notifiable) {
|
||||||
return $notifiable->routes['slack'] === $this->slackWebhookUrl;
|
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue