Skip to content

Commit

Permalink
you won't notified for your likes/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadmp97 committed Sep 18, 2023
1 parent a2c8c81 commit 8c541e5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 5 additions & 3 deletions app/Actions/Challenge/CreateCommentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public function execute(User $user, Challenge $challenge, array $data): Comment
'text' => $data['text'],
]);

$challenge
->user
->notify(new ChallengeCommentedNotification($comment));
if ($user->isNot($challenge->user)) {
$challenge
->user
->notify(new ChallengeCommentedNotification($comment));
}

CommentCreated::dispatch($comment);

Expand Down
8 changes: 5 additions & 3 deletions app/Actions/Challenge/LikeChallengeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public function execute(User $user, Challenge $challenge): void
'user_id' => $user->id,
]);

$challenge
->user
->notify(new ChallengeLikedNotification($user, $challenge));
if ($user->isNot($challenge->user)) {
$challenge
->user
->notify(new ChallengeLikedNotification($user, $challenge));
}
}
}
4 changes: 3 additions & 1 deletion tests/Feature/ChallengeCommentsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ public function test_user_leaves_a_comment()

Notification::fake();

User::factory()->create([
$user = User::factory()->create([
'email' => config('hope.hope_bot_mail'),
]);

$this->signIn($user);

$response = $this->postJson('api/challenges/1/comments', [
'text' => 'You ****** *****!',
Expand Down
10 changes: 7 additions & 3 deletions tests/Feature/ChallengeLikesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Challenge;
use App\Models\Country;
use App\Models\User;
use App\Notifications\ChallengeLikedNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
Expand All @@ -14,6 +15,7 @@ class ChallengeLikesControllerTest extends TestCase
use RefreshDatabase;

private $user;
private $challenge;

public function setUp(): void
{
Expand All @@ -26,7 +28,9 @@ public function setUp(): void

$this->user = $this->signIn();

Challenge::factory()->create();
$this->challenge = Challenge::factory()->create([
'user_id' => (User::factory()->create())->id
]);
}

public function test_user_gets_like_list()
Expand Down Expand Up @@ -60,9 +64,9 @@ public function test_user_likes_a_challenge()
$this->postJson('api/challenges/1/likes')
->assertOk();

$this->assertEquals(1, Challenge::first()->likes()->count());
$this->assertEquals(1, $this->challenge->likes()->count());

Notification::assertSentTo($this->user, ChallengeLikedNotification::class);
Notification::assertSentTo($this->challenge->user, ChallengeLikedNotification::class);
}

public function test_user_unlikes_a_challenge()
Expand Down

0 comments on commit 8c541e5

Please sign in to comment.