Skip to content

Commit 8cda74d

Browse files
committed
add backend test
1 parent 59f1087 commit 8cda74d

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

extensions/mentions/tests/integration/api/NotificationsTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ protected function setUp(): void
3535
],
3636
Discussion::class => [
3737
['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],
38+
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 2, 'first_post_id' => 3, 'comment_count' => 1, 'last_post_number' => 1, 'last_post_id' => 3],
3839
],
3940
Post::class => [
4041
['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],
4142
['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],
43+
['id' => 3, 'discussion_id' => 2, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>', 'number' => 1],
4244
],
4345
'group_user' => [
4446
['group_id' => Group::MEMBER_ID, 'user_id' => 2],
@@ -99,4 +101,38 @@ public function approving_reply_sends_mention_notification()
99101

100102
$this->assertEquals(1, $mainUser->getUnreadNotificationCount());
101103
}
104+
105+
#[Test]
106+
public function post_mention_notification_content_includes_the_reply_discussion_id()
107+
{
108+
$response = $this->send(
109+
$this->request('POST', '/api/posts', [
110+
'authenticatedAs' => 2,
111+
'json' => [
112+
'data' => [
113+
'attributes' => [
114+
'content' => '@"mainUser"#p2',
115+
],
116+
'relationships' => [
117+
'discussion' => ['data' => ['id' => 2]],
118+
],
119+
]
120+
]
121+
])
122+
);
123+
124+
$this->assertEquals(201, $response->getStatusCode());
125+
126+
/** @var User $mainUser */
127+
$mainUser = User::query()->find(3);
128+
$notification = $mainUser->notifications()
129+
->where('type', 'postMentioned')
130+
->first();
131+
132+
$this->assertNotNull($notification);
133+
$this->assertEquals([
134+
'replyNumber' => 2,
135+
'discussionId' => 2,
136+
], $notification->data);
137+
}
102138
}

0 commit comments

Comments
 (0)