wip
This commit is contained in:
parent
f62ac8fd56
commit
499a153a0a
|
|
@ -5,7 +5,7 @@ namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
|
||||||
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
|
use BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class DashboardApiController
|
class ShowStatistics
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get statistics for an app ID.
|
* Get statistics for an app ID.
|
||||||
|
|
@ -15,7 +15,7 @@ class DashboardApiController
|
||||||
* @param mixed $appId
|
* @param mixed $appId
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function getStatistics(Request $request, StatisticsDriver $driver, $appId)
|
public function __invoke(Request $request, StatisticsDriver $driver, $appId)
|
||||||
{
|
{
|
||||||
return $driver::get($appId, $request);
|
return $driver::get($appId, $request);
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ namespace BeyondCode\LaravelWebSockets;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Apps\AppManager;
|
use BeyondCode\LaravelWebSockets\Apps\AppManager;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowStatistics;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize as AuthorizeDashboard;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize as AuthorizeDashboard;
|
||||||
|
|
@ -124,9 +124,9 @@ class WebSocketsServiceProvider extends ServiceProvider
|
||||||
'middleware' => config('websockets.dashboard.middleware', [AuthorizeDashboard::class]),
|
'middleware' => config('websockets.dashboard.middleware', [AuthorizeDashboard::class]),
|
||||||
], function () {
|
], function () {
|
||||||
Route::get('/', ShowDashboard::class)->name('dashboard');
|
Route::get('/', ShowDashboard::class)->name('dashboard');
|
||||||
Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics'])->name('statistics');
|
Route::get('/api/{appId}/statistics', ShowStatistics::class)->name('statistics');
|
||||||
Route::post('/auth', AuthenticateDashboard::class)->name('auth');
|
Route::post('/auth', AuthenticateDashboard::class)->name('auth');
|
||||||
Route::post('/event', SendMessage::class)->name('send');
|
Route::post('/event', SendMessage::class)->name('event');
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeyondCode\LaravelWebSockets\Tests\Dashboard;
|
||||||
|
|
||||||
|
use BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger;
|
||||||
|
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||||
|
use BeyondCode\LaravelWebSockets\Tests\Models\User;
|
||||||
|
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||||
|
|
||||||
|
class StatisticsTest extends TestCase
|
||||||
|
{
|
||||||
|
/** @test */
|
||||||
|
public function can_get_statistics()
|
||||||
|
{
|
||||||
|
$connection = $this->getConnectedWebSocketConnection(['channel-1']);
|
||||||
|
|
||||||
|
$logger = new MemoryStatisticsLogger(
|
||||||
|
$this->channelManager,
|
||||||
|
$this->statisticsDriver
|
||||||
|
);
|
||||||
|
|
||||||
|
$logger->webSocketMessage($connection->app->id);
|
||||||
|
$logger->apiMessage($connection->app->id);
|
||||||
|
$logger->connection($connection->app->id);
|
||||||
|
$logger->disconnection($connection->app->id);
|
||||||
|
|
||||||
|
$logger->save();
|
||||||
|
|
||||||
|
$this->actingAs(factory(User::class)->create())
|
||||||
|
->json('GET', route('laravel-websockets.statistics', ['appId' => '1234']))
|
||||||
|
->assertResponseOk()
|
||||||
|
->seeJsonStructure([
|
||||||
|
'peak_connections' => ['x', 'y'],
|
||||||
|
'websocket_message_count' => ['x', 'y'],
|
||||||
|
'api_message_count' => ['x', 'y'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function cant_get_statistics_for_invalid_app_id()
|
||||||
|
{
|
||||||
|
$connection = $this->getConnectedWebSocketConnection(['channel-1']);
|
||||||
|
|
||||||
|
$logger = new MemoryStatisticsLogger(
|
||||||
|
$this->channelManager,
|
||||||
|
$this->statisticsDriver
|
||||||
|
);
|
||||||
|
|
||||||
|
$logger->webSocketMessage($connection->app->id);
|
||||||
|
$logger->apiMessage($connection->app->id);
|
||||||
|
$logger->connection($connection->app->id);
|
||||||
|
$logger->disconnection($connection->app->id);
|
||||||
|
|
||||||
|
$logger->save();
|
||||||
|
|
||||||
|
$this->actingAs(factory(User::class)->create())
|
||||||
|
->json('GET', route('laravel-websockets.statistics', ['appId' => 'not_found']))
|
||||||
|
->seeJson([
|
||||||
|
'peak_connections' => ['x' => [], 'y' => []],
|
||||||
|
'websocket_message_count' => ['x' => [], 'y' => []],
|
||||||
|
'api_message_count' => ['x' => [], 'y' => []],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue