Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Only show people with solutions in widget
4 changes: 3 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 32 additions & 2 deletions tests/Integration/Models/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down