From 3fcfe1bb391a96a09910bd444252526d35604b19 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Sun, 23 Aug 2020 13:44:09 +0300 Subject: [PATCH] Added test for app_id --- tests/Commands/CleanStatisticsTest.php | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Commands/CleanStatisticsTest.php b/tests/Commands/CleanStatisticsTest.php index 91f7790..9e26a6d 100644 --- a/tests/Commands/CleanStatisticsTest.php +++ b/tests/Commands/CleanStatisticsTest.php @@ -42,4 +42,34 @@ class CleanStatisticsTest extends TestCase $this->assertCount(0, WebSocketsStatisticsEntry::where('created_at', '<', $cutOffDate)->get()); } + + /** @test */ + public function it_can_clean_the_statistics_for_app_id_only() + { + Collection::times(60)->each(function (int $index) { + WebSocketsStatisticsEntry::create([ + 'app_id' => 'app_id', + 'peak_connection_count' => 1, + 'websocket_message_count' => 2, + 'api_message_count' => 3, + 'created_at' => Carbon::now()->subDays($index)->startOfDay(), + ]); + }); + + Collection::times(60)->each(function (int $index) { + WebSocketsStatisticsEntry::create([ + 'app_id' => 'app_id2', + 'peak_connection_count' => 1, + 'websocket_message_count' => 2, + 'api_message_count' => 3, + 'created_at' => Carbon::now()->subDays($index)->startOfDay(), + ]); + }); + + $this->assertCount(120, WebSocketsStatisticsEntry::all()); + + Artisan::call('websockets:clean', ['appId' => 'app_id']); + + $this->assertCount(91, WebSocketsStatisticsEntry::all()); + } }