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