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