Skip to content

Commit 0120ad3

Browse files
committed
add test for number of solutions in the widget
1 parent b31d58e commit 0120ad3

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

tests/Integration/Models/UserTest.php

Lines changed: 32 additions & 2 deletions
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)