Merge pull request #4374 from Obi-Wana/use-shouldSend-for-notifications

(Add) Use shouldSend for notifications
This commit is contained in:
HDVinnie
2025-02-28 00:30:12 -05:00
committed by GitHub
50 changed files with 7124 additions and 72 deletions
+1 -3
View File
@@ -96,9 +96,7 @@ class TorrentHelper
if (!$torrent->anon && $uploader !== null) {
foreach ($uploader->followers()->get() as $follower) {
if ($follower->acceptsNotification($uploader, $follower, 'following', 'show_following_upload')) {
$follower->notify(new NewUpload('follower', $torrent));
}
$follower->notify(new NewUpload('follower', $torrent));
}
}
@@ -74,9 +74,7 @@ class ApprovedRequestFillController extends Controller
);
}
if ($filler->acceptsNotification($approver, $filler, 'request', 'show_request_fill_approve')) {
$filler->notify(new NewRequestFillApprove($torrentRequest));
}
$filler->notify(new NewRequestFillApprove($torrentRequest));
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
->with('success', \sprintf(trans('request.approved-user'), $torrentRequest->name, $torrentRequest->filled_anon ? 'Anonymous' : $filler->username));
+1 -3
View File
@@ -78,9 +78,7 @@ class BountyController extends Controller
$requester = $torrentRequest->user;
if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_bounty')) {
$requester->notify(new NewRequestBounty($bounty));
}
$requester->notify(new NewRequestBounty($bounty));
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
->with('success', trans('request.added-bonus'));
+4 -8
View File
@@ -47,9 +47,7 @@ class ClaimController extends Controller
$requester = $torrentRequest->user;
if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_claim')) {
$requester->notify(new NewRequestClaim($claim));
}
$requester->notify(new NewRequestClaim($claim));
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
->with('success', trans('request.claimed-success'));
@@ -64,8 +62,6 @@ class ClaimController extends Controller
{
abort_unless($request->user()->group->is_modo || $request->user()->id == $claim->user_id, 403);
$claim->delete();
$torrentRequest->update([
'claimed' => null,
]);
@@ -73,9 +69,9 @@ class ClaimController extends Controller
$claimer = $claim->anon ? 'Anonymous' : $request->user()->username;
$requester = $torrentRequest->user;
if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_unclaim')) {
$requester->notify(new NewRequestUnclaim('torrent', $claimer, $torrentRequest));
}
$requester->notify((new NewRequestUnclaim('torrent', $claimer, $claim)));
$claim->delete();
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
->with('success', trans('request.unclaimed-success'));
+2 -6
View File
@@ -117,9 +117,7 @@ class PostController extends Controller
$topicStarter = $topic->user;
// Notify All Subscribers Of New Reply
if ($topicStarter && $topicStarter->isNot($user) && $topicStarter->acceptsNotification($user, $topicStarter, 'forum', 'show_forum_topic')) {
$topicStarter->notify(new NewPost('topic', $user, $post));
}
$topicStarter->notify(new NewPost('topic', $user, $post));
$subscribers = User::query()
->where('id', '!=', $user->id)
@@ -136,9 +134,7 @@ class PostController extends Controller
->get();
foreach ($subscribers as $subscriber) {
if ($subscriber->acceptsNotification($user, $subscriber, 'subscription', 'show_subscription_topic')) {
$subscriber->notify(new NewPost('subscription', $user, $post));
}
$subscriber->notify(new NewPost('subscription', $user, $post));
}
// Achievements
@@ -52,9 +52,7 @@ class RequestFillController extends Controller
$sender = $request->boolean('filled_anon') ? 'Anonymous' : $request->user()->username;
$requester = $torrentRequest->user;
if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_fill')) {
$requester->notify(new NewRequestFill($torrentRequest));
}
$requester->notify(new NewRequestFill($torrentRequest));
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
->with('success', trans('request.pending-approval'));
@@ -77,9 +75,7 @@ class RequestFillController extends Controller
'torrent_id' => null,
]);
if ($filler->acceptsNotification($approver, $filler, 'request', 'show_request_fill_reject')) {
$filler->notify(new NewRequestFillReject('torrent', $approver->is($requester) ? ($torrentRequest->anon ? 'Anonymous' : $requester->username) : $approver->username, $torrentRequest));
}
$filler->notify(new NewRequestFillReject('torrent', $approver->is($requester) ? ($torrentRequest->anon ? 'Anonymous' : $requester->username) : $approver->username, $torrentRequest));
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
->with('success', trans('request.request-reset'));
+1 -3
View File
@@ -168,9 +168,7 @@ class TopicController extends Controller
->get();
foreach ($subscribers as $subscriber) {
if ($subscriber->acceptsNotification($user, $subscriber, 'subscription', 'show_subscription_forum')) {
$subscriber->notify(new NewTopic('forum', $user, $topic));
}
$subscriber->notify(new NewTopic('forum', $user, $topic));
}
//Achievements
@@ -50,9 +50,7 @@ class FollowController extends Controller
$user->followers()->attach($request->user()->id);
if ($user->acceptsNotification($request->user(), $user, 'account', 'show_account_follow')) {
$user->notify(new NewFollow('user', $request->user()));
}
$user->notify(new NewFollow('user', $request->user()));
return to_route('users.show', ['user' => $user])
->with('success', \sprintf(trans('user.follow-user'), $user->username));
@@ -65,9 +63,7 @@ class FollowController extends Controller
{
$user->followers()->detach($request->user()->id);
if ($user->acceptsNotification($request->user(), $user, 'account', 'show_account_unfollow')) {
$user->notify(new NewUnfollow('user', $request->user()));
}
$user->notify(new NewUnfollow('user', $request->user()));
return to_route('users.show', ['user' => $user])
->with('success', \sprintf(trans('user.follow-revoked'), $user->username));
+1 -3
View File
@@ -89,9 +89,7 @@ class GiftController extends Controller
'message' => $request->message,
]);
if ($receiver->acceptsNotification($sender, $receiver, 'bon', 'show_bon_gift')) {
$receiver->notify((new NewBon($gift))->afterCommit());
}
$receiver->notify((new NewBon($gift))->afterCommit());
});
$this->chatRepository->systemMessage(
+5 -11
View File
@@ -128,24 +128,18 @@ class Comments extends Component
// New Comment Notification
switch (true) {
case $this->model instanceof Ticket:
$ticket = $this->model;
// Notify assigned staff if needed
User::find($this->model->staff_id)?->notify(new NewComment($this->model, $comment));
if ($this->user->id !== $ticket->staff_id && $ticket->staff_id !== null) {
User::find($ticket->staff_id)?->notify(new NewComment($this->model, $comment));
}
if ($this->user->id !== $ticket->user_id) {
User::find($ticket->user_id)?->notify(new NewComment($this->model, $comment));
}
// Notify ticket creator if needed
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
break;
case $this->model instanceof Article:
case $this->model instanceof Playlist:
case $this->model instanceof TorrentRequest:
case $this->model instanceof Torrent:
if ($this->user->id !== $this->model->user_id) {
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
}
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
break;
}
+24
View File
@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\Gift;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -42,6 +43,29 @@ class NewBon extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Enforce non-anonymous staff notifications to be sent
if ($this->gift->sender->group->is_modo) {
return true;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_bon_gift) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->gift->sender->group_id, $notifiable->notification->json_bon_groups, true);
}
/**
* Get the array representation of the notification.
*
+53 -7
View File
@@ -17,12 +17,12 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\Article;
use App\Models\Collection;
use App\Models\Comment;
use App\Models\Playlist;
use App\Models\Ticket;
use App\Models\Torrent;
use App\Models\TorrentRequest;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
@@ -33,7 +33,7 @@ class NewComment extends Notification
/**
* NewComment Constructor.
*/
public function __construct(public Torrent|TorrentRequest|Ticket|Playlist|Collection|Article $model, public Comment $comment)
public function __construct(public Torrent|TorrentRequest|Ticket|Playlist|Article $model, public Comment $comment)
{
}
@@ -47,6 +47,57 @@ class NewComment extends Notification
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->comment->user_id === $notifiable->id) {
return false;
}
// Enforce non-anonymous staff notifications to be sent
if ($this->comment->user->group->is_modo &&
! $this->comment->anon) {
return true;
}
// Evaluate general settings
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
// Evaluate model based settings
switch (true) {
case $this->model instanceof Torrent:
if (!$notifiable->notification?->show_torrent_comment) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_torrent_groups, true);
case $this->model instanceof TorrentRequest:
if (!$notifiable->notification?->show_request_comment) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_request_groups, true);
case $this->model instanceof Ticket:
return ! ($this->model->staff_id === $this->comment->id && $this->model->staff_id !== null)
;
case $this->model instanceof Playlist:
case $this->model instanceof Article:
break;
}
return true;
}
/**
* Get the array representation of the notification.
*
@@ -77,11 +128,6 @@ class NewComment extends Notification
'body' => $username.' has left you a comment on Playlist '.$this->model->name,
'url' => '/playlists/'.$this->model->id.'#comment-'.$this->comment->id,
],
$this->model instanceof Collection => [
'title' => 'New Collection Comment Received',
'body' => $username.' has left you a comment on Collection '.$this->model->name,
'url' => '/mediahub/collections/'.$this->model->id.'#comment-'.$this->comment->id,
],
$this->model instanceof Article => [
'title' => 'New Article Comment Received',
'body' => $username.' has left you a comment on Article '.$this->model->title,
+58
View File
@@ -23,6 +23,7 @@ use App\Models\Playlist;
use App\Models\Ticket;
use App\Models\Torrent;
use App\Models\TorrentRequest;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -48,6 +49,63 @@ class NewCommentTag extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->comment->user_id === $notifiable->id) {
return false;
}
// Enforce non-anonymous staff notifications to be sent
if ($this->comment->user->group->is_modo &&
! $this->comment->anon) {
return true;
}
// Evaluate general settings
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
// Evaluate model based settings
switch (true) {
case $this->model instanceof Torrent:
if (!$notifiable->notification?->show_mention_torrent_comment) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
case $this->model instanceof TorrentRequest:
if (!$notifiable->notification?->show_mention_request_comment) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
case $this->model instanceof Ticket:
return ! ($this->model->staff_id === $this->comment->id);
case $this->model instanceof Playlist:
case $this->model instanceof Article:
if (!$notifiable->notification?->show_mention_article_comment) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
case $this->model instanceof Collection:
break;
}
return true;
}
/**
* Get the array representation of the notification.
*
+18
View File
@@ -42,6 +42,24 @@ class NewFollow extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_account_follow) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->follower->group_id, $notifiable->notification->json_following_groups, true);
}
/**
* Get the array representation of the notification.
*
+40
View File
@@ -43,6 +43,46 @@ class NewPost extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->post->user_id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
$targetNotification = match ($this->type) {
'subscription' => 'show_subscription_topic',
'staff' => null,
'topic' => 'show_forum_topic',
default => 'show_forum_topic',
};
if (!$notifiable->notification?->$targetNotification) {
return false;
}
$targetGroup = match ($this->type) {
'subscription' => 'json_subscription_groups',
'staff' => null,
'topic' => 'json_forum_groups',
default => 'json_forum_groups',
};
// If target group is null (for 'staff'), always return true
if ($targetGroup === null) {
return true;
}
return ! \in_array($this->post->user->group_id, $notifiable->notification->$targetGroup, true);
}
/**
* Get the array representation of the notification.
*
+29
View File
@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\Post;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -42,6 +43,34 @@ class NewPostTag extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->post->user_id === $notifiable->id) {
return false;
}
// Enforce staff notifications to be sent
if ($this->post->user->group->is_modo) {
return true;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_mention_forum_post) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->post->user->group_id, $notifiable->notification->json_mention_groups, true);
}
/**
* Get the array representation of the notification.
*
+24
View File
@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\TorrentRequestBounty;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -42,6 +43,29 @@ class NewRequestBounty extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->bounty->user_id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_request_bounty) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->bounty->user->group_id, $notifiable->notification->json_request_groups, true);
}
/**
* Get the array representation of the notification.
*
+24
View File
@@ -16,6 +16,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\User;
use App\Models\TorrentRequestClaim;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -42,6 +43,29 @@ class NewRequestClaim extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->claim->user_id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_request_claim) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->claim->user->group_id, $notifiable->notification->json_request_groups, true);
}
/**
* Get the array representation of the notification.
*
+24
View File
@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\TorrentRequest;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -42,6 +43,29 @@ class NewRequestFill extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->torrentRequest->filler->id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_request_fill) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->torrentRequest->filler->group_id, $notifiable->notification->json_request_groups, true);
}
/**
* Get the array representation of the notification.
*
@@ -16,6 +16,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\User;
use App\Models\TorrentRequest;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -42,6 +43,29 @@ class NewRequestFillApprove extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->torrentRequest->approver->id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_request_fill_approve) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->torrentRequest->approver->group_id, $notifiable->notification->json_request_groups, true);
}
/**
* Get the array representation of the notification.
*
@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\TorrentRequest;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -42,6 +43,29 @@ class NewRequestFillReject extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->torrentRequest->user_id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_request_fill_reject) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->torrentRequest->user->group_id, $notifiable->notification->json_request_groups, true);
}
/**
* Get the array representation of the notification.
*
+28 -4
View File
@@ -16,7 +16,8 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\TorrentRequest;
use App\Models\TorrentRequestClaim;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
@@ -28,7 +29,7 @@ class NewRequestUnclaim extends Notification implements ShouldQueue
/**
* NewRequestUnclaim Constructor.
*/
public function __construct(public string $type, public string $sender, public TorrentRequest $torrentRequest)
public function __construct(public string $type, public string $sender, public TorrentRequestClaim $torrentRequestClaim)
{
}
@@ -42,6 +43,29 @@ class NewRequestUnclaim extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
// Do not notify self
if ($this->torrentRequestClaim->user_id === $notifiable->id) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_request_unclaim) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->torrentRequestClaim->user->group_id, $notifiable->notification->json_request_groups, true);
}
/**
* Get the array representation of the notification.
*
@@ -51,8 +75,8 @@ class NewRequestUnclaim extends Notification implements ShouldQueue
{
return [
'title' => $this->sender.' Has Unclaimed One Of Your Requested Torrents',
'body' => $this->sender.' has unclaimed your Requested Torrent '.$this->torrentRequest->name,
'url' => \sprintf('/requests/%s', $this->torrentRequest->id),
'body' => $this->sender.' has unclaimed your Requested Torrent '.$this->torrentRequestClaim->request->name,
'url' => \sprintf('/requests/%s', $this->torrentRequestClaim->request->id),
];
}
}
+18
View File
@@ -43,6 +43,24 @@ class NewTopic extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_subscription_forum) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->user->group_id, $notifiable->notification->json_subscription_groups, true);
}
/**
* Get the array representation of the notification.
*
+18
View File
@@ -42,6 +42,24 @@ class NewUnfollow extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_account_unfollow) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->unfollower->group_id, $notifiable->notification->json_account_groups, true);
}
/**
* Get the array representation of the notification.
*
+23
View File
@@ -16,6 +16,7 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\User;
use App\Models\Torrent;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -42,6 +43,28 @@ class NewUpload extends Notification implements ShouldQueue
return ['database'];
}
/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
if ($this->torrent->anon) {
return false;
}
if ($notifiable->notification?->block_notifications == 1) {
return false;
}
if (!$notifiable->notification?->show_following_upload) {
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->torrent->user->group_id, $notifiable->notification->json_following_groups, true);
}
/**
* Get the array representation of the notification.
*
@@ -36,7 +36,7 @@ class TorrentRequestClaimFactory extends Factory
{
return [
'request_id' => TorrentRequest::factory(),
'username' => User::factory(),
'user_id' => User::factory(),
'anon' => $this->faker->boolean(),
];
}
@@ -16,6 +16,7 @@ declare(strict_types=1);
namespace Database\Factories;
use App\Models\Group;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\UserNotification;
@@ -57,14 +58,14 @@ class UserNotificationFactory extends Factory
'show_torrent_thank' => $this->faker->boolean(),
'show_account_follow' => $this->faker->boolean(),
'show_account_unfollow' => $this->faker->boolean(),
'json_account_groups' => $this->faker->word(),
'json_bon_groups' => $this->faker->word(),
'json_mention_groups' => $this->faker->word(),
'json_request_groups' => $this->faker->word(),
'json_torrent_groups' => $this->faker->word(),
'json_forum_groups' => $this->faker->word(),
'json_following_groups' => $this->faker->word(),
'json_subscription_groups' => $this->faker->word(),
'json_account_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_bon_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_mention_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_request_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_torrent_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_forum_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_following_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
'json_subscription_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
];
}
}
@@ -0,0 +1,305 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Group;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewBon;
use Database\Seeders\UsersTableSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('gift a user creates a notification for the gifted user', function (): void {
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$sender = User::factory()->create([
'seedbonus' => 1000,
]);
$receiver = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $receiver->id,
'block_notifications' => 0,
'show_bon_gift' => 1,
]);
$response = $this->actingAs($sender)->post(route('users.gifts.store', ['user' => $receiver]), [
'sender_id' => $sender->id,
'recipient_username' => $receiver->username,
'message' => 'foo',
'bon' => 100.00,
]);
// The transaction must complete to trigger a notification
$this->assertDatabaseHas('gifts', [
'bon' => '100.00',
'sender_id' => $sender->id,
'recipient_id' => $receiver->id,
]);
Notification::assertSentTo(
[$receiver],
NewBon::class
);
Notification::assertCount(1);
});
test('gift a user creates a notification for the gifted user when gift notifications are not disabled for specific group', function (): void {
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$sender = User::factory()->create([
'group_id' => $group->id,
'seedbonus' => 1000,
]);
$receiver = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $receiver->id,
'block_notifications' => 0,
'show_bon_gift' => 1,
'json_bon_groups' => [$randomGroup->id],
]);
$response = $this->actingAs($sender)->post(route('users.gifts.store', ['user' => $receiver]), [
'sender_id' => $sender->id,
'recipient_username' => $receiver->username,
'message' => 'foo',
'bon' => 100.00,
]);
// The transaction must complete to trigger a notification
$this->assertDatabaseHas('gifts', [
'bon' => '100.00',
'sender_id' => $sender->id,
'recipient_id' => $receiver->id,
]);
Notification::assertSentTo(
[$receiver],
NewBon::class
);
Notification::assertCount(1);
});
test('staff gifts a user creates a notification for the gifted user even when gift notifications are disabled', function (): void {
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create([
'is_modo' => 1,
]);
$sender = User::factory()->create([
'group_id' => $group->id,
'seedbonus' => 1000,
]);
$receiver = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $receiver->id,
'block_notifications' => 0,
'show_bon_gift' => 0,
]);
$response = $this->actingAs($sender)->post(route('users.gifts.store', ['user' => $receiver]), [
'sender_id' => $sender->id,
'recipient_username' => $receiver->username,
'message' => 'foo',
'bon' => 100.00,
]);
// The transaction must complete to trigger a notification
$this->assertDatabaseHas('gifts', [
'bon' => '100.00',
'sender_id' => $sender->id,
'recipient_id' => $receiver->id,
]);
Notification::assertSentTo(
[$receiver],
NewBon::class
);
Notification::assertCount(1);
});
test('gift a user does not create a notification for the gifted user when all notifications disabled', function (): void {
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$sender = User::factory()->create([
'seedbonus' => 1000,
]);
$receiver = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $receiver->id,
'block_notifications' => 1,
'show_bon_gift' => 1,
]);
$response = $this->actingAs($sender)->post(route('users.gifts.store', ['user' => $receiver]), [
'sender_id' => $sender->id,
'recipient_username' => $receiver->username,
'message' => 'foo',
'bon' => 100.00,
]);
// The transaction must complete to trigger a notification
$this->assertDatabaseHas('gifts', [
'bon' => '100.00',
'sender_id' => $sender->id,
'recipient_id' => $receiver->id,
]);
Notification::assertCount(0);
});
test('gift a user does not create a notification for the gifted user when gift notifications are disabled', function (): void {
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$sender = User::factory()->create([
'seedbonus' => 1000,
]);
$receiver = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $receiver->id,
'block_notifications' => 0,
'show_bon_gift' => 0,
]);
$response = $this->actingAs($sender)->post(route('users.gifts.store', ['user' => $receiver]), [
'sender_id' => $sender->id,
'recipient_username' => $receiver->username,
'message' => 'foo',
'bon' => 100.00,
]);
// The transaction must complete to trigger a notification
$this->assertDatabaseHas('gifts', [
'bon' => '100.00',
'sender_id' => $sender->id,
'recipient_id' => $receiver->id,
]);
Notification::assertCount(0);
});
test('gift a user does not create a notification for the gifted user when gift notifications are disabled for specific group', function (): void {
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create();
$sender = User::factory()->create([
'group_id' => $group->id,
'seedbonus' => 1000,
]);
$receiver = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $receiver->id,
'block_notifications' => 0,
'show_bon_gift' => 1,
'json_bon_groups' => [$group->id],
]);
$response = $this->actingAs($sender)->post(route('users.gifts.store', ['user' => $receiver]), [
'sender_id' => $sender->id,
'recipient_username' => $receiver->username,
'message' => 'foo',
'bon' => 100.00,
]);
// The transaction must complete to trigger a notification
$this->assertDatabaseHas('gifts', [
'bon' => '100.00',
'sender_id' => $sender->id,
'recipient_id' => $receiver->id,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,174 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Article;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewComment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('user comments on article creates a notification for staff', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$staffNotificationSettings = UserNotification::factory()->for($staff)->create([
'block_notifications' => 0,
]);
$article = Article::factory()->for($staff)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($user)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$staff],
NewComment::class
);
Notification::assertCount(1);
});
test('staff comments on own article does not create a notification for staff', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$staffNotificationSettings = UserNotification::factory()->for($staff)->create([
'block_notifications' => 0,
]);
$article = Article::factory()->for($staff)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($staff)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('user comments on article does not a notification for staff user when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$staffNotificationSettings = UserNotification::factory()->for($staff)->create([
'block_notifications' => 1,
]);
$article = Article::factory()->for($staff)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($user)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
@@ -0,0 +1,348 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Article;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewCommentTag;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('user tags user on article creates a notification for tagged user', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_article_comment' => 1,
]);
$article = Article::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
// Tag notification for user and notification for staff article poster gets sent
Notification::assertCount(2);
});
test('staff tags user on article creates a notification for tagged user even when mentions are disabled for other specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$randomGroup = Group::factory()->create();
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_article_comment' => 1,
'json_mention_groups' => [$randomGroup->id],
]);
$article = Article::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
// Tag notification for user and notification for staff article poster gets sent
Notification::assertCount(2);
});
test('user tags user on article creates a notification for tagged user when mentions are disabled for other specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$randomGroup = Group::factory()->create();
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_article_comment' => 1,
'json_mention_groups' => [$randomGroup->id],
]);
$article = Article::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
// Tag notification for user and notification for staff article poster gets sent
Notification::assertCount(2);
});
test('user tags user on article does not create a notification for tagged user when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 1,
'show_mention_article_comment' => 1,
]);
$article = Article::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
test('user tags user on article does not create a notification for tagged user when mention notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_article_comment' => 0,
]);
$article = Article::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
test('user tags user on article does not create a notification for tagged user when mention notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_article_comment' => 1,
'json_mention_groups' => [$group->id],
]);
$article = Article::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $article])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
@@ -0,0 +1,165 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\Playlist;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewComment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('comments on playlist creates a notification for playlist owner', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$owner = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$ownerNotificationSettings = UserNotification::factory()->for($owner)->create([
'block_notifications' => 0,
]);
$playlist = Playlist::factory()->for($owner)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $playlist])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$owner],
NewComment::class
);
Notification::assertCount(1);
});
test('user comments on own playlist does not create a notification for self', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$owner = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$ownerNotificationSettings = UserNotification::factory()->for($owner)->create([
'block_notifications' => 0,
]);
$playlist = Playlist::factory()->for($owner)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($owner)
->test(Comments::class, ['model' => $playlist])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comments on playlist does not create a notification for playlist owner when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$owner = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$ownerNotificationSettings = UserNotification::factory()->for($owner)->create([
'block_notifications' => 1,
]);
$playlist = Playlist::factory()->for($owner)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $playlist])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
@@ -0,0 +1,330 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\TorrentRequest;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewComment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('comment own request does not create a notification for self', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$requester = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($requester)->create([
'block_notifications' => 0,
'show_request_comment' => 1,
]);
$torrentRequest = TorrentRequest::factory()->for($requester)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($requester)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comment a request creates a notification for the requester', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$requester = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($requester)->create([
'block_notifications' => 0,
'show_request_comment' => 1,
]);
$torrentRequest = TorrentRequest::factory()->for($requester)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$requester],
NewComment::class
);
Notification::assertCount(1);
});
test('comment a request creates a notification for the requester when request comment notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$randomGroup = Group::factory()->create();
$requester = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($requester)->create([
'block_notifications' => 0,
'show_request_comment' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$torrentRequest = TorrentRequest::factory()->for($requester)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$requester],
NewComment::class
);
Notification::assertCount(1);
});
test('comment a request creates a notification for the requester when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$requester = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($requester)->create([
'block_notifications' => 1,
'show_request_comment' => 1,
]);
$torrentRequest = TorrentRequest::factory()->for($requester)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comment a request creates a notification for the requester when request comment notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$requester = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($requester)->create([
'block_notifications' => 0,
'show_request_comment' => 0,
]);
$torrentRequest = TorrentRequest::factory()->for($requester)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comment a request creates a notification for the requester when request comment notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$requester = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($requester)->create([
'block_notifications' => 0,
'show_request_comment' => 1,
'json_request_groups' => [$group->id],
]);
$torrentRequest = TorrentRequest::factory()->for($requester)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
@@ -0,0 +1,252 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\Ticket;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewComment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('user comments own ticket does not create a notification for self but assigned staff', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->for($user)->create([
'block_notifications' => 0,
]);
$staffNotificationSettings = UserNotification::factory()->for($staff)->create([
'block_notifications' => 0,
]);
$ticket = Ticket::factory()->create([
'user_id' => $user->id,
'staff_id' => $staff->id,
]);
$commentText = 'This is a test comment';
Livewire::actingAs($user)
->test(Comments::class, ['model' => $ticket])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$staff],
NewComment::class
);
Notification::assertCount(1);
});
test('user comments own ticket does not create a notification for staff when none is assigned', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->for($user)->create([
'block_notifications' => 0,
]);
$ticket = Ticket::factory()->for($user)->create([
'staff_id' => null,
]);
$commentText = 'This is a test comment';
Livewire::actingAs($user)
->test(Comments::class, ['model' => $ticket])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('staff comments a ticket creates a notification for the user but not staff', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->for($user)->create([
'block_notifications' => 0,
]);
$ticket = Ticket::factory()->for($user)->create([
'staff_id' => $staff->id,
]);
$commentText = 'This is a test comment';
Livewire::actingAs($staff)
->test(Comments::class, ['model' => $ticket])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewComment::class
);
Notification::assertCount(1);
});
test('staff comments a ticket create a notification for the user even when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$staffGroup = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$staff = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->for($user)->create([
'block_notifications' => 1,
]);
$ticket = Ticket::factory()->for($user)->create([
'staff_id' => $staff->id,
]);
$commentText = 'This is a test comment';
Livewire::actingAs($staff)
->test(Comments::class, ['model' => $ticket])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewComment::class
);
Notification::assertCount(1);
});
@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\Ticket;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewCommentTag;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('user tags user on ticket creates a notification for tagged user', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'is_admin' => true,
]);
$staff = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $staffGroup->id,
]);
$commenter = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$staffNotificationSettings = UserNotification::factory()->create([
'user_id' => $staff->id,
'block_notifications' => 0,
]);
$ticket = Ticket::factory()->create([
'staff_id' => $staff->id,
]);
$commentText = '@'.$staff->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $ticket])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$staff],
NewCommentTag::class
);
// Tag notification for user and notification for staff ticket poster gets sent
Notification::assertCount(3);
});
test('user tags user on ticket does not create a notification for tagged user when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$staffGroup = Group::factory()->create([
'is_admin' => true,
]);
$staff = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $staffGroup->id,
]);
$commenter = User::factory()->create([
'group_id' => $staffGroup->id,
'can_comment' => true,
]);
$staffNotificationSettings = UserNotification::factory()->create([
'user_id' => $staff->id,
'block_notifications' => 1,
]);
$ticket = Ticket::factory()->create([
'staff_id' => $staff->id,
]);
$commentText = '@'.$staff->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $ticket])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$staff],
NewCommentTag::class
);
});
@@ -0,0 +1,330 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\Torrent;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewComment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('comment own torrent does not create a notification for self', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$uploaderNotificationSettings = UserNotification::factory()->for($uploader)->create([
'block_notifications' => 0,
'show_torrent_comment' => 1,
]);
$torrent = Torrent::factory()->for($uploader)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($uploader)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comment a torrent creates a notification for the uploader', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($uploader)->create([
'block_notifications' => 0,
'show_torrent_comment' => 1,
]);
$torrent = Torrent::factory()->for($uploader)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$uploader],
NewComment::class
);
Notification::assertCount(1);
});
test('comment a torrent creates a notification for the requester when request comment notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$randomGroup = Group::factory()->create();
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($uploader)->create([
'block_notifications' => 0,
'show_torrent_comment' => 1,
'json_torrent_groups' => [$randomGroup->id],
]);
$torrent = Torrent::factory()->for($uploader)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$uploader],
NewComment::class
);
Notification::assertCount(1);
});
test('comment a torrent creates a notification for the requester when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($uploader)->create([
'block_notifications' => 1,
'show_torrent_comment' => 1,
]);
$torrent = Torrent::factory()->for($uploader)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comment a torrent creates a notification for the requester when request comment notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($uploader)->create([
'block_notifications' => 0,
'show_torrent_comment' => 0,
]);
$torrent = Torrent::factory()->for($uploader)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
test('comment a torrent creates a notification for the requester when request comment notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'can_request' => true,
]);
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
'can_request' => true,
]);
$fillerNotificationSettings = UserNotification::factory()->for($uploader)->create([
'block_notifications' => 0,
'show_torrent_comment' => 1,
'json_torrent_groups' => [$group->id],
]);
$torrent = Torrent::factory()->for($uploader)->create();
$commentText = 'This is a test comment';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertCount(0);
});
@@ -0,0 +1,290 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\TorrentRequest;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewCommentTag;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('user tags user on request creates a notification for tagged user', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_request_comment' => 1,
]);
$torrentRequest = TorrentRequest::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
Notification::assertCount(1);
});
test('user tags user on request creates a notification for tagged user when mentions are disabled for other specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$randomGroup = Group::factory()->create();
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_request_comment' => 1,
'json_mention_groups' => [$randomGroup->id],
]);
$torrentRequest = TorrentRequest::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
Notification::assertCount(1);
});
test('user tags user on request does not create a notification for tagged user when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 1,
'show_mention_request_comment' => 1,
]);
$torrentRequest = TorrentRequest::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
test('user tags user on request does not create a notification for tagged user when mention notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_request_comment' => 0,
]);
$torrentRequest = TorrentRequest::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
test('user tags user on request does not create a notification for tagged user when mention notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_request_comment' => 1,
'json_mention_groups' => [$group->id],
]);
$torrentRequest = TorrentRequest::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrentRequest])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
@@ -0,0 +1,290 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Http\Livewire\Comments;
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Comment;
use App\Models\Group;
use App\Models\Torrent;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewCommentTag;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('user tags user on torrent creates a notification for tagged user', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_torrent_comment' => 1,
]);
$torrent = Torrent::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
Notification::assertCount(1);
});
test('user tags user on torrent creates a notification for tagged user when mentions are disabled for other specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$randomGroup = Group::factory()->create();
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_torrent_comment' => 1,
'json_mention_groups' => [$randomGroup->id],
]);
$torrent = Torrent::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertSentTo(
[$user],
NewCommentTag::class
);
Notification::assertCount(1);
});
test('user tags user on torrent does not create a notification for tagged user when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 1,
'show_mention_torrent_comment' => 1,
]);
$torrent = Torrent::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
test('user tags user on torrent does not create a notification for tagged user when mention notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_torrent_comment' => 0,
]);
$torrent = Torrent::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
test('user tags user on torrent does not create a notification for tagged user when mention notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$commenter = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_torrent_comment' => 1,
'json_mention_groups' => [$group->id],
]);
$torrent = Torrent::factory()->create();
$commentText = '@'.$user->username.' Test';
Livewire::actingAs($commenter)
->test(Comments::class, ['model' => $torrent])
->set('newCommentState', $commentText)
->set('anon', false)
->call('postComment');
$this->assertEquals(1, Comment::count());
Notification::assertNotSentTo(
[$user],
NewCommentTag::class
);
});
@@ -0,0 +1,131 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Group;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewFollow;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('follow a user creates a notification for the followed user', function (): void {
Notification::fake();
$follower = User::factory()->create();
$followed = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_follow' => 1,
]);
// $follower starts following $followed
$response = $this->actingAs($follower)->post(route('users.followers.store', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-user'), $followed->username));
Notification::assertSentTo(
[$followed],
NewFollow::class
);
Notification::assertCount(1);
});
test('follow a user does not create a notification for the followed user when all notifications disabled', function (): void {
Notification::fake();
$group = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 1,
'show_account_follow' => 1,
]);
// $follower starts following $followed
$response = $this->actingAs($follower)->post(route('users.followers.store', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-user'), $followed->username));
Notification::assertCount(0);
});
test('follow a user does not create a notification for the followed user when following notifications are disabled', function (): void {
Notification::fake();
$group = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_follow' => 0,
]);
// $follower starts following $followed
$response = $this->actingAs($follower)->post(route('users.followers.store', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-user'), $followed->username));
Notification::assertCount(0);
});
test('follow a user does not create a notification for the followed user when following notifications are disabled for specific group', function (): void {
Notification::fake();
$group = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_follow' => 1,
'json_following_groups' => [$group->id],
]);
// $follower starts following $followed
$response = $this->actingAs($follower)->post(route('users.followers.store', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-user'), $followed->username));
Notification::assertCount(0);
});
@@ -0,0 +1,340 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Forum;
use App\Models\ForumPermission;
use App\Models\Group;
use App\Models\Post;
use App\Models\Topic;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewPost;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('post in a topic creates a notification for the topic creator', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 0,
'show_forum_topic' => 1,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$topicOwner],
NewPost::class
);
Notification::assertCount(1);
});
test('post in a topic creates a notification for the topic creator when post notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 0,
'show_forum_topic' => 1,
'json_forum_groups' => [$randomGroup->id],
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$topicOwner],
NewPost::class
);
Notification::assertCount(1);
});
test('post in a topic does not create a notification for the topic creator when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 1,
'show_forum_topic' => 1,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertCount(0);
});
test('post in a topic does not create a notification for the topic creator when post notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 0,
'show_forum_topic' => 0,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertCount(0);
});
test('post in a topic does not create a notification for the topic creator when post notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 0,
'show_forum_topic' => 1,
'json_forum_groups' => [$group->id],
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,396 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Forum;
use App\Models\ForumPermission;
use App\Models\Group;
use App\Models\Post;
use App\Models\Subscription;
use App\Models\Topic;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewPost;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('post in a topic creates a notification for the topic subscriber', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$topicOwnerNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 1,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_topic' => 1,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$topicSubscription = Subscription::factory()->create([
'user_id' => $subscriber->id,
'forum_id' => $forum->id,
'topic_id' => $topic->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$subscriber],
NewPost::class
);
});
test('post in a topic creates a notification for the topic subscriber when subscriber notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$topicOwnerNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 1,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_topic' => 1,
'json_subscription_groups' => [$randomGroup->id],
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$topicSubscription = Subscription::factory()->create([
'user_id' => $subscriber->id,
'forum_id' => $forum->id,
'topic_id' => $topic->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$subscriber],
NewPost::class
);
});
test('post in a topic does not create a notification for the topic subscriber when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$topicOwnerNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 1,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 1,
'show_subscription_topic' => 1,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$topicSubscription = Subscription::factory()->create([
'user_id' => $subscriber->id,
'forum_id' => $forum->id,
'topic_id' => $topic->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertCount(0);
});
test('post in a topic does not create a notification for the topic subscriber when topic subscription notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$topicOwnerNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 1,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_topic' => 0,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$topicSubscription = Subscription::factory()->create([
'user_id' => $subscriber->id,
'forum_id' => $forum->id,
'topic_id' => $topic->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertCount(0);
});
test('post in a topic does not create a notification for the topic subscriber when topic subscription notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$topicOwner = User::factory()->create();
$poster = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$topicOwnerNotificationSettings = UserNotification::factory()->create([
'user_id' => $topicOwner->id,
'block_notifications' => 1,
'show_forum_topic' => 1,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_topic' => 1,
'json_subscription_groups' => [$group->id],
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$topicSubscription = Subscription::factory()->create([
'user_id' => $subscriber->id,
'forum_id' => $forum->id,
'topic_id' => $topic->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => 'Test Post',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,460 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Group;
use App\Models\Forum;
use App\Models\ForumPermission;
use App\Models\Topic;
use App\Models\Post;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewPostTag;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('user tags user in forum topic creates a notification for tagged user', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$poster = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$topicOwner = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_forum_post' => 1,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => '@'.$user->username.' Test',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$user],
NewPostTag::class
);
Notification::assertCount(1);
});
test('user tags user in forum topic creates a notification for tagged user when post mention notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$randomGroup = Group::factory()->create();
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$poster = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$topicOwner = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_forum_post' => 1,
'json_mention_groups' => [$randomGroup->id],
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => '@'.$user->username.' Test',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$user],
NewPostTag::class
);
Notification::assertCount(1);
});
test('user tags user in forum topic does not create a notification for tagged user when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$poster = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$topicOwner = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 1,
'show_mention_forum_post' => 1,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => '@'.$user->username.' Test',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertNotSentTo(
[$user],
NewPostTag::class
);
Notification::assertCount(0);
});
test('staff tags user in forum topic creates a notification for tagged user even when post mention notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
'is_modo' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$poster = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$topicOwner = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_forum_post' => 0,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => '@'.$user->username.' Test',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertSentTo(
[$user],
NewPostTag::class
);
Notification::assertCount(1);
});
test('user tags user in forum topic does not create a notification for tagged user when post mention notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$poster = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$topicOwner = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_forum_post' => 0,
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => '@'.$user->username.' Test',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertNotSentTo(
[$user],
NewPostTag::class
);
Notification::assertCount(0);
});
test('user tags user in forum topic does not create a notification for tagged user when post mention notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_comment' => true,
]);
$user = User::factory()->create([
'username' => 'TestUsername',
'group_id' => $group->id,
'can_comment' => true,
]);
$poster = User::factory()->create([
'group_id' => $group->id,
'can_comment' => true,
]);
$topicOwner = User::factory()->create();
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $user->id,
'block_notifications' => 0,
'show_mention_forum_post' => 1,
'json_mention_groups' => [$group->id],
]);
$forum = Forum::factory()->create();
$forumPermissions = ForumPermission::factory()->create([
'forum_id' => $forum->id,
'group_id' => $group->id,
'read_topic' => 1,
'reply_topic' => 1,
]);
$topic = Topic::factory()->create([
'forum_id' => $forum->id,
'state' => 'open',
'first_post_user_id' => $topicOwner->id,
]);
$post = Post::factory()->create([
'user_id' => $topicOwner->id,
'topic_id' => $topic->id,
'content' => 'First Post',
]);
$response = $this->actingAs($poster)->post(route('posts.store'), [
'topic_id' => $topic->id,
'content' => '@'.$user->username.' Test',
]);
$response->assertRedirect();
$this->assertDatabaseHas('posts', [
'topic_id' => $topic->id,
'user_id' => $poster->id,
]);
Notification::assertNotSentTo(
[$user],
NewPostTag::class
);
Notification::assertCount(0);
});
@@ -0,0 +1,303 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Group;
use App\Models\TorrentRequest;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewRequestBounty;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('add bounty to request creates a notification for the requester', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_request' => true,
]);
$requester = User::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
'can_request' => true,
'seedbonus' => 1000,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_bounty' => 1,
]);
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'filled_by' => null,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$bounty = 100;
$response = $this->actingAs($user)->post(route('requests.bounties.store', ['torrentRequest' => $torrentRequest]), [
'seedbonus' => $bounty,
'anon' => false,
]);
$this->assertDatabaseHas('request_bounty', [
'requests_id' => $torrentRequest->id,
'seedbonus' => $bounty,
]);
Notification::assertSentTo(
[$requester],
NewRequestBounty::class
);
Notification::assertCount(1);
});
test('add bounty to request creates a notification for the requester when bounty notifications not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_request' => true,
]);
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
'can_request' => true,
'seedbonus' => 1000,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_bounty' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'filled_by' => null,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$bounty = 100;
$response = $this->actingAs($user)->post(route('requests.bounties.store', ['torrentRequest' => $torrentRequest]), [
'seedbonus' => $bounty,
'anon' => false,
]);
$this->assertDatabaseHas('request_bounty', [
'requests_id' => $torrentRequest->id,
'seedbonus' => $bounty,
]);
Notification::assertSentTo(
[$requester],
NewRequestBounty::class
);
Notification::assertCount(1);
});
test('add bounty to request does not create a notification for the requester when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_request' => true,
]);
$requester = User::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
'can_request' => true,
'seedbonus' => 1000,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 1,
'show_request_bounty' => 1,
]);
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'filled_by' => null,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$bounty = 100;
$response = $this->actingAs($user)->post(route('requests.bounties.store', ['torrentRequest' => $torrentRequest]), [
'seedbonus' => $bounty,
'anon' => false,
]);
$this->assertDatabaseHas('request_bounty', [
'requests_id' => $torrentRequest->id,
'seedbonus' => $bounty,
]);
Notification::assertCount(0);
});
test('add bounty to request does not create a notification for the requester when request bounty notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_request' => true,
]);
$requester = User::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
'can_request' => true,
'seedbonus' => 1000,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_bounty' => 0,
]);
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'filled_by' => null,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$bounty = 100;
$response = $this->actingAs($user)->post(route('requests.bounties.store', ['torrentRequest' => $torrentRequest]), [
'seedbonus' => $bounty,
'anon' => false,
]);
$this->assertDatabaseHas('request_bounty', [
'requests_id' => $torrentRequest->id,
'seedbonus' => $bounty,
]);
Notification::assertCount(0);
});
test('add bounty to request does not create a notification for the requester when request bounty notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create([
'can_request' => true,
]);
$requester = User::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
'can_request' => true,
'seedbonus' => 1000,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_bounty' => 1,
'json_request_groups' => [$group->id],
]);
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'filled_by' => null,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$bounty = 100;
$response = $this->actingAs($user)->post(route('requests.bounties.store', ['torrentRequest' => $torrentRequest]), [
'seedbonus' => $bounty,
'anon' => false,
]);
$this->assertDatabaseHas('request_bounty', [
'requests_id' => $torrentRequest->id,
'seedbonus' => $bounty,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,275 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Category;
use App\Models\Group;
use App\Models\Resolution;
use App\Models\TorrentRequest;
use App\Models\Torrent;
use App\Models\Type;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewRequestClaim;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('claim a request creates a notification for the requester', function (): void {
Notification::fake();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_claim' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($filler)->post(route('requests.claims.store', [$torrentRequest]), [
'anon' => 0,
]);
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.claimed-success'));
Notification::assertSentTo(
[$requester],
NewRequestClaim::class
);
Notification::assertCount(1);
});
test('claim a request creates a notification for the requester when claim notifications not disabled for specific group', function (): void {
Notification::fake();
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([]);
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_claim' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($filler)->post(route('requests.claims.store', [$torrentRequest]), [
'anon' => 0,
]);
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.claimed-success'));
Notification::assertSentTo(
[$requester],
NewRequestClaim::class
);
Notification::assertCount(1);
});
test('claim a request creates a notification for the requester when all notifications are disabled', function (): void {
Notification::fake();
$requester = User::factory()->create();
$filler = User::factory()->create([]);
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 1,
'show_request_claim' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($filler)->post(route('requests.claims.store', [$torrentRequest]), [
'anon' => 0,
]);
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.claimed-success'));
Notification::assertCount(0);
});
test('claim a request creates a notification for the requester when request claim notifications are disabled', function (): void {
Notification::fake();
$requester = User::factory()->create();
$filler = User::factory()->create([]);
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_claim' => 0,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($filler)->post(route('requests.claims.store', [$torrentRequest]), [
'anon' => 0,
]);
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.claimed-success'));
Notification::assertCount(0);
});
test('claim a request creates a notification for the requester when request claim notifications are disabled for specific group', function (): void {
Notification::fake();
$group = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_claim' => 0,
'json_request_groups' => [$group->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($filler)->post(route('requests.claims.store', [$torrentRequest]), [
'anon' => 0,
]);
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.claimed-success'));
Notification::assertCount(0);
});
@@ -0,0 +1,314 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Category;
use App\Models\Group;
use App\Models\Resolution;
use App\Models\TorrentRequest;
use App\Models\Torrent;
use App\Models\Type;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewRequestFillApprove;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('accept a request fill creates a notification for the filler', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_approve' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->post(route('requests.approved_fills.store', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest));
Notification::assertSentTo(
[$filler],
NewRequestFillApprove::class
);
Notification::assertCount(1);
});
test('accept a request fill creates a notification for the filler when request accept notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_approve' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->post(route('requests.approved_fills.store', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest));
Notification::assertSentTo(
[$filler],
NewRequestFillApprove::class
);
Notification::assertCount(1);
});
test('accept a request fill creates a notification for the filler when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 1,
'show_request_fill_approve' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->post(route('requests.approved_fills.store', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest));
Notification::assertCount(0);
});
test('accept a request fill creates a notification for the filler when fill approve notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_approve' => 0,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->post(route('requests.approved_fills.store', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest));
Notification::assertCount(0);
});
test('accept a request fill creates a notification for the filler when request notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$requester = User::factory()->create([
'group_id' => $group->id,
]);
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_approve' => 1,
'json_request_groups' => [$group->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->post(route('requests.approved_fills.store', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest));
Notification::assertCount(0);
});
@@ -0,0 +1,327 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Category;
use App\Models\Group;
use App\Models\Resolution;
use App\Models\TorrentRequest;
use App\Models\Torrent;
use App\Models\Type;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewRequestFill;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('fill a request creates a notification for the request creator', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_fill' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'filled_by' => null,
'torrent_id' => null,
'claimed' => false,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$response = $this->actingAs($filler)->post(route('requests.fills.store', [$torrentRequest]), [
'torrent_id' => $torrent->id,
'filled_anon' => 0,
]);
Notification::assertSentTo(
[$requester],
NewRequestFill::class
);
Notification::assertCount(1);
});
test('fill a request creates a notification for the request creator when request-fill notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_fill' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'filled_by' => null,
'torrent_id' => null,
'claimed' => false,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$response = $this->actingAs($filler)->post(route('requests.fills.store', [$torrentRequest]), [
'torrent_id' => $torrent->id,
'filled_anon' => 0,
]);
Notification::assertSentTo(
[$requester],
NewRequestFill::class
);
Notification::assertCount(1);
});
test('fill a request does not create a notification for the request creator when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 1,
'show_request_fill' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'filled_by' => null,
'torrent_id' => null,
'claimed' => false,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$response = $this->actingAs($filler)->post(route('requests.fills.store', [$torrentRequest]), [
'torrent_id' => $torrent->id,
'filled_anon' => 0,
]);
Notification::assertCount(0);
});
test('fill a request does not create a notification for the request creator when request notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_fill' => 0,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'filled_by' => null,
'torrent_id' => null,
'claimed' => false,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$response = $this->actingAs($filler)->post(route('requests.fills.store', [$torrentRequest]), [
'torrent_id' => $torrent->id,
'filled_anon' => 0,
]);
Notification::assertCount(0);
});
test('fill a request does not create a notification for the request creator when request notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$requesterNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_fill' => 1,
'json_request_groups' => [$group->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrentRequest = TorrentRequest::factory()->create([
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'filled_by' => null,
'torrent_id' => null,
'claimed' => false,
'filled_when' => null,
'approved_by' => null,
'approved_when' => null,
]);
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$response = $this->actingAs($filler)->post(route('requests.fills.store', [$torrentRequest]), [
'torrent_id' => $torrent->id,
'filled_anon' => 0,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,317 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Category;
use App\Models\Group;
use App\Models\Resolution;
use App\Models\TorrentRequest;
use App\Models\Torrent;
use App\Models\Type;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewRequestFillReject;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('decline a request fill creates a notification for the filler', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_reject' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->delete(route('requests.fills.destroy', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.request-reset'));
Notification::assertSentTo(
[$filler],
NewRequestFillReject::class
);
Notification::assertCount(1);
});
test('decline a request fill creates a notification for the filler when request reject notifications are not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_reject' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->delete(route('requests.fills.destroy', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.request-reset'));
Notification::assertSentTo(
[$filler],
NewRequestFillReject::class
);
Notification::assertCount(1);
});
test('decline a request fill does not create a notification for the filler when all notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 1,
'show_request_fill_reject' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->delete(route('requests.fills.destroy', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.request-reset'));
Notification::assertCount(0);
});
test('decline a request fill does not create a notification for the filler when fill rejected notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_reject' => 0,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->delete(route('requests.fills.destroy', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.request-reset'));
Notification::assertCount(0);
});
test('decline a request fill does not create a notification for the filler when fill rejected notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$requester = User::factory()->create([
'group_id' => $group->id,
]);
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $filler->id,
'block_notifications' => 0,
'show_request_fill_reject' => 0,
'json_request_groups' => [$group->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => $torrent->id,
'claimed' => true,
'filled_by' => $filler->id,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$response = $this->actingAs($requester)->delete(route('requests.fills.destroy', [$torrentRequest]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.request-reset'));
Notification::assertCount(0);
});
@@ -0,0 +1,303 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Category;
use App\Models\Group;
use App\Models\Resolution;
use App\Models\TorrentRequest;
use App\Models\TorrentRequestClaim;
use App\Models\Torrent;
use App\Models\Type;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewRequestUnclaim;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('unclaim a request creates a notification for the requester', function (): void {
Notification::fake();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_unclaim' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$torrentRequestClaim = TorrentRequestClaim::factory()->create([
'request_id' => $torrentRequest->id,
'user_id' => $filler->id,
]);
$response = $this->actingAs($filler)->delete(route('requests.claims.destroy', ['torrentRequest' => $torrentRequest, 'claim' => $torrentRequest->claim]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.unclaimed-success'));
Notification::assertSentTo(
[$requester],
NewRequestUnclaim::class
);
Notification::assertCount(1);
});
test('unclaim a request creates a notification for the requester when claim notifications not disabled for specific group', function (): void {
Notification::fake();
$randomGroup = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_unclaim' => 1,
'json_request_groups' => [$randomGroup->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$torrentRequestClaim = TorrentRequestClaim::factory()->create([
'request_id' => $torrentRequest->id,
'user_id' => $filler->id,
]);
$response = $this->actingAs($filler)->delete(route('requests.claims.destroy', ['torrentRequest' => $torrentRequest, 'claim' => $torrentRequest->claim]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.unclaimed-success'));
Notification::assertSentTo(
[$requester],
NewRequestUnclaim::class
);
Notification::assertCount(1);
});
test('unclaim a request does not create a notification for the requester when all notifications disabled', function (): void {
Notification::fake();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 1,
'show_request_unclaim' => 1,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$torrentRequestClaim = TorrentRequestClaim::factory()->create([
'request_id' => $torrentRequest->id,
'user_id' => $filler->id,
]);
$response = $this->actingAs($filler)->delete(route('requests.claims.destroy', ['torrentRequest' => $torrentRequest, 'claim' => $torrentRequest->claim]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.unclaimed-success'));
$this->assertDatabaseMissing('request_claims', [
'request_id' => $torrentRequest->id,
]);
Notification::assertCount(0);
});
test('unclaim a request does not create a notification for the requester when request unclaim notifications are disabled', function (): void {
Notification::fake();
$requester = User::factory()->create();
$filler = User::factory()->create();
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_unclaim' => 0,
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$torrentRequestClaim = TorrentRequestClaim::factory()->create([
'request_id' => $torrentRequest->id,
'user_id' => $filler->id,
]);
$response = $this->actingAs($filler)->delete(route('requests.claims.destroy', ['torrentRequest' => $torrentRequest, 'claim' => $torrentRequest->claim]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.unclaimed-success'));
$this->assertDatabaseMissing('request_claims', [
'request_id' => $torrentRequest->id,
]);
Notification::assertCount(0);
});
test('unclaim a request does not create a notification for the requester when request unclaim notifications are disabled for specific group', function (): void {
Notification::fake();
$group = Group::factory()->create();
$requester = User::factory()->create();
$filler = User::factory()->create([
'group_id' => $group->id,
]);
$fillerNotificationSettings = UserNotification::factory()->create([
'user_id' => $requester->id,
'block_notifications' => 0,
'show_request_unclaim' => 1,
'json_request_groups' => [$group->id],
]);
$category = Category::factory()->create();
$type = Type::factory()->create();
$resolution = Resolution::factory()->create();
$torrent = Torrent::factory()->create([
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
]);
$torrentRequest = TorrentRequest::factory()->create([
'anon' => false,
'user_id' => $requester->id,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'torrent_id' => null,
'claimed' => null,
'filled_by' => null,
'filled_when' => now(),
'approved_by' => null,
'approved_when' => null,
]);
$torrentRequestClaim = TorrentRequestClaim::factory()->create([
'request_id' => $torrentRequest->id,
'user_id' => $filler->id,
]);
$response = $this->actingAs($filler)->delete(route('requests.claims.destroy', ['torrentRequest' => $torrentRequest, 'claim' => $torrentRequest->claim]));
$response->assertRedirect(route('requests.show', $torrentRequest))
->assertSessionHas('success', trans('request.unclaimed-success'));
$this->assertDatabaseMissing('request_claims', [
'request_id' => $torrentRequest->id,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,340 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Chatroom;
use App\Models\Forum;
use App\Models\ForumPermission;
use App\Models\Group;
use App\Models\Subscription;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewTopic;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('create a topic in a subscribed forum creates a notification for the subscriber', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_forum' => 1,
]);
$forum = Forum::factory()->create();
$forumPermission = ForumPermission::factory()->create([
'group_id' => $group->id,
'forum_id' => $forum->id,
'start_topic' => true,
'read_topic' => true,
]);
$forumSubscription = Subscription::factory()->create([
'forum_id' => $forum->id,
'topic_id' => null,
'user_id' => $subscriber->id,
]);
$postData = [
'title' => 'Sample Topic Title',
'content' => 'This is the test content.',
];
$response = $this->actingAs($user)->post(route('topics.store', ['id' => $forum->id]), [
'title' => $postData['title'],
'content' => $postData['content'],
]);
$this->assertDatabaseHas('topics', [
'name' => $postData['title'],
'first_post_user_id' => $user->id,
'forum_id' => $forum->id,
]);
Notification::assertSentTo(
[$subscriber],
NewTopic::class
);
Notification::assertCount(1);
});
test('create a topic in a subscribed forum creates a notification for the subscriber when subscribe notifications not disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_forum' => 1,
'json_subscription_groups' => [$randomGroup->id],
]);
$forum = Forum::factory()->create();
$forumPermission = ForumPermission::factory()->create([
'group_id' => $group->id,
'forum_id' => $forum->id,
'start_topic' => true,
'read_topic' => true,
]);
$forumSubscription = Subscription::factory()->create([
'forum_id' => $forum->id,
'topic_id' => null,
'user_id' => $subscriber->id,
]);
$postData = [
'title' => 'Sample Topic Title',
'content' => 'This is the test content.',
];
$response = $this->actingAs($user)->post(route('topics.store', ['id' => $forum->id]), [
'title' => $postData['title'],
'content' => $postData['content'],
]);
$this->assertDatabaseHas('topics', [
'name' => $postData['title'],
'first_post_user_id' => $user->id,
'forum_id' => $forum->id,
]);
Notification::assertSentTo(
[$subscriber],
NewTopic::class
);
Notification::assertCount(1);
});
test('create a topic in a subscribed forum does not create a notification for the subscriber when all notifications disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 1,
'show_subscription_forum' => 1,
]);
$forum = Forum::factory()->create();
$forumPermission = ForumPermission::factory()->create([
'group_id' => $group->id,
'forum_id' => $forum->id,
'start_topic' => true,
'read_topic' => true,
]);
$forumSubscription = Subscription::factory()->create([
'forum_id' => $forum->id,
'topic_id' => null,
'user_id' => $subscriber->id,
]);
$postData = [
'title' => 'Sample Topic Title',
'content' => 'This is the test content.',
];
$response = $this->actingAs($user)->post(route('topics.store', ['id' => $forum->id]), [
'title' => $postData['title'],
'content' => $postData['content'],
]);
$this->assertDatabaseHas('topics', [
'name' => $postData['title'],
'first_post_user_id' => $user->id,
'forum_id' => $forum->id,
]);
Notification::assertCount(0);
});
test('create a topic in a subscribed forum does not create a notification for the subscriber when forum subscribe notifications are disabled', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_forum' => 0,
]);
$forum = Forum::factory()->create();
$forumPermission = ForumPermission::factory()->create([
'group_id' => $group->id,
'forum_id' => $forum->id,
'start_topic' => true,
'read_topic' => true,
]);
$forumSubscription = Subscription::factory()->create([
'forum_id' => $forum->id,
'topic_id' => null,
'user_id' => $subscriber->id,
]);
$postData = [
'title' => 'Sample Topic Title',
'content' => 'This is the test content.',
];
$response = $this->actingAs($user)->post(route('topics.store', ['id' => $forum->id]), [
'title' => $postData['title'],
'content' => $postData['content'],
]);
$this->assertDatabaseHas('topics', [
'name' => $postData['title'],
'first_post_user_id' => $user->id,
'forum_id' => $forum->id,
]);
Notification::assertCount(0);
});
test('create a topic in a subscribed forum does not create a notification for the subscriber when forum subscribe notifications are disabled for specific group', function (): void {
Notification::fake();
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
$group = Group::factory()->create();
$user = User::factory()->create([
'group_id' => $group->id,
]);
$subscriber = User::factory()->create([
'group_id' => $group->id,
]);
$subscriberNotificationSettings = UserNotification::factory()->create([
'user_id' => $subscriber->id,
'block_notifications' => 0,
'show_subscription_forum' => 1,
'json_subscription_groups' => [$group->id],
]);
$forum = Forum::factory()->create();
$forumPermission = ForumPermission::factory()->create([
'group_id' => $group->id,
'forum_id' => $forum->id,
'start_topic' => true,
'read_topic' => true,
]);
$forumSubscription = Subscription::factory()->create([
'forum_id' => $forum->id,
'topic_id' => null,
'user_id' => $subscriber->id,
]);
$postData = [
'title' => 'Sample Topic Title',
'content' => 'This is the test content.',
];
$response = $this->actingAs($user)->post(route('topics.store', ['id' => $forum->id]), [
'title' => $postData['title'],
'content' => $postData['content'],
]);
$this->assertDatabaseHas('topics', [
'name' => $postData['title'],
'first_post_user_id' => $user->id,
'forum_id' => $forum->id,
]);
Notification::assertCount(0);
});
@@ -0,0 +1,174 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Group;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewUnfollow;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('unfollow a user creates a notification for the followed user', function (): void {
Notification::fake();
$follower = User::factory()->create();
$followed = User::factory()->create();
$followed->followers()->attach($follower->id);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_unfollow' => 1,
]);
// $follower unfollows $followed
$response = $this->actingAs($follower)->delete(route('users.followers.destroy', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-revoked'), $followed->username));
Notification::assertSentTo(
[$followed],
NewUnfollow::class
);
Notification::assertCount(1);
});
test('unfollow a user creates a notification for the followed user when following notifications are not disabled for specific group', function (): void {
Notification::fake();
$group = Group::factory()->create();
$randomGroup = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$followed->followers()->attach($follower->id);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_unfollow' => 1,
'json_account_groups' => [$randomGroup->id],
]);
// $follower unfollows $followed
$response = $this->actingAs($follower)->delete(route('users.followers.destroy', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-revoked'), $followed->username));
Notification::assertSentTo(
[$followed],
NewUnfollow::class
);
Notification::assertCount(1);
});
test('unfollow a user does not create a notification for the followed user when all notifications disabled', function (): void {
Notification::fake();
$group = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$followed->followers()->attach($follower->id);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 1,
'show_account_unfollow' => 1,
]);
// $follower unfollows $followed
$response = $this->actingAs($follower)->delete(route('users.followers.destroy', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-revoked'), $followed->username));
Notification::assertCount(0);
});
test('unfollow a user does not create a notification for the followed user when following notifications are disabled', function (): void {
Notification::fake();
$group = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$followed->followers()->attach($follower->id);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_unfollow' => 0,
]);
// $follower unfollows $followed
$response = $this->actingAs($follower)->delete(route('users.followers.destroy', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-revoked'), $followed->username));
Notification::assertCount(0);
});
test('unfollow a user does not create a notification for the followed user when following notifications are disabled for specific group', function (): void {
Notification::fake();
$group = Group::factory()->create();
$follower = User::factory()->create([
'group_id' => $group->id,
]);
$followed = User::factory()->create([
'group_id' => $group->id,
]);
$followed->followers()->attach($follower->id);
$userNotificationSettings = UserNotification::factory()->create([
'user_id' => $followed->id,
'block_notifications' => 0,
'show_account_unfollow' => 1,
'json_account_groups' => [$group->id],
]);
// $follower unfollows $followed
$response = $this->actingAs($follower)->delete(route('users.followers.destroy', ['user' => $followed]));
$response->assertRedirect(route('users.show', ['user' => $followed->username]))
->assertSessionHas('success', \sprintf(trans('user.follow-revoked'), $followed->username));
Notification::assertCount(0);
});
@@ -0,0 +1,361 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Models\Bot;
use App\Models\Category;
use App\Models\Chatroom;
use App\Models\Group;
use App\Models\Resolution;
use App\Models\Torrent;
use App\Models\Type;
use App\Models\User;
use App\Models\UserNotification;
use App\Notifications\NewUpload;
use Database\Seeders\UsersTableSeeder;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
test('upload a torrent creates a notification for followers', function (): void {
$this->markTestIncomplete('Works locally, but fails in pipeline with:
file_put_contents(/home/runner/work/UNIT3D-Community-Edition/UNIT3D-Community-Edition/files/torrents/676034f8afd077.09743623.torrent): Failed to open stream: No such file or directory');
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create([
'is_uploader' => true,
'can_upload' => true,
'is_trusted' => true,
]);
$follower = User::factory()->create();
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_upload' => true,
]);
$uploader->followers()->attach($follower->id);
$this->assertDatabaseHas('follows', [
'user_id' => $follower->id,
'target_id' => $uploader->id,
]);
$followerNotificationSettings = UserNotification::factory()->create([
'user_id' => $follower->id,
'block_notifications' => 0,
'show_following_upload' => 1,
]);
$resolution = Resolution::factory()->create([]);
$category = Category::factory()->create([
// Prevent upload errors depending on the boolean used in the factory() for meta requirements
'movie_meta' => true,
'tv_meta' => false,
'game_meta' => false,
]);
$type = Type::factory()->create([]);
$torrent = Torrent::factory()->make();
$name = 'Pony Music';
$filePath = base_path('tests/Resources/Pony Music - Mind Fragments (2014).torrent');
$file = new UploadedFile($filePath, 'Pony Music.torrent', 'text/plain', null, true);
$response = $this->actingAs($uploader)->post(route('torrents.store'), [
'torrent' => $file,
'name' => $name,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'tmdb' => 111,
'imdb' => 111,
'mal' => 0,
'tvdb' => 0,
'igdb' => 0,
'description' => 'One song that represents the elements of being lost, abandoned, sadness and innocence.',
'mediainfo' => 'Video: Length: 00:00:10',
'anon' => $torrent->anon,
'stream' => $torrent->stream,
'sd' => $torrent->sd,
'personal_release' => false,
]);
$response = $this->followRedirects($response);
$response->assertOk();
$response->assertViewIs('torrent.download_check');
Notification::assertSentTo(
[$follower],
NewUpload::class
);
Notification::assertCount(1);
});
test('upload a torrent does not create a notification for followers when all notifications disabled', function (): void {
$this->markTestIncomplete('Works locally, but fails in pipeline with:
file_put_contents(/home/runner/work/UNIT3D-Community-Edition/UNIT3D-Community-Edition/files/torrents/676034f8afd077.09743623.torrent): Failed to open stream: No such file or directory');
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create([
'is_uploader' => true,
'can_upload' => true,
'is_trusted' => true,
]);
$follower = User::factory()->create();
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_upload' => true,
]);
$uploader->followers()->attach($follower->id);
$this->assertDatabaseHas('follows', [
'user_id' => $follower->id,
'target_id' => $uploader->id,
]);
$followerNotificationSettings = UserNotification::factory()->create([
'user_id' => $follower->id,
'block_notifications' => 1,
'show_following_upload' => 1,
]);
$resolution = Resolution::factory()->create([]);
$category = Category::factory()->create([
// Prevent upload errors depending on the boolean used in the factory() for meta requirements
'movie_meta' => true,
'tv_meta' => false,
'game_meta' => false,
]);
$type = Type::factory()->create([]);
$torrent = Torrent::factory()->make();
$name = 'Pony Music';
$filePath = base_path('tests/Resources/Pony Music - Mind Fragments (2014).torrent');
$file = new UploadedFile($filePath, 'Pony Music.torrent', 'text/plain', null, true);
$response = $this->actingAs($uploader)->post(route('torrents.store'), [
'torrent' => $file,
'name' => $name,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'tmdb' => 111,
'imdb' => 111,
'mal' => 0,
'tvdb' => 0,
'igdb' => 0,
'description' => 'One song that represents the elements of being lost, abandoned, sadness and innocence.',
'mediainfo' => 'Video: Length: 00:00:10',
'anon' => $torrent->anon,
'stream' => $torrent->stream,
'sd' => $torrent->sd,
'personal_release' => false,
]);
$response = $this->followRedirects($response);
$response->assertOk();
$response->assertViewIs('torrent.download_check');
Notification::assertCount(0);
});
test('upload a torrent does not create a notification for followers when following upload notifications are disabled', function (): void {
$this->markTestIncomplete('Works locally, but fails in pipeline with:
file_put_contents(/home/runner/work/UNIT3D-Community-Edition/UNIT3D-Community-Edition/files/torrents/676034f8afd077.09743623.torrent): Failed to open stream: No such file or directory');
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create([
'is_uploader' => true,
'can_upload' => true,
'is_trusted' => true,
]);
$follower = User::factory()->create();
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_upload' => true,
]);
$uploader->followers()->attach($follower->id);
$this->assertDatabaseHas('follows', [
'user_id' => $follower->id,
'target_id' => $uploader->id,
]);
$followerNotificationSettings = UserNotification::factory()->create([
'user_id' => $follower->id,
'block_notifications' => 0,
'show_following_upload' => 0,
]);
$resolution = Resolution::factory()->create([]);
$category = Category::factory()->create([
// Prevent upload errors depending on the boolean used in the factory() for meta requirements
'movie_meta' => true,
'tv_meta' => false,
'game_meta' => false,
]);
$type = Type::factory()->create([]);
$torrent = Torrent::factory()->make();
$name = 'Pony Music';
$filePath = base_path('tests/Resources/Pony Music - Mind Fragments (2014).torrent');
$file = new UploadedFile($filePath, 'Pony Music.torrent', 'text/plain', null, true);
$response = $this->actingAs($uploader)->post(route('torrents.store'), [
'torrent' => $file,
'name' => $name,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'tmdb' => 111,
'imdb' => 111,
'mal' => 0,
'tvdb' => 0,
'igdb' => 0,
'description' => 'One song that represents the elements of being lost, abandoned, sadness and innocence.',
'mediainfo' => 'Video: Length: 00:00:10',
'anon' => $torrent->anon,
'stream' => $torrent->stream,
'sd' => $torrent->sd,
'personal_release' => false,
]);
$response = $this->followRedirects($response);
$response->assertOk();
$response->assertViewIs('torrent.download_check');
Notification::assertCount(0);
});
test('upload a torrent does not create a notification for followers when following upload notifications are disabled for specific group', function (): void {
$this->markTestIncomplete('Works locally, but fails in pipeline with:
file_put_contents(/home/runner/work/UNIT3D-Community-Edition/UNIT3D-Community-Edition/files/torrents/676034f8afd077.09743623.torrent): Failed to open stream: No such file or directory');
// Required for ChatRepository()
$this->seed(UsersTableSeeder::class);
$bot = Bot::factory()->create([
'command' => 'Systembot',
]);
$chat = Chatroom::factory()->create([
'name' => config('chat.system_chatroom'),
]);
Notification::fake();
$group = Group::factory()->create([
'is_uploader' => true,
'can_upload' => true,
'is_trusted' => true,
]);
$follower = User::factory()->create();
$uploader = User::factory()->create([
'group_id' => $group->id,
'can_upload' => true,
]);
$uploader->followers()->attach($follower->id);
$this->assertDatabaseHas('follows', [
'user_id' => $follower->id,
'target_id' => $uploader->id,
]);
$followerNotificationSettings = UserNotification::factory()->create([
'user_id' => $follower->id,
'block_notifications' => 0,
'show_following_upload' => 1,
'json_following_groups' => [$group->id],
]);
$resolution = Resolution::factory()->create([]);
$category = Category::factory()->create([
// Prevent upload errors depending on the boolean used in the factory() for meta requirements
'movie_meta' => true,
'tv_meta' => false,
'game_meta' => false,
]);
$type = Type::factory()->create([]);
$torrent = Torrent::factory()->make();
$name = 'Pony Music';
$filePath = base_path('tests/Resources/Pony Music - Mind Fragments (2014).torrent');
$file = new UploadedFile($filePath, 'Pony Music.torrent', 'text/plain', null, true);
$response = $this->actingAs($uploader)->post(route('torrents.store'), [
'torrent' => $file,
'name' => $name,
'category_id' => $category->id,
'type_id' => $type->id,
'resolution_id' => $resolution->id,
'tmdb' => 111,
'imdb' => 111,
'mal' => 0,
'tvdb' => 0,
'igdb' => 0,
'description' => 'One song that represents the elements of being lost, abandoned, sadness and innocence.',
'mediainfo' => 'Video: Length: 00:00:10',
'anon' => $torrent->anon,
'stream' => $torrent->stream,
'sd' => $torrent->sd,
'personal_release' => false,
]);
$response = $this->followRedirects($response);
$response->assertOk();
$response->assertViewIs('torrent.download_check');
Notification::assertCount(0);
});