diff --git a/tests/Feature/UserDashboardTest.php b/tests/Feature/UserDashboardTest.php index 686aaed8..ce395214 100644 --- a/tests/Feature/UserDashboardTest.php +++ b/tests/Feature/UserDashboardTest.php @@ -66,6 +66,10 @@ public function test_accurate_data_is_returned_for_graph_usage() 'user_id' => $user->id, ]); + $currentMonth = Carbon::now()->format('M'); // Current month abbreviation + $lastMonth = Carbon::now()->subMonth()->format('M'); // Last month abbreviation + + $order = Order::factory()->create([ 'product_id' => $product->product_id, 'quantity' => 2, @@ -79,24 +83,16 @@ public function test_accurate_data_is_returned_for_graph_usage() 'total_amount' => 3000, ]); $response = $this->get('/api/v1/user-analytics'); + + $expectedData = array_fill_keys(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 0); + $expectedData[$lastMonth] = 2000.00; + $expectedData[$currentMonth] = 3000.00; + $response->assertJson( [ 'message' => 'User analytics retrieved successfully', 'status_code' => 200, - 'data' => [ - 'Jan' => 0, - 'Feb' => 0, - 'Mar' => 0, - 'Apr' => 0, - 'May' => 0, - 'Jun' => 0, - 'Jul' => 2000.00, - 'Aug' => 3000.00, - 'Sep' => 0, - 'Oct' => 0, - 'Nov' => 0, - 'Dec' => 0, - ] + 'data' => $expectedData ] ); } @@ -146,4 +142,4 @@ public function test_accurate_data_is_returned_for_recent_sales() ] ); } -} +} \ No newline at end of file