create(); $user = User::factory()->create(); $this->actingAs($user) ->getJson("/api/posts/{$post->id}"); $this->assertEquals(1, $post->fresh()->views); } public function test_same_ip_does_not_increase_view_count_within_24_hours(): void { $post = Post::factory()->create(); $user = User::factory()->create(); $this->actingAs($user) ->getJson("/api/posts/{$post->id}"); $this->actingAs($user) ->getJson("/api/posts/{$post->id}"); $this->assertEquals(1, $post->fresh()->views); } public function test_can_get_popular_posts(): void { $posts = Post::factory()->count(5)->create(); $user = User::factory()->create(); foreach ($posts as $index => $post) { for ($i = 0; $i <= $index; $i++) { $post->increment('views'); } } $response = $this->actingAs($user) ->getJson('/api/posts/popular'); $response->assertStatus(200) ->assertJsonCount(5, 'data') ->assertJsonPath('data.0.views', 4); } }