Skip to content

Commit ebe95d5

Browse files
authored
Feat/only show people with solutions in widget (#1252)
* WIP WIP * feat: filter out people with zero solutions in widget * add test for number of solutions in the widget * chore: Delete WIP.md Delete unwanted file
1 parent 219af0e commit ebe95d5

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

app/Models/User.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ public function scopeMostSolutions(Builder $query, ?int $inLastDays = null)
319319
}
320320

321321
return $query;
322-
}])->orderBy('solutions_count', 'desc');
322+
}])
323+
->having('solutions_count', '>', 0)
324+
->orderBy('solutions_count', 'desc');
323325
}
324326

325327
public function scopeMostSubmissions(Builder $query, ?int $inLastDays = null)

tests/Integration/Models/UserTest.php

+32-2
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,43 @@
6767
]);
6868

6969
$this->dispatch(new MarkThreadSolution($thread, $reply, $user));
70-
expect($user->mostSolutions()->find($user->id())->solutions_count)->toBe(0);
70+
71+
expect($user->mostSolutions()->find($user->id()))->toBeNull();
7172

7273
$otherThread = Thread::factory()->create();
7374

7475
$this->dispatch(new MarkThreadSolution($otherThread, $reply, $user));
76+
7577
expect($user->mostSolutions()->find($user->id())->solutions_count)->toBe(1);
76-
});
78+
})->group('emeka');
79+
80+
it('only shows users with solutions in the widget', function () {
81+
$userWithSolution = User::factory()->create();
82+
$userWithoutSolution = User::factory()->create();
83+
$anotherUserWithSolution = User::factory()->create();
84+
85+
$thread1 = Thread::factory()->create();
86+
$thread2 = Thread::factory()->create();
87+
88+
$reply1 = Reply::factory()->create([
89+
'author_id' => $userWithSolution->id,
90+
]);
91+
92+
$reply2 = Reply::factory()->create([
93+
'author_id' => $anotherUserWithSolution->id,
94+
]);
95+
96+
$this->dispatch(new MarkThreadSolution($thread1, $reply1, $userWithSolution));
97+
$this->dispatch(new MarkThreadSolution($thread2, $reply2, $anotherUserWithSolution));
98+
99+
$topMembers = User::mostSolutions(365)->take(5)->get();
100+
101+
expect($topMembers)->toHaveCount(2)
102+
->and($topMembers->pluck('id'))->toContain($userWithSolution->id)
103+
->and($topMembers->pluck('id'))->toContain($anotherUserWithSolution->id)
104+
->and($topMembers->pluck('id'))->not->toContain($userWithoutSolution->id);
105+
})->group('widget');
106+
77107

78108
// Helpers
79109
function createTwoSolutionReplies(User $user)

0 commit comments

Comments
 (0)