]>
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 | cleanupTests, |
2b02c520 C |
10 | MockSmtpServer, |
11 | prepareNotificationsTest, | |
254d3579 | 12 | PeerTubeServer, |
2b02c520 C |
13 | waitJobs |
14 | } from '@shared/extra-utils' | |
12edc149 | 15 | import { UserNotification } from '@shared/models' |
8eb07b01 C |
16 | |
17 | const expect = chai.expect | |
18 | ||
19 | describe('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 | |
89d241a7 | 55 | const { uuid } = 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) |
8eb07b01 C |
61 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') |
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 | |
89d241a7 | 67 | const { uuid } = 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) |
8eb07b01 C |
73 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') |
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 | |
89d241a7 | 81 | const { uuid } = 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) |
8eb07b01 C |
87 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') |
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 | |
89d241a7 | 95 | const { uuid } = 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) |
8eb07b01 C |
101 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') |
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 | |
89d241a7 | 107 | const { uuid } = 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 |
8eb07b01 C |
119 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') |
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 | |
89d241a7 | 125 | const { uuid } = 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) |
8eb07b01 C |
132 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') |
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 | |
89d241a7 | 138 | const { uuid } = 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 | ||
158 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | |
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 | |
177 | ||
178 | before(async () => { | |
179 | baseParams = { | |
180 | server: servers[0], | |
181 | emails, | |
182 | socketNotifications: userNotifications, | |
12edc149 | 183 | token: userToken |
8eb07b01 C |
184 | } |
185 | ||
89d241a7 C |
186 | await servers[0].users.updateMe({ displayName: 'super root name' }) |
187 | await servers[1].users.updateMe({ displayName: 'super root 2 name' }) | |
8eb07b01 C |
188 | }) |
189 | ||
190 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | |
191 | this.timeout(10000) | |
192 | ||
89d241a7 | 193 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) |
8eb07b01 | 194 | |
89d241a7 | 195 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) |
8eb07b01 | 196 | |
faa9d434 | 197 | await waitJobs(servers) |
8eb07b01 C |
198 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') |
199 | }) | |
200 | ||
201 | it('Should not send a new mention comment notification if I mention myself', async function () { | |
202 | this.timeout(10000) | |
203 | ||
89d241a7 | 204 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
8eb07b01 | 205 | |
89d241a7 | 206 | const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) |
8eb07b01 | 207 | |
faa9d434 | 208 | await waitJobs(servers) |
8eb07b01 C |
209 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') |
210 | }) | |
211 | ||
212 | it('Should not send a new mention notification if the account is muted', async function () { | |
213 | this.timeout(10000) | |
214 | ||
89d241a7 | 215 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) |
8eb07b01 | 216 | |
89d241a7 | 217 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
8eb07b01 | 218 | |
89d241a7 | 219 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) |
8eb07b01 | 220 | |
faa9d434 | 221 | await waitJobs(servers) |
8eb07b01 C |
222 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') |
223 | ||
89d241a7 | 224 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) |
8eb07b01 C |
225 | }) |
226 | ||
227 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | |
228 | this.timeout(20000) | |
229 | ||
89d241a7 | 230 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
8eb07b01 C |
231 | |
232 | await waitJobs(servers) | |
89d241a7 | 233 | const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) |
8eb07b01 C |
234 | |
235 | await waitJobs(servers) | |
236 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') | |
237 | }) | |
238 | ||
239 | it('Should send a new mention notification after local comments', async function () { | |
240 | this.timeout(10000) | |
241 | ||
89d241a7 | 242 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
8eb07b01 | 243 | |
89d241a7 | 244 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) |
8eb07b01 | 245 | |
faa9d434 | 246 | await waitJobs(servers) |
8eb07b01 C |
247 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') |
248 | ||
89d241a7 | 249 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) |
8eb07b01 | 250 | |
faa9d434 | 251 | await waitJobs(servers) |
8eb07b01 C |
252 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') |
253 | }) | |
254 | ||
255 | it('Should send a new mention notification after remote comments', async function () { | |
256 | this.timeout(20000) | |
257 | ||
89d241a7 | 258 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
8eb07b01 C |
259 | |
260 | await waitJobs(servers) | |
261 | ||
262 | const text1 = `hello @user_1@localhost:${servers[0].port} 1` | |
89d241a7 | 263 | const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 }) |
8eb07b01 C |
264 | |
265 | await waitJobs(servers) | |
266 | ||
89d241a7 | 267 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) |
12edc149 C |
268 | expect(data).to.have.lengthOf(1) |
269 | ||
270 | const server1ThreadId = data[0].id | |
8eb07b01 C |
271 | await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') |
272 | ||
273 | const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` | |
89d241a7 | 274 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) |
8eb07b01 C |
275 | |
276 | await waitJobs(servers) | |
277 | ||
89d241a7 | 278 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId: server1ThreadId }) |
8eb07b01 C |
279 | |
280 | expect(tree.children).to.have.lengthOf(1) | |
281 | const commentId = tree.children[0].comment.id | |
282 | ||
283 | await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') | |
284 | }) | |
45c70083 C |
285 | |
286 | it('Should convert markdown in comment to html', async function () { | |
287 | this.timeout(10000) | |
288 | ||
89d241a7 | 289 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) |
45c70083 | 290 | |
89d241a7 | 291 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' }) |
45c70083 | 292 | |
89d241a7 | 293 | await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText }) |
45c70083 C |
294 | |
295 | await waitJobs(servers) | |
296 | ||
297 | const latestEmail = emails[emails.length - 1] | |
298 | expect(latestEmail['html']).to.contain(expectedHtml) | |
299 | }) | |
8eb07b01 C |
300 | }) |
301 | ||
302 | after(async function () { | |
303 | MockSmtpServer.Instance.kill() | |
304 | ||
305 | await cleanupTests(servers) | |
306 | }) | |
307 | }) |