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