mirror of
https://github.com/flarum/core.git
synced 2025-08-12 19:34:18 +02:00
feat: send notifications of a new reply when post is approved (#3656)
* test(subscriptions): approved reply sends out notifications to users Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * feat: send notifications when a post is approved The code in approval was extracted into a listener because no matter what listeners are always executed before subscribers even if the extension is set to load before. Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
namespace Flarum\Subscriptions\tests\integration\api\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
@@ -221,4 +222,60 @@ class ReplyNotificationTest extends TestCase
|
||||
[[8, 9, 10]]
|
||||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function approving_reply_sends_reply_notification()
|
||||
{
|
||||
// Flags was only specified because it is required for approval.
|
||||
$this->extensions = ['flarum-flags', 'flarum-approval', 'flarum-subscriptions'];
|
||||
|
||||
$this->app();
|
||||
|
||||
$this->database()
|
||||
->table('group_permission')
|
||||
->where('group_id', Group::MEMBER_ID)
|
||||
->where('permission', 'discussion.replyWithoutApproval')
|
||||
->delete();
|
||||
|
||||
/** @var User $mainUser */
|
||||
$mainUser = User::query()->find(2);
|
||||
|
||||
$this->assertEquals(0, $mainUser->getUnreadNotificationCount());
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/posts', [
|
||||
'authenticatedAs' => 4,
|
||||
'json' => [
|
||||
'data' => [
|
||||
'attributes' => [
|
||||
'content' => 'reply with predetermined content for automated testing - too-obscure',
|
||||
],
|
||||
'relationships' => [
|
||||
'discussion' => ['data' => ['id' => 1]],
|
||||
],
|
||||
],
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $mainUser->getUnreadNotificationCount());
|
||||
|
||||
$json = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
// Approve the previous post
|
||||
$this->send(
|
||||
$this->request('PATCH', '/api/posts/'.$json['data']['id'], [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'data' => [
|
||||
'attributes' => [
|
||||
'isApproved' => 1,
|
||||
],
|
||||
],
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $mainUser->getUnreadNotificationCount());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user