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