From 1157ade659481e30a37fccef4c85bbd079f15c84 Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Tue, 25 Feb 2025 19:15:31 +0000 Subject: [PATCH 1/4] WIP WIP --- WIP.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 WIP.md diff --git a/WIP.md b/WIP.md new file mode 100644 index 000000000..2c846fab5 --- /dev/null +++ b/WIP.md @@ -0,0 +1 @@ +- Only show people with solutions in widget From b31d58e0aa3780785d5300e2a54661909ed337cd Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Mon, 3 Mar 2025 18:13:48 +0000 Subject: [PATCH 2/4] feat: filter out people with zero solutions in widget --- app/Models/User.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 10d41fb9a..d1d6f5dc5 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -319,7 +319,9 @@ public function scopeMostSolutions(Builder $query, ?int $inLastDays = null) } return $query; - }])->orderBy('solutions_count', 'desc'); + }]) + ->having('solutions_count', '>', 0) + ->orderBy('solutions_count', 'desc'); } public function scopeMostSubmissions(Builder $query, ?int $inLastDays = null) From 0120ad32fa5f55e8cf8ada47ce9ffc387ec9013b Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Mon, 3 Mar 2025 20:43:49 +0000 Subject: [PATCH 3/4] add test for number of solutions in the widget --- tests/Integration/Models/UserTest.php | 34 +++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Models/UserTest.php b/tests/Integration/Models/UserTest.php index fb39dd545..cbb7c8e8f 100644 --- a/tests/Integration/Models/UserTest.php +++ b/tests/Integration/Models/UserTest.php @@ -67,13 +67,43 @@ ]); $this->dispatch(new MarkThreadSolution($thread, $reply, $user)); - expect($user->mostSolutions()->find($user->id())->solutions_count)->toBe(0); + + expect($user->mostSolutions()->find($user->id()))->toBeNull(); $otherThread = Thread::factory()->create(); $this->dispatch(new MarkThreadSolution($otherThread, $reply, $user)); + expect($user->mostSolutions()->find($user->id())->solutions_count)->toBe(1); -}); +})->group('emeka'); + +it('only shows users with solutions in the widget', function () { + $userWithSolution = User::factory()->create(); + $userWithoutSolution = User::factory()->create(); + $anotherUserWithSolution = User::factory()->create(); + + $thread1 = Thread::factory()->create(); + $thread2 = Thread::factory()->create(); + + $reply1 = Reply::factory()->create([ + 'author_id' => $userWithSolution->id, + ]); + + $reply2 = Reply::factory()->create([ + 'author_id' => $anotherUserWithSolution->id, + ]); + + $this->dispatch(new MarkThreadSolution($thread1, $reply1, $userWithSolution)); + $this->dispatch(new MarkThreadSolution($thread2, $reply2, $anotherUserWithSolution)); + + $topMembers = User::mostSolutions(365)->take(5)->get(); + + expect($topMembers)->toHaveCount(2) + ->and($topMembers->pluck('id'))->toContain($userWithSolution->id) + ->and($topMembers->pluck('id'))->toContain($anotherUserWithSolution->id) + ->and($topMembers->pluck('id'))->not->toContain($userWithoutSolution->id); +})->group('widget'); + // Helpers function createTwoSolutionReplies(User $user) From 8c5029f1893332af618cb02e36d8c2cd220d8d0e Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Wed, 12 Mar 2025 07:31:17 +0000 Subject: [PATCH 4/4] chore: Delete WIP.md Delete unwanted file --- WIP.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 WIP.md diff --git a/WIP.md b/WIP.md deleted file mode 100644 index 2c846fab5..000000000 --- a/WIP.md +++ /dev/null @@ -1 +0,0 @@ -- Only show people with solutions in widget