mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 14:31:52 +01:00
Added some tests for listeners and updated workflows with secrets
This commit is contained in:
5
.github/workflows/laravel-dev.yml
vendored
5
.github/workflows/laravel-dev.yml
vendored
@@ -13,6 +13,11 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
- name: Update .env with secrets
|
||||
run: |
|
||||
echo SLACK_WEBHOOK=${{ secrets.SLACK_WEBHOOK }} >> .env
|
||||
echo TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} >> .env
|
||||
echo TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }} >> .env
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
- name: Create Database
|
||||
|
||||
5
.github/workflows/laravel-pr.yml
vendored
5
.github/workflows/laravel-pr.yml
vendored
@@ -13,6 +13,11 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
- name: Update .env with secrets
|
||||
run: |
|
||||
echo SLACK_WEBHOOK=${{ secrets.SLACK_WEBHOOK }} >> .env
|
||||
echo TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} >> .env
|
||||
echo TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }} >> .env
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
- name: Create Database
|
||||
|
||||
5
.github/workflows/laravel-stable.yml
vendored
5
.github/workflows/laravel-stable.yml
vendored
@@ -13,6 +13,11 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
- name: Update .env with secrets
|
||||
run: |
|
||||
echo SLACK_WEBHOOK=${{ secrets.SLACK_WEBHOOK }} >> .env
|
||||
echo TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} >> .env
|
||||
echo TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }} >> .env
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
- name: Create Database
|
||||
|
||||
127
tests/Unit/Listeners/SpeedtestCompleteListener/SlackTest.php
Normal file
127
tests/Unit/Listeners/SpeedtestCompleteListener/SlackTest.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
107
tests/Unit/Listeners/SpeedtestCompleteListener/TelegramTest.php
Normal file
107
tests/Unit/Listeners/SpeedtestCompleteListener/TelegramTest.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
18
tests/Unit/Listeners/SpeedtestFailedListener/SlackTest.php
Normal file
18
tests/Unit/Listeners/SpeedtestFailedListener/SlackTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestFailedListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SlackTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestFailedListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
18
tests/Unit/Listeners/SpeedtestOverviewListener/SlackTest.php
Normal file
18
tests/Unit/Listeners/SpeedtestOverviewListener/SlackTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestOverviewListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SlackTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Listeners\SpeedtestOverviewListener;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user