|
67 | 67 | ]);
|
68 | 68 |
|
69 | 69 | $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(); |
71 | 72 |
|
72 | 73 | $otherThread = Thread::factory()->create();
|
73 | 74 |
|
74 | 75 | $this->dispatch(new MarkThreadSolution($otherThread, $reply, $user));
|
| 76 | + |
75 | 77 | 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 | + |
77 | 107 |
|
78 | 108 | // Helpers
|
79 | 109 | function createTwoSolutionReplies(User $user)
|
|
0 commit comments