-
-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mentions): add integration test for reply approval notification (#…
…3748) Co-authored-by: Sami Mazouz <[email protected]>
- Loading branch information
1 parent
808a060
commit f729a4d
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
extensions/mentions/tests/integration/api/NotificationsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Mentions\tests\integration\api\NotificationsTest; | ||
|
||
use Carbon\Carbon; | ||
use Flarum\Discussion\Discussion; | ||
use Flarum\Group\Group; | ||
use Flarum\Post\Post; | ||
use Flarum\Testing\integration\RetrievesAuthorizedUsers; | ||
use Flarum\Testing\integration\TestCase; | ||
use Flarum\User\User; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class NotificationsTest extends TestCase | ||
{ | ||
use RetrievesAuthorizedUsers; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->extension('flarum-mentions'); | ||
|
||
$this->prepareDatabase([ | ||
User::class => [ | ||
$this->normalUser(), | ||
['id' => 3, 'username' => 'acme', 'email' => '[email protected]', 'is_email_confirmed' => 1], | ||
], | ||
Discussion::class => [ | ||
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'last_post_number' => 2, 'last_post_id' => 2], | ||
], | ||
Post::class => [ | ||
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>', 'number' => 1], | ||
['id' => 2, 'discussion_id' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 3, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>', 'number' => 2], | ||
], | ||
'group_user' => [ | ||
['group_id' => Group::MEMBER_ID, 'user_id' => 2], | ||
], | ||
]); | ||
} | ||
|
||
#[Test] | ||
public function approving_reply_sends_mention_notification() | ||
{ | ||
$this->extensions = ['flarum-flags', 'flarum-approval', 'flarum-mentions']; | ||
|
||
$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(3); | ||
|
||
$this->assertEquals(0, $mainUser->getUnreadNotificationCount()); | ||
|
||
$response = $this->send( | ||
$this->request('POST', '/api/posts', [ | ||
'authenticatedAs' => 2, | ||
'json' => [ | ||
'data' => [ | ||
'attributes' => [ | ||
'content' => '@"mainUser"#p2', | ||
], | ||
'relationships' => [ | ||
'discussion' => ['data' => ['id' => 1]], | ||
], | ||
] | ||
] | ||
]) | ||
); | ||
|
||
$this->assertEquals(0, $mainUser->getUnreadNotificationCount()); | ||
|
||
$json = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->send( | ||
$this->request('PATCH', '/api/posts/'.$json['data']['id'], [ | ||
'authenticatedAs' => 1, | ||
'json' => [ | ||
'data' => [ | ||
'attributes' => [ | ||
'isApproved' => 1, | ||
] | ||
] | ||
] | ||
]) | ||
); | ||
|
||
$this->assertEquals(1, $mainUser->getUnreadNotificationCount()); | ||
} | ||
} |