Skip to content

Commit c515356

Browse files
committed
fix: UserDashboardTest
1 parent dcc505f commit c515356

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

tests/Feature/UserDashboardTest.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function test_accurate_data_is_returned_for_graph_usage()
6666
'user_id' => $user->id,
6767
]);
6868

69+
$currentMonth = Carbon::now()->format('M'); // Current month abbreviation
70+
$lastMonth = Carbon::now()->subMonth()->format('M'); // Last month abbreviation
71+
72+
6973
$order = Order::factory()->create([
7074
'product_id' => $product->product_id,
7175
'quantity' => 2,
@@ -79,24 +83,16 @@ public function test_accurate_data_is_returned_for_graph_usage()
7983
'total_amount' => 3000,
8084
]);
8185
$response = $this->get('/api/v1/user-analytics');
86+
87+
$expectedData = array_fill_keys(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 0);
88+
$expectedData[$lastMonth] = 2000.00;
89+
$expectedData[$currentMonth] = 3000.00;
90+
8291
$response->assertJson(
8392
[
8493
'message' => 'User analytics retrieved successfully',
8594
'status_code' => 200,
86-
'data' => [
87-
'Jan' => 0,
88-
'Feb' => 0,
89-
'Mar' => 0,
90-
'Apr' => 0,
91-
'May' => 0,
92-
'Jun' => 0,
93-
'Jul' => 2000.00,
94-
'Aug' => 3000.00,
95-
'Sep' => 0,
96-
'Oct' => 0,
97-
'Nov' => 0,
98-
'Dec' => 0,
99-
]
95+
'data' => $expectedData
10096
]
10197
);
10298
}
@@ -146,4 +142,4 @@ public function test_accurate_data_is_returned_for_recent_sales()
146142
]
147143
);
148144
}
149-
}
145+
}

0 commit comments

Comments
 (0)