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