]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/notifications/comments-notifications.ts
Adapt CLI to new commands
[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
C
10 MockSmtpServer,
11 prepareNotificationsTest,
2b02c520
C
12 ServerInfo,
13 updateMyUser,
14 uploadVideo,
15 waitJobs
16} from '@shared/extra-utils'
12edc149 17import { UserNotification } from '@shared/models'
8eb07b01
C
18
19const expect = chai.expect
20
21describe('Test comments notifications', function () {
22 let servers: ServerInfo[] = []
12edc149 23 let userToken: string
8eb07b01
C
24 let userNotifications: UserNotification[] = []
25 let emails: object[] = []
26
45c70083
C
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
8eb07b01
C
32 before(async function () {
33 this.timeout(120000)
34
35 const res = await prepareNotificationsTest(2)
36 emails = res.emails
12edc149 37 userToken = res.userAccessToken
8eb07b01
C
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,
12edc149 50 token: userToken
8eb07b01
C
51 }
52 })
53
54 it('Should not send a new comment notification after a comment on another video', async function () {
a0464535 55 this.timeout(20000)
8eb07b01
C
56
57 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
58 const uuid = resVideo.body.video.uuid
59
12edc149
C
60 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
61 const commentId = created.id
8eb07b01 62
faa9d434 63 await waitJobs(servers)
8eb07b01
C
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 () {
a0464535 68 this.timeout(20000)
8eb07b01 69
12edc149 70 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
71 const uuid = resVideo.body.video.uuid
72
12edc149
C
73 const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
74 const commentId = created.id
8eb07b01 75
faa9d434 76 await waitJobs(servers)
8eb07b01
C
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 () {
a0464535 81 this.timeout(20000)
8eb07b01 82
12edc149 83 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
8eb07b01 84
12edc149 85 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
86 const uuid = resVideo.body.video.uuid
87
12edc149
C
88 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
89 const commentId = created.id
8eb07b01 90
faa9d434 91 await waitJobs(servers)
8eb07b01
C
92 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
93
12edc149 94 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
8eb07b01
C
95 })
96
97 it('Should send a new comment notification after a local comment on my video', async function () {
a0464535 98 this.timeout(20000)
8eb07b01 99
12edc149 100 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
101 const uuid = resVideo.body.video.uuid
102
12edc149
C
103 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
104 const commentId = created.id
8eb07b01 105
faa9d434 106 await waitJobs(servers)
8eb07b01
C
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 () {
a0464535 111 this.timeout(20000)
8eb07b01 112
12edc149 113 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
114 const uuid = resVideo.body.video.uuid
115
116 await waitJobs(servers)
117
12edc149 118 await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
8eb07b01
C
119
120 await waitJobs(servers)
121
12edc149
C
122 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
123 expect(data).to.have.lengthOf(1)
8eb07b01 124
12edc149 125 const commentId = data[0].id
8eb07b01
C
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 () {
a0464535 130 this.timeout(20000)
8eb07b01 131
12edc149 132 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
133 const uuid = resVideo.body.video.uuid
134
12edc149 135 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
8eb07b01 136
12edc149 137 const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
8eb07b01 138
faa9d434 139 await waitJobs(servers)
8eb07b01
C
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 () {
a0464535 144 this.timeout(20000)
8eb07b01 145
12edc149 146 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
147 const uuid = resVideo.body.video.uuid
148 await waitJobs(servers)
149
150 {
12edc149
C
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' })
8eb07b01
C
154 }
155
156 await waitJobs(servers)
157
12edc149
C
158 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
159 expect(data).to.have.lengthOf(1)
8eb07b01 160
12edc149
C
161 const threadId = data[0].id
162 const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId })
8eb07b01
C
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 })
9afb5c10
C
169
170 it('Should convert markdown in comment to html', async function () {
a0464535 171 this.timeout(20000)
9afb5c10 172
12edc149 173 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' })
9afb5c10
C
174 const uuid = resVideo.body.video.uuid
175
12edc149 176 await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
9afb5c10
C
177
178 await waitJobs(servers)
9afb5c10
C
179
180 const latestEmail = emails[emails.length - 1]
45c70083 181 expect(latestEmail['html']).to.contain(expectedHtml)
9afb5c10 182 })
8eb07b01
C
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,
12edc149 193 token: userToken
8eb07b01
C
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
12edc149 212 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
8eb07b01
C
213 const uuid = resVideo.body.video.uuid
214
12edc149 215 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
8eb07b01 216
faa9d434 217 await waitJobs(servers)
8eb07b01
C
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
12edc149 227 const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
8eb07b01 228
faa9d434 229 await waitJobs(servers)
8eb07b01
C
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
12edc149 236 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
8eb07b01
C
237
238 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
239 const uuid = resVideo.body.video.uuid
240
12edc149 241 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
8eb07b01 242
faa9d434 243 await waitJobs(servers)
8eb07b01
C
244 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
245
12edc149 246 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
8eb07b01
C
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)
12edc149 256 const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
8eb07b01
C
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
12edc149 268 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
8eb07b01 269
faa9d434 270 await waitJobs(servers)
8eb07b01
C
271 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
272
12edc149 273 const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
8eb07b01 274
faa9d434 275 await waitJobs(servers)
8eb07b01
C
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`
12edc149 288 const { id: server2ThreadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: text1 })
8eb07b01
C
289
290 await waitJobs(servers)
291
12edc149
C
292 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
293 expect(data).to.have.lengthOf(1)
294
295 const server1ThreadId = data[0].id
8eb07b01
C
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}`
12edc149 299 await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
8eb07b01
C
300
301 await waitJobs(servers)
302
12edc149 303 const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId })
8eb07b01
C
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 })
45c70083
C
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
12edc149 317 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
45c70083 318
12edc149 319 await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
45c70083
C
320
321 await waitJobs(servers)
322
323 const latestEmail = emails[emails.length - 1]
324 expect(latestEmail['html']).to.contain(expectedHtml)
325 })
8eb07b01
C
326 })
327
328 after(async function () {
329 MockSmtpServer.Instance.kill()
330
331 await cleanupTests(servers)
332 })
333})