mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 06:28:27 +01:00
Added more tests and fixed changelog
This commit is contained in:
58
tests/Unit/Controllers/SpeedtestController/LatestTest.php
Normal file
58
tests/Unit/Controllers/SpeedtestController/LatestTest.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user