]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/notifications/comments-notifications.ts
Add ability to search by host in server
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / comments-notifications.ts
CommitLineData
8eb07b01
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
8eb07b01
C
5import {
6 checkCommentMention,
7 CheckerBaseParams,
8 checkNewCommentOnMyVideo,
2b02c520 9 cleanupTests,
2b02c520 10 MockSmtpServer,
254d3579 11 PeerTubeServer,
4c7e60bc 12 prepareNotificationsTest,
2b02c520
C
13 waitJobs
14} from '@shared/extra-utils'
12edc149 15import { UserNotification } from '@shared/models'
8eb07b01
C
16
17const expect = chai.expect
18
19describe('Test comments notifications', function () {
254d3579 20 let servers: PeerTubeServer[] = []
12edc149 21 let userToken: string
8eb07b01
C
22 let userNotifications: UserNotification[] = []
23 let emails: object[] = []
24
45c70083
C
25 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
26 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
27 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
28 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
29
8eb07b01
C
30 before(async function () {
31 this.timeout(120000)
32
33 const res = await prepareNotificationsTest(2)
34 emails = res.emails
12edc149 35 userToken = res.userAccessToken
8eb07b01
C
36 servers = res.servers
37 userNotifications = res.userNotifications
38 })
39
40 describe('Comment on my video notifications', function () {
41 let baseParams: CheckerBaseParams
42
43 before(() => {
44 baseParams = {
45 server: servers[0],
46 emails,
47 socketNotifications: userNotifications,
12edc149 48 token: userToken
8eb07b01
C
49 }
50 })
51
52 it('Should not send a new comment notification after a comment on another video', async function () {
a0464535 53 this.timeout(20000)
8eb07b01 54
29837f88 55 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
8eb07b01 56
89d241a7 57 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
12edc149 58 const commentId = created.id
8eb07b01 59
faa9d434 60 await waitJobs(servers)
29837f88 61 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
8eb07b01
C
62 })
63
64 it('Should not send a new comment notification if I comment my own video', async function () {
a0464535 65 this.timeout(20000)
8eb07b01 66
29837f88 67 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01 68
89d241a7 69 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
12edc149 70 const commentId = created.id
8eb07b01 71
faa9d434 72 await waitJobs(servers)
29837f88 73 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
8eb07b01
C
74 })
75
76 it('Should not send a new comment notification if the account is muted', async function () {
a0464535 77 this.timeout(20000)
8eb07b01 78
89d241a7 79 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
8eb07b01 80
29837f88 81 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01 82
89d241a7 83 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
12edc149 84 const commentId = created.id
8eb07b01 85
faa9d434 86 await waitJobs(servers)
29837f88 87 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
8eb07b01 88
89d241a7 89 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
8eb07b01
C
90 })
91
92 it('Should send a new comment notification after a local comment on my video', async function () {
a0464535 93 this.timeout(20000)
8eb07b01 94
29837f88 95 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01 96
89d241a7 97 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
12edc149 98 const commentId = created.id
8eb07b01 99
faa9d434 100 await waitJobs(servers)
29837f88 101 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
8eb07b01
C
102 })
103
104 it('Should send a new comment notification after a remote comment on my video', async function () {
a0464535 105 this.timeout(20000)
8eb07b01 106
29837f88 107 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01
C
108
109 await waitJobs(servers)
110
89d241a7 111 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
8eb07b01
C
112
113 await waitJobs(servers)
114
89d241a7 115 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
12edc149 116 expect(data).to.have.lengthOf(1)
8eb07b01 117
12edc149 118 const commentId = data[0].id
29837f88 119 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
8eb07b01
C
120 })
121
122 it('Should send a new comment notification after a local reply on my video', async function () {
a0464535 123 this.timeout(20000)
8eb07b01 124
29837f88 125 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01 126
89d241a7 127 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
8eb07b01 128
89d241a7 129 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
8eb07b01 130
faa9d434 131 await waitJobs(servers)
29837f88 132 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
8eb07b01
C
133 })
134
135 it('Should send a new comment notification after a remote reply on my video', async function () {
a0464535 136 this.timeout(20000)
8eb07b01 137
29837f88 138 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01
C
139 await waitJobs(servers)
140
141 {
89d241a7 142 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
12edc149 143 const threadId = created.id
89d241a7 144 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
8eb07b01
C
145 }
146
147 await waitJobs(servers)
148
89d241a7 149 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
12edc149 150 expect(data).to.have.lengthOf(1)
8eb07b01 151
12edc149 152 const threadId = data[0].id
89d241a7 153 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
8eb07b01
C
154
155 expect(tree.children).to.have.lengthOf(1)
156 const commentId = tree.children[0].comment.id
157
29837f88 158 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
8eb07b01 159 })
9afb5c10
C
160
161 it('Should convert markdown in comment to html', async function () {
a0464535 162 this.timeout(20000)
9afb5c10 163
89d241a7 164 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
9afb5c10 165
89d241a7 166 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
9afb5c10
C
167
168 await waitJobs(servers)
9afb5c10
C
169
170 const latestEmail = emails[emails.length - 1]
45c70083 171 expect(latestEmail['html']).to.contain(expectedHtml)
9afb5c10 172 })
8eb07b01
C
173 })
174
175 describe('Mention notifications', function () {
176 let baseParams: CheckerBaseParams
29837f88 177 const byAccountDisplayName = 'super root name'
8eb07b01
C
178
179 before(async () => {
180 baseParams = {
181 server: servers[0],
182 emails,
183 socketNotifications: userNotifications,
12edc149 184 token: userToken
8eb07b01
C
185 }
186
89d241a7
C
187 await servers[0].users.updateMe({ displayName: 'super root name' })
188 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
8eb07b01
C
189 })
190
191 it('Should not send a new mention comment notification if I mention the video owner', async function () {
192 this.timeout(10000)
193
29837f88 194 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
8eb07b01 195
89d241a7 196 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
8eb07b01 197
faa9d434 198 await waitJobs(servers)
29837f88 199 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
8eb07b01
C
200 })
201
202 it('Should not send a new mention comment notification if I mention myself', async function () {
203 this.timeout(10000)
204
29837f88 205 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
8eb07b01 206
89d241a7 207 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
8eb07b01 208
faa9d434 209 await waitJobs(servers)
29837f88 210 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
8eb07b01
C
211 })
212
213 it('Should not send a new mention notification if the account is muted', async function () {
214 this.timeout(10000)
215
89d241a7 216 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
8eb07b01 217
29837f88 218 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
8eb07b01 219
89d241a7 220 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
8eb07b01 221
faa9d434 222 await waitJobs(servers)
29837f88 223 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
8eb07b01 224
89d241a7 225 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
8eb07b01
C
226 })
227
228 it('Should not send a new mention notification if the remote account mention a local account', async function () {
229 this.timeout(20000)
230
29837f88 231 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
8eb07b01
C
232
233 await waitJobs(servers)
89d241a7 234 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
8eb07b01
C
235
236 await waitJobs(servers)
29837f88
C
237
238 const byAccountDisplayName = 'super root 2 name'
239 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
8eb07b01
C
240 })
241
242 it('Should send a new mention notification after local comments', async function () {
243 this.timeout(10000)
244
29837f88 245 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
8eb07b01 246
89d241a7 247 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
8eb07b01 248
faa9d434 249 await waitJobs(servers)
29837f88 250 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
8eb07b01 251
89d241a7 252 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
8eb07b01 253
faa9d434 254 await waitJobs(servers)
29837f88 255 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
8eb07b01
C
256 })
257
258 it('Should send a new mention notification after remote comments', async function () {
259 this.timeout(20000)
260
29837f88 261 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
8eb07b01
C
262
263 await waitJobs(servers)
264
265 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
89d241a7 266 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
8eb07b01
C
267
268 await waitJobs(servers)
269
89d241a7 270 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
12edc149
C
271 expect(data).to.have.lengthOf(1)
272
29837f88
C
273 const byAccountDisplayName = 'super root 2 name'
274 const threadId = data[0].id
275 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
8eb07b01
C
276
277 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
89d241a7 278 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
8eb07b01
C
279
280 await waitJobs(servers)
281
29837f88 282 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
8eb07b01
C
283
284 expect(tree.children).to.have.lengthOf(1)
285 const commentId = tree.children[0].comment.id
286
29837f88 287 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
8eb07b01 288 })
45c70083
C
289
290 it('Should convert markdown in comment to html', async function () {
291 this.timeout(10000)
292
89d241a7 293 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
45c70083 294
89d241a7 295 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
45c70083 296
89d241a7 297 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
45c70083
C
298
299 await waitJobs(servers)
300
301 const latestEmail = emails[emails.length - 1]
302 expect(latestEmail['html']).to.contain(expectedHtml)
303 })
8eb07b01
C
304 })
305
306 after(async function () {
307 MockSmtpServer.Instance.kill()
308
309 await cleanupTests(servers)
310 })
311})