mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
fix notification chanels and more tests (#108)
* fix notification chanels and more tests * fix code style
This commit is contained in:
87
tests/Unit/NotificationChannels/DiscordTest.php
Normal file
87
tests/Unit/NotificationChannels/DiscordTest.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\NotificationChannels;
|
||||
|
||||
use App\Models\NotificationChannel;
|
||||
use App\NotificationChannels\Discord;
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DiscordTest extends TestCase
|
||||
{
|
||||
public function test_create_rules(): void
|
||||
{
|
||||
$provider = new Discord(NotificationChannel::factory()->create([
|
||||
'provider' => 'discord',
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'webhook_url' => 'required|url',
|
||||
], $provider->createRules([]));
|
||||
}
|
||||
|
||||
public function test_create_data(): void
|
||||
{
|
||||
$provider = new Discord(NotificationChannel::factory()->create([
|
||||
'provider' => 'discord',
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'webhook_url' => 'https://discord.com/xxxxx',
|
||||
], $provider->createData([
|
||||
'webhook_url' => 'https://discord.com/xxxxx',
|
||||
]));
|
||||
}
|
||||
|
||||
public function test_data(): void
|
||||
{
|
||||
$provider = new Discord(NotificationChannel::factory()->create([
|
||||
'provider' => 'discord',
|
||||
'data' => [
|
||||
'webhook_url' => 'https://discord.com/xxxxx',
|
||||
],
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'webhook_url' => 'https://discord.com/xxxxx',
|
||||
], $provider->data());
|
||||
}
|
||||
|
||||
public function test_connect(): void
|
||||
{
|
||||
$provider = new Discord(NotificationChannel::factory()->create([
|
||||
'provider' => 'discord',
|
||||
'data' => [
|
||||
'webhook_url' => 'https://discord.com/xxxxx',
|
||||
],
|
||||
]));
|
||||
|
||||
Http::fake();
|
||||
|
||||
$this->assertTrue($provider->connect());
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return $request->url() === 'https://discord.com/xxxxx';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_send(): void
|
||||
{
|
||||
$channel = NotificationChannel::factory()->create([
|
||||
'provider' => 'discord',
|
||||
'data' => [
|
||||
'webhook_url' => 'https://discord.com/xxxxx',
|
||||
],
|
||||
]);
|
||||
$provider = new Discord($channel);
|
||||
|
||||
Http::fake();
|
||||
|
||||
$provider->send($channel, new TestNotification());
|
||||
|
||||
Http::assertSent(function (Request $request) {
|
||||
return $request->body() === '{"content":"Hello"}';
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user