mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 06:28:27 +01:00
Updated files to v1.9.4
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Speedtest Tracker
|
||||
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
|
||||
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses [Ookla's Speedtest cli](https://www.speedtest.net/apps/cli) to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Speedtest Tracker
|
||||
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
|
||||
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
||||
|
||||
|
||||
@@ -172,4 +172,25 @@ class SettingsHelper {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function loadIntegrationConfig()
|
||||
{
|
||||
$settings = [
|
||||
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
|
||||
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
|
||||
'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
|
||||
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
|
||||
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
|
||||
];
|
||||
|
||||
foreach($settings as $key => $value) {
|
||||
$key = 'integrations.' . $key;
|
||||
|
||||
if($value === "") {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
config()->set([ $key => $value ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,8 +263,12 @@ class SpeedtestHelper {
|
||||
if(env('DB_CONNECTION') === 'sqlite') {
|
||||
if(env('DB_DATABASE') !== null) {
|
||||
$current = env('DB_DATABASE');
|
||||
if(File::copy($current, $current . '.bak')) {
|
||||
return true;
|
||||
try {
|
||||
if(File::copy($current, $current . '.bak')) {
|
||||
return true;
|
||||
}
|
||||
}catch(Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,23 +287,18 @@ class SpeedtestHelper {
|
||||
{
|
||||
Cache::flush();
|
||||
|
||||
if(SpeedtestHelper::dbBackup() !== false) {
|
||||
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
|
||||
if(Speedtest::whereNotNull('id')->delete()) {
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
SpeedtestHelper::dbBackup();
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
|
||||
if(Speedtest::whereNotNull('id')->delete()) {
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'msg' => 'There was an error backing up the database. No speedtests have been deleted.'
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -30,17 +30,17 @@ class IntegrationsController extends Controller
|
||||
$methodResp = 'test healthchecks \'' . $method . '\' endpoint';
|
||||
|
||||
try {
|
||||
$hc = new Healthchecks(config('integrations.healthchecks_uuid'));
|
||||
// SettingsHelper::loadIntegrationConfig();
|
||||
if($method == 'success') {
|
||||
$hc->success();
|
||||
Healthcheck::success();
|
||||
}
|
||||
|
||||
if($method == 'fail') {
|
||||
$hc->fail();
|
||||
Healthcheck::fail();
|
||||
}
|
||||
|
||||
if($method == 'start') {
|
||||
$hc->start();
|
||||
Healthcheck::start();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
@@ -78,7 +78,7 @@ class IntegrationsController extends Controller
|
||||
SettingsHelper::testNotification();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'test notificaiton agents'
|
||||
'method' => 'test notification agents'
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ class SpeedtestController extends Controller
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
SettingsHelper::loadIntegrationConfig();
|
||||
$data = SpeedtestJob::dispatch(false, config('integrations'));
|
||||
return response()->json([
|
||||
'method' => 'run speedtest',
|
||||
|
||||
@@ -37,28 +37,12 @@ class IntegrationsServiceProvider extends ServiceProvider
|
||||
{
|
||||
if(File::exists(env('DB_DATABASE'))) {
|
||||
if(Schema::hasTable('settings')) {
|
||||
$settings = [
|
||||
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
|
||||
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
|
||||
'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
|
||||
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
|
||||
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
|
||||
];
|
||||
$setting = SettingsHelper::get('healthchecks_uuid');
|
||||
|
||||
foreach($settings as $key => $value) {
|
||||
$key = 'integrations.' . $key;
|
||||
|
||||
if($value === "") {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
config()->set([ $key => $value ]);
|
||||
}
|
||||
|
||||
if($settings['healthchecks_enabled']) {
|
||||
if($setting !== false) {
|
||||
try {
|
||||
App::bind('healthcheck', function() use ($settings) {
|
||||
return new Healthchecks($settings['healthchecks_uuid']);
|
||||
App::bind('healthcheck', function() use ($setting) {
|
||||
return new Healthchecks($setting->value);
|
||||
});
|
||||
} catch(InvalidUuidStringException $e) {
|
||||
Log::error('Invalid healthchecks UUID');
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
{
|
||||
"1.9.4": [
|
||||
{
|
||||
"description": "Changed integration config loading.",
|
||||
"link": ""
|
||||
}.
|
||||
{
|
||||
"description": "Added more tests.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.3": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
|
||||
@@ -7,7 +7,7 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'version' => '1.9.3',
|
||||
'version' => '1.9.4',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
21
conf/site/tests/Feature/Commands/AcceptEULACommandTest.php
Normal file
21
conf/site/tests/Feature/Commands/AcceptEULACommandTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AcceptEULACommandTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAcceptEULA()
|
||||
{
|
||||
$response = $this->artisan('speedtest:eula')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
21
conf/site/tests/Feature/Commands/AppVersionTest.php
Normal file
21
conf/site/tests/Feature/Commands/AppVersionTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AppVersionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test the version CLI command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testVersionCommand()
|
||||
{
|
||||
$response = $this->artisan('speedtest:version')
|
||||
->expectsOutput('Speedtest Tracker v' . config('speedtest.version'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Console\Commands\AuthenticationCommand;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Artisan;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Enable app auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnableAuth()
|
||||
{
|
||||
SettingsHelper::set('auth', false);
|
||||
|
||||
$this->assertEquals(Artisan::call('speedtest:auth', [ '--enable' => true ]), 0);
|
||||
|
||||
$this->assertTrue((bool)SettingsHelper::get('auth')->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable app auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisableAuth()
|
||||
{
|
||||
SettingsHelper::set('auth', true);
|
||||
|
||||
$this->assertEquals(Artisan::call('speedtest:auth', [ '--disable' => true ]), 0);
|
||||
|
||||
$this->assertFalse((bool)SettingsHelper::get('auth')->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid params for command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function testAuthBothOptions()
|
||||
// {
|
||||
// $command = new AuthenticationCommand();
|
||||
// $command->setLaravel($this->app);
|
||||
// $tester = new CommandTester($command);
|
||||
// $tester->setInputs([]);
|
||||
// $tester->execute([ '--enable' => true, '--disable' => true ]);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Test invalid params for command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function testAuthNoOptions()
|
||||
// {
|
||||
// $command = new AuthenticationCommand();
|
||||
// $command->setLaravel($this->app);
|
||||
// $tester = new CommandTester($command);
|
||||
// $tester->setInputs([]);
|
||||
// $tester->execute([]);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClearOldSessionCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClearSessionsCommand()
|
||||
{
|
||||
$this->artisan('speedtest:clear-sessions')
|
||||
->expectsOutput('Invalidated expired sessions')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
23
conf/site/tests/Feature/Commands/ClearQueueCommandTest.php
Normal file
23
conf/site/tests/Feature/Commands/ClearQueueCommandTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClearQueueCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClearQueue()
|
||||
{
|
||||
$this->artisan('queue:clear')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
27
conf/site/tests/Feature/Commands/GetConfigCommandTest.php
Normal file
27
conf/site/tests/Feature/Commands/GetConfigCommandTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GetConfigCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetConfig()
|
||||
{
|
||||
$configJson = json_encode(SettingsHelper::getConfig(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$this->artisan('speedtest:config')
|
||||
->expectsOutput($configJson)
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SetSlackWebhookCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSlackWebhook()
|
||||
{
|
||||
SettingsHelper::set('slack_webhook', 'pre-test');
|
||||
|
||||
$this->artisan('speedtest:slack', [ 'webhook' => 'test' ])
|
||||
->expectsOutput('Slack webhook updated')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertEquals(SettingsHelper::get('slack_webhook')->value, 'test');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SetTelegramOptionsCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetTelegramOptions()
|
||||
{
|
||||
SettingsHelper::set('telegram_bot_token', 'pre-test-bot');
|
||||
SettingsHelper::set('telegram_chat_id', 'pre-test-bot');
|
||||
|
||||
$this->artisan('speedtest:telegram', [
|
||||
'--bot' => 'test-bot',
|
||||
'--chat' => 'test-chat'
|
||||
])->expectsOutput('Telegram options updated')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertEquals(SettingsHelper::get('telegram_bot_token')->value, 'test-bot');
|
||||
$this->assertEquals(SettingsHelper::get('telegram_chat_id')->value, 'test-chat');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpeedtestOverviewCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOverviewCommand()
|
||||
{
|
||||
$this->artisan('speedtest:overview')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TestNotificationCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestNotificationCommand()
|
||||
{
|
||||
$this->artisan('speedtest:notification')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\IntegrationsController;
|
||||
|
||||
use App;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Http\Controllers\IntegrationsController;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HealthcheckTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Controller
|
||||
*
|
||||
* @var IntegrationsController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
private $uuid;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new IntegrationsController();
|
||||
|
||||
$this->uuid = env('HEALTHCHECKS_UUID');
|
||||
$this->bindFacade($this->uuid);
|
||||
}
|
||||
|
||||
public function testStartPing()
|
||||
{
|
||||
$resp = $this->controller->testHealthchecks('start')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'start\' endpoint',
|
||||
'success' => true
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testSuccessPing()
|
||||
{
|
||||
$resp = $this->controller->testHealthchecks('success')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'success\' endpoint',
|
||||
'success' => true
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testFailPing()
|
||||
{
|
||||
$resp = $this->controller->testHealthchecks('fail')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'fail\' endpoint',
|
||||
'success' => true
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testInvalidUUID()
|
||||
{
|
||||
$this->bindFacade('test');
|
||||
|
||||
$resp = $this->controller->testHealthchecks('start')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'start\' endpoint',
|
||||
'success' => false,
|
||||
'error' => 'Invalid UUID'
|
||||
], $resp);
|
||||
|
||||
$this->bindFacade($this->uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* As clean install before setting up, there is no healthchecks
|
||||
* uuid in the db, so the facade doesn't get created during boot,
|
||||
* now just bind it in the container on test setup
|
||||
*
|
||||
* @param String $uuid
|
||||
* @return void
|
||||
*/
|
||||
private function bindFacade(String $uuid)
|
||||
{
|
||||
App::bind('healthcheck', function() use ($uuid) {
|
||||
return new Healthchecks($uuid);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\IntegrationsController;
|
||||
|
||||
use App\Http\Controllers\IntegrationsController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotificationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Controller
|
||||
*
|
||||
* @var IntegrationsController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new IntegrationsController();
|
||||
}
|
||||
|
||||
public function testNotificationsTest()
|
||||
{
|
||||
$resp = $this->controller->testNotification()->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test notification agents'
|
||||
], $resp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Speedtest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testDeleteAll()
|
||||
{
|
||||
for($i = 0; $i < 5; $i++) {
|
||||
Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertEquals(5, Speedtest::count());
|
||||
|
||||
$resp = $this->controller->deleteAll()->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('success', $resp);
|
||||
|
||||
$this->assertEquals(0, Speedtest::count());
|
||||
}
|
||||
|
||||
public function testDeleteSpecific()
|
||||
{
|
||||
$test = Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
$id = $test->id;
|
||||
|
||||
$this->assertNotNull(Speedtest::find($id));
|
||||
|
||||
$resp = $this->controller->delete($test)->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('success', $resp);
|
||||
|
||||
$this->assertNull(Speedtest::find($id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FailTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testFail()
|
||||
{
|
||||
$resp = $this->controller->fail(5)->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('days', $resp);
|
||||
}
|
||||
|
||||
public function testFailInvalidInput()
|
||||
{
|
||||
$resp = $this->controller->fail('test')->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('error', $resp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$resp = $this->controller->index()->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Speedtest;
|
||||
use DB;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LatestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testLatestNoEntries()
|
||||
{
|
||||
DB::table('speedtests')->delete();
|
||||
|
||||
$resp = $this->controller->latest();
|
||||
$resp = $resp->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'get latest speedtest',
|
||||
'error' => 'no speedtests have been run'
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testLatest()
|
||||
{
|
||||
$test = Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
$test = $test->attributesToArray();
|
||||
|
||||
$resp = $this->controller->latest();
|
||||
$resp = $resp->original;
|
||||
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('average', $resp);
|
||||
$this->assertArrayHasKey('max', $resp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Jobs\SpeedtestJob;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RunTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$resp = $this->controller->run()->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
|
||||
Queue::assertPushed(SpeedtestJob::class, function($job) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TimeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
{
|
||||
$resp = $this->controller->time(5)->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('days', $resp);
|
||||
}
|
||||
|
||||
public function testTimeInvalidInput()
|
||||
{
|
||||
$resp = $this->controller->time('test')->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('error', $resp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\NotificationsHelper;
|
||||
|
||||
use App\Helpers\NotificationsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ThresholdMessageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteMessageMultiField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage([ 'ping', 'upload' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping, upload values exceeded the absolute threshold', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteMessageSingleField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage([ 'ping' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping value exceeded the absolute threshold', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPercentageMessageMultiField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatPercentageThresholdMessage([ 'ping', 'upload' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping, upload values exceeded the percentage threshold', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPercentageMessageSingleField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatPercentageThresholdMessage([ 'ping' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping value exceeded the percentage threshold', $msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SettingsHelper;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingsGetTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidSetting()
|
||||
{
|
||||
$response = SettingsHelper::get('auth');
|
||||
|
||||
$this->assertNotFalse($response);
|
||||
$this->assertFalse((bool)$response->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidSetting()
|
||||
{
|
||||
$response = SettingsHelper::get('test');
|
||||
|
||||
$this->assertFalse($response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SettingsHelper;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingsLoadIntegrationsConfigTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadIntegrationsConfig()
|
||||
{
|
||||
$preLoad = [
|
||||
"healthchecks_enabled" => false,
|
||||
"healthchecks_uuid" => null,
|
||||
"slack_webhook" => null,
|
||||
"telegram_bot_token" => null,
|
||||
"telegram_chat_id" => null,
|
||||
];
|
||||
|
||||
SettingsHelper::set('slack_webhook', 'test');
|
||||
|
||||
SettingsHelper::loadIntegrationConfig();
|
||||
|
||||
$this->assertEquals(config('integrations.slack_webhook'), 'test');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SettingsHelper;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingsSetTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdatingSetting()
|
||||
{
|
||||
$response = SettingsHelper::set('auth', 'hello');
|
||||
|
||||
$this->assertEquals('hello', $response->value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Speedtest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use InvalidArgumentException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AbsoluteThresholdTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteDownloadThresholdExceeded()
|
||||
{
|
||||
$threshold = 10;
|
||||
$dl = 5;
|
||||
|
||||
SettingsHelper::set('threshold_alert_absolute_download', $threshold);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => $dl,
|
||||
'upload' => 11,
|
||||
'ping' => 5
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('absolute', $test);
|
||||
|
||||
$this->assertEquals([ 'download' ], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteDownloadThresholdNotExceeded()
|
||||
{
|
||||
$threshold = 1;
|
||||
$dl = 5;
|
||||
|
||||
SettingsHelper::set('threshold_alert_absolute_download', $threshold);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => $dl,
|
||||
'upload' => 11,
|
||||
'ping' => 5
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('absolute', $test);
|
||||
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteUploadThresholdExceeded()
|
||||
{
|
||||
$threshold = 10;
|
||||
$ul = 5;
|
||||
|
||||
SettingsHelper::set('threshold_alert_absolute_upload', $threshold);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => 11,
|
||||
'upload' => $ul,
|
||||
'ping' => 5
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('absolute', $test);
|
||||
|
||||
$this->assertEquals([ 'upload' ], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteUploadThresholdNotExceeded()
|
||||
{
|
||||
$threshold = 1;
|
||||
$ul = 5;
|
||||
|
||||
SettingsHelper::set('threshold_alert_absolute_upload', $threshold);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => 11,
|
||||
'upload' => $ul,
|
||||
'ping' => 5
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('absolute', $test);
|
||||
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsolutePingThresholdExceeded()
|
||||
{
|
||||
$threshold = 10;
|
||||
$ping = 11;
|
||||
|
||||
SettingsHelper::set('threshold_alert_absolute_ping', $threshold);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => 10,
|
||||
'upload' => 10,
|
||||
'ping' => $ping
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('absolute', $test);
|
||||
|
||||
$this->assertEquals([ 'ping' ], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsolutePingThresholdNotExceeded()
|
||||
{
|
||||
$threshold = 10;
|
||||
$ping = 9;
|
||||
|
||||
SettingsHelper::set('threshold_alert_absolute_ping', $threshold);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => 10,
|
||||
'upload' => 10,
|
||||
'ping' => $ping
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('absolute', $test);
|
||||
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidArgument()
|
||||
{
|
||||
try {
|
||||
SpeedtestHelper::testIsLowerThanThreshold('test', new Speedtest());
|
||||
} catch(InvalidArgumentException $e) {
|
||||
$this->assertTrue(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CheckOutputTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGoodOutput()
|
||||
{
|
||||
$expected = [
|
||||
'type' => 'result',
|
||||
'download' => [ 'bandwidth' => '*' ],
|
||||
'upload' => [ 'bandwidth' => '*' ],
|
||||
'ping' => [ 'latency' => '*' ],
|
||||
'server' => [
|
||||
'id' => '*',
|
||||
'name' => '*',
|
||||
'host' => '*',
|
||||
'port' => '*',
|
||||
],
|
||||
'result' => [
|
||||
'url' => '*',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertTrue(SpeedtestHelper::checkOutputIsComplete($expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBadOutput()
|
||||
{
|
||||
$expected = [
|
||||
'type' => 'result',
|
||||
'download' => [ 'bandwidth' => '*' ],
|
||||
'server' => [
|
||||
'id' => '*',
|
||||
'name' => '*',
|
||||
'host' => '*',
|
||||
'port' => '*',
|
||||
],
|
||||
'result' => [
|
||||
'url' => '*',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertFalse(SpeedtestHelper::checkOutputIsComplete($expected));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Speedtest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FailureRateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFailureRate()
|
||||
{
|
||||
$success = rand(1, 15);
|
||||
$failed = rand(1, 15);
|
||||
|
||||
for($i = 0; $i < $success; $i++) {
|
||||
Speedtest::create([
|
||||
'ping' => 5,
|
||||
'download' => 5,
|
||||
'upload' => 5
|
||||
]);
|
||||
}
|
||||
|
||||
for($i = 0; $i < $failed; $i++) {
|
||||
Speedtest::create([
|
||||
'ping' => 5,
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'failed' => true
|
||||
]);
|
||||
}
|
||||
|
||||
$output = SpeedtestHelper::failureRate(1);
|
||||
|
||||
$this->assertEquals($output[0]['success'], $success);
|
||||
$this->assertEquals($output[0]['failure'], $failed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParseUnitsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMbyteToMb()
|
||||
{
|
||||
$initial = '80 Mbyte';
|
||||
$expected = 640;
|
||||
|
||||
$result = SpeedtestHelper::parseUnits($initial);
|
||||
|
||||
$this->assertEquals($expected, $result['val']);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKbitToMb()
|
||||
{
|
||||
$initial = '80 Kbit';
|
||||
$expected = 0.08;
|
||||
|
||||
$result = SpeedtestHelper::parseUnits($initial);
|
||||
|
||||
$this->assertEquals($expected, $result['val']);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testKbyteToMb()
|
||||
{
|
||||
$initial = '80 Kbyte';
|
||||
$expected = 0.64;
|
||||
|
||||
$result = SpeedtestHelper::parseUnits($initial);
|
||||
|
||||
$this->assertEquals($expected, $result['val']);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMbToMb()
|
||||
{
|
||||
$initial = '80 Mbit';
|
||||
$expected = 80;
|
||||
|
||||
$result = SpeedtestHelper::parseUnits($initial);
|
||||
|
||||
$this->assertEquals($expected, $result['val']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Speedtest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PercentageThresholdTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createAverageOf5();
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPercentageThresholdDownloadExceeded()
|
||||
{
|
||||
SettingsHelper::set('threshold_alert_percentage', 15);
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => 5 * 0.8,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('percentage', $test);
|
||||
|
||||
$this->assertEquals([ 'download' ], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testThresholdNotSet()
|
||||
{
|
||||
SettingsHelper::set('threshold_alert_percentage', '');
|
||||
|
||||
$test = Speedtest::create([
|
||||
'download' => 5 * 0.9,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
|
||||
$result = SpeedtestHelper::testIsLowerThanThreshold('percentage', $test);
|
||||
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
private function createAverageOf5()
|
||||
{
|
||||
for($i = 0; $i < 5; $i++) {
|
||||
Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpeedtestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private $output;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->output = SpeedtestHelper::output();
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOutputFunction()
|
||||
{
|
||||
$this->assertJson($this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRunSpeedtestWithExistingOutput()
|
||||
{
|
||||
$output = json_decode($this->output, true);
|
||||
|
||||
$test = SpeedtestHelper::runSpeedtest($this->output);
|
||||
|
||||
$this->assertEquals($output['ping']['latency'], $test->ping);
|
||||
$this->assertEquals(SpeedtestHelper::convert($output['download']['bandwidth']), $test->download);
|
||||
$this->assertEquals(SpeedtestHelper::convert($output['upload']['bandwidth']), $test->upload);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvaidJson()
|
||||
{
|
||||
$json = '{hi: hi}';
|
||||
|
||||
$o = SpeedtestHelper::runSpeedtest($json);
|
||||
|
||||
$this->assertFalse($o);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncompleteJson()
|
||||
{
|
||||
$json = '{"hi": "hi"}';
|
||||
|
||||
$o = SpeedtestHelper::runSpeedtest($json);
|
||||
|
||||
$this->assertFalse($o);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestCompleteListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\SpeedtestCompleteListener;
|
||||
use App\Speedtest;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SlackTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSlackSpeedtestNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', true);
|
||||
SettingsHelper::set('slack_webhook', env('SLACK_WEBHOOK'));
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidSlackWebhook()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', true);
|
||||
SettingsHelper::set('slack_webhook', 'invalid');
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSlackPercentageThresholdNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', false);
|
||||
SettingsHelper::set('slack_webhook', env('SLACK_WEBHOOK'));
|
||||
SettingsHelper::set('threshold_alert_percentage_notifications', 1);
|
||||
Speedtest::create([ 'download' => 50, 'upload' => 50, 'ping' => 1 ]);
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSlackAbsoluteThresholdNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', false);
|
||||
SettingsHelper::set('slack_webhook', env('SLACK_WEBHOOK'));
|
||||
SettingsHelper::set('threshold_alert_absolute_notifications', 1);
|
||||
SettingsHelper::set('threshold_alert_absolute_download', 50);
|
||||
SettingsHelper::set('threshold_alert_absolute_upload', 50);
|
||||
SettingsHelper::set('threshold_alert_absolute_ping', 1);
|
||||
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestCompleteListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\SpeedtestCompleteListener;
|
||||
use App\Speedtest;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelegramSpeedtestNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', true);
|
||||
SettingsHelper::set('telegram_bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
SettingsHelper::set('telegram_chat_id', env('TELEGRAM_CHAT_ID'));
|
||||
SettingsHelper::set('slack_webhook', false);
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelegramPercentageThresholdNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', false);
|
||||
SettingsHelper::set('telegram_bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
SettingsHelper::set('telegram_chat_id', env('TELEGRAM_CHAT_ID'));
|
||||
SettingsHelper::set('slack_webhook', false);
|
||||
SettingsHelper::set('threshold_alert_percentage_notifications', 1);
|
||||
Speedtest::create([ 'download' => 50, 'upload' => 50, 'ping' => 1 ]);
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelegramAbsoluteThresholdNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', false);
|
||||
SettingsHelper::set('telegram_bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
SettingsHelper::set('telegram_chat_id', env('TELEGRAM_CHAT_ID'));
|
||||
SettingsHelper::set('slack_webhook', false);
|
||||
SettingsHelper::set('threshold_alert_absolute_notifications', 1);
|
||||
SettingsHelper::set('threshold_alert_absolute_download', 50);
|
||||
SettingsHelper::set('threshold_alert_absolute_upload', 50);
|
||||
SettingsHelper::set('threshold_alert_absolute_ping', 1);
|
||||
|
||||
|
||||
$l = new SpeedtestCompleteListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5 ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestFailedListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\SpeedtestFailedListener;
|
||||
use App\Speedtest;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SlackTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSlackFailedNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', true);
|
||||
SettingsHelper::set('slack_webhook', env('SLACK_WEBHOOK'));
|
||||
|
||||
$l = new SpeedtestFailedListener();
|
||||
$test = Speedtest::create([ 'download' => 0, 'upload' => 0, 'ping' => 0, 'failed' => true ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestFailedListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\SpeedtestFailedListener;
|
||||
use App\Speedtest;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelegramFailedNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_notifications', true);
|
||||
SettingsHelper::set('telegram_bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
SettingsHelper::set('telegram_chat_id', env('TELEGRAM_CHAT_ID'));
|
||||
SettingsHelper::set('slack_webhook', false);
|
||||
|
||||
$l = new SpeedtestFailedListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5, 'failed' => true ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestOverviewListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\SpeedtestOverviewListener;
|
||||
use App\Speedtest;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SlackTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSlackOverviewNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_overview_notification', true);
|
||||
SettingsHelper::set('slack_webhook', env('SLACK_WEBHOOK'));
|
||||
|
||||
$l = new SpeedtestOverviewListener();
|
||||
|
||||
$event = new stdClass();
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestOverviewListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\SpeedtestOverviewListener;
|
||||
use App\Speedtest;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelegramOverviewNotification()
|
||||
{
|
||||
SettingsHelper::set('speedtest_overview_notification', true);
|
||||
SettingsHelper::set('telegram_bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
SettingsHelper::set('telegram_chat_id', env('TELEGRAM_CHAT_ID'));
|
||||
SettingsHelper::set('slack_webhook', false);
|
||||
|
||||
$l = new SpeedtestOverviewListener();
|
||||
$test = Speedtest::create([ 'download' => 5, 'upload' => 5, 'ping' => 5, 'failed' => true ]);
|
||||
|
||||
$event = new stdClass();
|
||||
$event->speedtest = $test;
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\TestNotificationListener;
|
||||
|
||||
use App\Events\TestNotificationEvent;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\TestNotificationListener;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SlackTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSlackTest()
|
||||
{
|
||||
SettingsHelper::set('slack_webhook', env('SLACK_WEBHOOK'));
|
||||
|
||||
$l = new TestNotificationListener();
|
||||
|
||||
$event = new stdClass();
|
||||
$event->agents = [ 'slack' ];
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\TestNotificationListener;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Listeners\TestNotificationListener;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelegramTest()
|
||||
{
|
||||
SettingsHelper::set('telegram_bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
SettingsHelper::set('telegram_chat_id', env('TELEGRAM_CHAT_ID'));
|
||||
SettingsHelper::set('slack_webhook', false);
|
||||
|
||||
$l = new TestNotificationListener();
|
||||
|
||||
$event = new stdClass();
|
||||
$event->agents = [ 'telegram' ];
|
||||
|
||||
try {
|
||||
$l->handle($event);
|
||||
} catch(Exception $e) {
|
||||
$this->assertTrue(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user