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