laravel-websockets/tests/Dashboard/StatisticsTest.php

43 lines
1.4 KiB
PHP
Raw Normal View History

2020-08-23 17:41:17 +00:00
<?php
2020-09-10 19:59:26 +00:00
namespace BeyondCode\LaravelWebSockets\Test\Dashboard;
2020-08-23 17:41:17 +00:00
2020-09-10 19:59:26 +00:00
use BeyondCode\LaravelWebSockets\Test\Models\User;
use BeyondCode\LaravelWebSockets\Test\TestCase;
2020-08-23 17:41:17 +00:00
class StatisticsTest extends TestCase
{
2020-09-10 19:59:26 +00:00
public function test_can_get_statistics()
{
2020-09-10 19:59:26 +00:00
$rick = $this->newActiveConnection(['public-channel']);
$morty = $this->newActiveConnection(['public-channel']);
2020-09-10 19:59:26 +00:00
$this->statisticsCollector->save();
2020-08-23 17:41:17 +00:00
2020-09-10 19:59:26 +00:00
$response = $this->actingAs(factory(User::class)->create())
2020-08-23 17:41:17 +00:00
->json('GET', route('laravel-websockets.statistics', ['appId' => '1234']))
->assertResponseOk()
->seeJsonStructure([
'peak_connections' => ['x', 'y'],
2020-09-10 19:59:26 +00:00
'websocket_messages_count' => ['x', 'y'],
'api_messages_count' => ['x', 'y'],
2020-08-23 17:41:17 +00:00
]);
}
2020-09-10 19:59:26 +00:00
public function test_cant_get_statistics_for_invalid_app_id()
2020-08-23 17:41:17 +00:00
{
2020-09-10 19:59:26 +00:00
$rick = $this->newActiveConnection(['public-channel']);
$morty = $this->newActiveConnection(['public-channel']);
2020-08-23 17:41:17 +00:00
2020-09-10 19:59:26 +00:00
$this->statisticsCollector->save();
2020-08-23 17:41:17 +00:00
$this->actingAs(factory(User::class)->create())
->json('GET', route('laravel-websockets.statistics', ['appId' => 'not_found']))
->seeJson([
'peak_connections' => ['x' => [], 'y' => []],
2020-09-10 19:59:26 +00:00
'websocket_messages_count' => ['x' => [], 'y' => []],
'api_messages_count' => ['x' => [], 'y' => []],
2020-08-23 17:41:17 +00:00
]);
}
}