diff --git a/config/websockets.php b/config/websockets.php index 0904b0e..693f861 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -45,7 +45,7 @@ return [ /* * This model will be used to store the statistics of the WebSocketsServer */ - 'statistics_model' => \BeyondCode\LaravelWebSockets\Statistics\WebSocketsStatisticsEntry::class, + 'statistics_model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class, /* * Define the optional SSL context for your WebSocket connections. diff --git a/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php b/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php index ffab25d..38c4d01 100644 --- a/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php +++ b/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php @@ -3,7 +3,7 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers; use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; -use BeyondCode\LaravelWebSockets\Statistics\WebSocketsStatisticsEntry; +use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; use Illuminate\Http\Request; class WebsocketStatisticsEntriesController diff --git a/src/Statistics/WebSocketsStatisticsEntry.php b/src/Statistics/Models/WebSocketsStatisticsEntry.php similarity index 75% rename from src/Statistics/WebSocketsStatisticsEntry.php rename to src/Statistics/Models/WebSocketsStatisticsEntry.php index 2569306..637047e 100644 --- a/src/Statistics/WebSocketsStatisticsEntry.php +++ b/src/Statistics/Models/WebSocketsStatisticsEntry.php @@ -1,6 +1,6 @@ namespace('\\')->middleware(Authorize::class)->group(function() { + Route::prefix($prefix)->middleware(Authorize::class)->group(function() { Route::get('/', ShowDashboard::class); Route::post('auth', AuthenticateDashboard::class); Route::post('event', SendMessage::class); }); //TODO: add middleware - Route::prefix($prefix)->namespace('\\')->group(function() { + Route::prefix($prefix)->group(function() { Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']); }); }); diff --git a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php new file mode 100644 index 0000000..28bbb53 --- /dev/null +++ b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php @@ -0,0 +1,35 @@ +post( + action([WebsocketStatisticsEntriesController::class, 'store']), + $this->payload() + ); + + $entries = WebSocketsStatisticsEntry::get(); + + $this->assertCount(1, $entries); + + $this->assertArraySubset($this->payload(), $entries->first()->attributesToArray()); + } + + protected function payload(): array + { + return [ + 'app_id' => config('websockets.apps.0.id'), + 'peak_connections' => 1, + 'websocket_message_count' => 2, + 'api_message_count' => 3, + ]; + } +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 2c63920..be99228 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,6 +8,7 @@ use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler; use GuzzleHttp\Psr7\Request; use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider; +use Illuminate\Support\Facades\Route; use Ratchet\ConnectionInterface; abstract class TestCase extends \Orchestra\Testbench\TestCase @@ -25,6 +26,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase $this->pusherServer = app(WebSocketHandler::class); $this->channelManager = app(ChannelManager::class); + + Route::webSockets(); } protected function getPackageProviders($app) @@ -48,6 +51,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase include_once __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub'; (new \CreateWebSocketsStatisticsEntriesTable())->up(); + + } protected function getWebSocketConnection(string $url = '/?appKey=TestKey'): Connection