aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-11 11:52:34 +0100
committerChocobozzz <me@florianbigard.com>2019-02-11 11:52:34 +0100
commit88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch)
treeb242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /server/tests/api/users
parent53a94c7cfa8368da4cd248d65df8346905938f0c (diff)
parent9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff)
downloadPeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz
PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst
PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip
Merge branch 'develop' into pr/1217
Diffstat (limited to 'server/tests/api/users')
-rw-r--r--server/tests/api/users/blocklist.ts511
-rw-r--r--server/tests/api/users/index.ts4
-rw-r--r--server/tests/api/users/user-notifications.ts1053
-rw-r--r--server/tests/api/users/user-subscriptions.ts19
-rw-r--r--server/tests/api/users/users-multiple-servers.ts10
-rw-r--r--server/tests/api/users/users-verification.ts13
-rw-r--r--server/tests/api/users/users.ts62
7 files changed, 1648 insertions, 24 deletions
diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts
new file mode 100644
index 000000000..4bca27a94
--- /dev/null
+++ b/server/tests/api/users/blocklist.ts
@@ -0,0 +1,511 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { AccountBlock, ServerBlock, Video } from '../../../../shared/index'
6import {
7 createUser,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 flushTests,
11 killallServers,
12 ServerInfo,
13 uploadVideo,
14 userLogin
15} from '../../../../shared/utils/index'
16import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
17import { getVideosListWithToken, getVideosList } from '../../../../shared/utils/videos/videos'
18import {
19 addVideoCommentReply,
20 addVideoCommentThread,
21 getVideoCommentThreads,
22 getVideoThreadComments
23} from '../../../../shared/utils/videos/video-comments'
24import { waitJobs } from '../../../../shared/utils/server/jobs'
25import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
26import {
27 addAccountToAccountBlocklist,
28 addAccountToServerBlocklist,
29 addServerToAccountBlocklist,
30 addServerToServerBlocklist,
31 getAccountBlocklistByAccount,
32 getAccountBlocklistByServer,
33 getServerBlocklistByAccount,
34 getServerBlocklistByServer,
35 removeAccountFromAccountBlocklist,
36 removeAccountFromServerBlocklist,
37 removeServerFromAccountBlocklist,
38 removeServerFromServerBlocklist
39} from '../../../../shared/utils/users/blocklist'
40
41const expect = chai.expect
42
43async function checkAllVideos (url: string, token: string) {
44 {
45 const res = await getVideosListWithToken(url, token)
46
47 expect(res.body.data).to.have.lengthOf(4)
48 }
49
50 {
51 const res = await getVideosList(url)
52
53 expect(res.body.data).to.have.lengthOf(4)
54 }
55}
56
57async function checkAllComments (url: string, token: string, videoUUID: string) {
58 const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 5, '-createdAt', token)
59
60 const threads: VideoComment[] = resThreads.body.data
61 expect(threads).to.have.lengthOf(2)
62
63 for (const thread of threads) {
64 const res = await getVideoThreadComments(url, videoUUID, thread.id, token)
65
66 const tree: VideoCommentThreadTree = res.body
67 expect(tree.children).to.have.lengthOf(1)
68 }
69}
70
71describe('Test blocklist', function () {
72 let servers: ServerInfo[]
73 let videoUUID1: string
74 let videoUUID2: string
75 let userToken1: string
76 let userModeratorToken: string
77 let userToken2: string
78
79 before(async function () {
80 this.timeout(60000)
81
82 await flushTests()
83
84 servers = await flushAndRunMultipleServers(2)
85 await setAccessTokensToServers(servers)
86
87 {
88 const user = { username: 'user1', password: 'password' }
89 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
90
91 userToken1 = await userLogin(servers[0], user)
92 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
93 }
94
95 {
96 const user = { username: 'moderator', password: 'password' }
97 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
98
99 userModeratorToken = await userLogin(servers[0], user)
100 }
101
102 {
103 const user = { username: 'user2', password: 'password' }
104 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
105
106 userToken2 = await userLogin(servers[1], user)
107 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
108 }
109
110 {
111 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
112 videoUUID1 = res.body.video.uuid
113 }
114
115 {
116 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
117 videoUUID2 = res.body.video.uuid
118 }
119
120 await doubleFollow(servers[0], servers[1])
121
122 {
123 const resComment = await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, 'comment root 1')
124 const resReply = await addVideoCommentReply(servers[ 0 ].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1')
125 await addVideoCommentReply(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1')
126 }
127
128 {
129 const resComment = await addVideoCommentThread(servers[ 0 ].url, userToken1, videoUUID1, 'comment user 1')
130 await addVideoCommentReply(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1')
131 }
132
133 await waitJobs(servers)
134 })
135
136 describe('User blocklist', function () {
137
138 describe('When managing account blocklist', function () {
139 it('Should list all videos', function () {
140 return checkAllVideos(servers[ 0 ].url, servers[ 0 ].accessToken)
141 })
142
143 it('Should list the comments', function () {
144 return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1)
145 })
146
147 it('Should block a remote account', async function () {
148 await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
149 })
150
151 it('Should hide its videos', async function () {
152 const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken)
153
154 const videos: Video[] = res.body.data
155 expect(videos).to.have.lengthOf(3)
156
157 const v = videos.find(v => v.name === 'video user 2')
158 expect(v).to.be.undefined
159 })
160
161 it('Should block a local account', async function () {
162 await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1')
163 })
164
165 it('Should hide its videos', async function () {
166 const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken)
167
168 const videos: Video[] = res.body.data
169 expect(videos).to.have.lengthOf(2)
170
171 const v = videos.find(v => v.name === 'video user 1')
172 expect(v).to.be.undefined
173 })
174
175 it('Should hide its comments', async function () {
176 const resThreads = await getVideoCommentThreads(servers[ 0 ].url, videoUUID1, 0, 5, '-createdAt', servers[ 0 ].accessToken)
177
178 const threads: VideoComment[] = resThreads.body.data
179 expect(threads).to.have.lengthOf(1)
180 expect(threads[ 0 ].totalReplies).to.equal(0)
181
182 const t = threads.find(t => t.text === 'comment user 1')
183 expect(t).to.be.undefined
184
185 for (const thread of threads) {
186 const res = await getVideoThreadComments(servers[ 0 ].url, videoUUID1, thread.id, servers[ 0 ].accessToken)
187
188 const tree: VideoCommentThreadTree = res.body
189 expect(tree.children).to.have.lengthOf(0)
190 }
191 })
192
193 it('Should list all the videos with another user', async function () {
194 return checkAllVideos(servers[ 0 ].url, userToken1)
195 })
196
197 it('Should list all the comments with another user', async function () {
198 return checkAllComments(servers[ 0 ].url, userToken1, videoUUID1)
199 })
200
201 it('Should list blocked accounts', async function () {
202 {
203 const res = await getAccountBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt')
204 const blocks: AccountBlock[] = res.body.data
205
206 expect(res.body.total).to.equal(2)
207
208 const block = blocks[ 0 ]
209 expect(block.byAccount.displayName).to.equal('root')
210 expect(block.byAccount.name).to.equal('root')
211 expect(block.blockedAccount.displayName).to.equal('user2')
212 expect(block.blockedAccount.name).to.equal('user2')
213 expect(block.blockedAccount.host).to.equal('localhost:9002')
214 }
215
216 {
217 const res = await getAccountBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 1, 2, 'createdAt')
218 const blocks: AccountBlock[] = res.body.data
219
220 expect(res.body.total).to.equal(2)
221
222 const block = blocks[ 0 ]
223 expect(block.byAccount.displayName).to.equal('root')
224 expect(block.byAccount.name).to.equal('root')
225 expect(block.blockedAccount.displayName).to.equal('user1')
226 expect(block.blockedAccount.name).to.equal('user1')
227 expect(block.blockedAccount.host).to.equal('localhost:9001')
228 }
229 })
230
231 it('Should unblock the remote account', async function () {
232 await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
233 })
234
235 it('Should display its videos', async function () {
236 const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken)
237
238 const videos: Video[] = res.body.data
239 expect(videos).to.have.lengthOf(3)
240
241 const v = videos.find(v => v.name === 'video user 2')
242 expect(v).not.to.be.undefined
243 })
244
245 it('Should unblock the local account', async function () {
246 await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1')
247 })
248
249 it('Should display its comments', function () {
250 return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1)
251 })
252 })
253
254 describe('When managing server blocklist', function () {
255 it('Should list all videos', function () {
256 return checkAllVideos(servers[ 0 ].url, servers[ 0 ].accessToken)
257 })
258
259 it('Should list the comments', function () {
260 return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1)
261 })
262
263 it('Should block a remote server', async function () {
264 await addServerToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
265 })
266
267 it('Should hide its videos', async function () {
268 const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken)
269
270 const videos: Video[] = res.body.data
271 expect(videos).to.have.lengthOf(2)
272
273 const v1 = videos.find(v => v.name === 'video user 2')
274 const v2 = videos.find(v => v.name === 'video server 2')
275
276 expect(v1).to.be.undefined
277 expect(v2).to.be.undefined
278 })
279
280 it('Should list all the videos with another user', async function () {
281 return checkAllVideos(servers[ 0 ].url, userToken1)
282 })
283
284 it('Should hide its comments')
285
286 it('Should list blocked servers', async function () {
287 const res = await getServerBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt')
288 const blocks: ServerBlock[] = res.body.data
289
290 expect(res.body.total).to.equal(1)
291
292 const block = blocks[ 0 ]
293 expect(block.byAccount.displayName).to.equal('root')
294 expect(block.byAccount.name).to.equal('root')
295 expect(block.blockedServer.host).to.equal('localhost:9002')
296 })
297
298 it('Should unblock the remote server', async function () {
299 await removeServerFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
300 })
301
302 it('Should display its videos', function () {
303 return checkAllVideos(servers[ 0 ].url, servers[ 0 ].accessToken)
304 })
305
306 it('Should display its comments', function () {
307 return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1)
308 })
309 })
310 })
311
312 describe('Server blocklist', function () {
313
314 describe('When managing account blocklist', function () {
315 it('Should list all videos', async function () {
316 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
317 await checkAllVideos(servers[ 0 ].url, token)
318 }
319 })
320
321 it('Should list the comments', async function () {
322 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
323 await checkAllComments(servers[ 0 ].url, token, videoUUID1)
324 }
325 })
326
327 it('Should block a remote account', async function () {
328 await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
329 })
330
331 it('Should hide its videos', async function () {
332 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
333 const res = await getVideosListWithToken(servers[ 0 ].url, token)
334
335 const videos: Video[] = res.body.data
336 expect(videos).to.have.lengthOf(3)
337
338 const v = videos.find(v => v.name === 'video user 2')
339 expect(v).to.be.undefined
340 }
341 })
342
343 it('Should block a local account', async function () {
344 await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1')
345 })
346
347 it('Should hide its videos', async function () {
348 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
349 const res = await getVideosListWithToken(servers[ 0 ].url, token)
350
351 const videos: Video[] = res.body.data
352 expect(videos).to.have.lengthOf(2)
353
354 const v = videos.find(v => v.name === 'video user 1')
355 expect(v).to.be.undefined
356 }
357 })
358
359 it('Should hide its comments', async function () {
360 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
361 const resThreads = await getVideoCommentThreads(servers[ 0 ].url, videoUUID1, 0, 5, '-createdAt', token)
362
363 const threads: VideoComment[] = resThreads.body.data
364 expect(threads).to.have.lengthOf(1)
365 expect(threads[ 0 ].totalReplies).to.equal(0)
366
367 const t = threads.find(t => t.text === 'comment user 1')
368 expect(t).to.be.undefined
369
370 for (const thread of threads) {
371 const res = await getVideoThreadComments(servers[ 0 ].url, videoUUID1, thread.id, token)
372
373 const tree: VideoCommentThreadTree = res.body
374 expect(tree.children).to.have.lengthOf(0)
375 }
376 }
377 })
378
379 it('Should list blocked accounts', async function () {
380 {
381 const res = await getAccountBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt')
382 const blocks: AccountBlock[] = res.body.data
383
384 expect(res.body.total).to.equal(2)
385
386 const block = blocks[ 0 ]
387 expect(block.byAccount.displayName).to.equal('peertube')
388 expect(block.byAccount.name).to.equal('peertube')
389 expect(block.blockedAccount.displayName).to.equal('user2')
390 expect(block.blockedAccount.name).to.equal('user2')
391 expect(block.blockedAccount.host).to.equal('localhost:9002')
392 }
393
394 {
395 const res = await getAccountBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 1, 2, 'createdAt')
396 const blocks: AccountBlock[] = res.body.data
397
398 expect(res.body.total).to.equal(2)
399
400 const block = blocks[ 0 ]
401 expect(block.byAccount.displayName).to.equal('peertube')
402 expect(block.byAccount.name).to.equal('peertube')
403 expect(block.blockedAccount.displayName).to.equal('user1')
404 expect(block.blockedAccount.name).to.equal('user1')
405 expect(block.blockedAccount.host).to.equal('localhost:9001')
406 }
407 })
408
409 it('Should unblock the remote account', async function () {
410 await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
411 })
412
413 it('Should display its videos', async function () {
414 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
415 const res = await getVideosListWithToken(servers[ 0 ].url, token)
416
417 const videos: Video[] = res.body.data
418 expect(videos).to.have.lengthOf(3)
419
420 const v = videos.find(v => v.name === 'video user 2')
421 expect(v).not.to.be.undefined
422 }
423 })
424
425 it('Should unblock the local account', async function () {
426 await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1')
427 })
428
429 it('Should display its comments', async function () {
430 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
431 await checkAllComments(servers[ 0 ].url, token, videoUUID1)
432 }
433 })
434 })
435
436 describe('When managing server blocklist', function () {
437 it('Should list all videos', async function () {
438 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
439 await checkAllVideos(servers[ 0 ].url, token)
440 }
441 })
442
443 it('Should list the comments', async function () {
444 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
445 await checkAllComments(servers[ 0 ].url, token, videoUUID1)
446 }
447 })
448
449 it('Should block a remote server', async function () {
450 await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
451 })
452
453 it('Should hide its videos', async function () {
454 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
455 const res1 = await getVideosList(servers[ 0 ].url)
456 const res2 = await getVideosListWithToken(servers[ 0 ].url, token)
457
458 for (const res of [ res1, res2 ]) {
459 const videos: Video[] = res.body.data
460 expect(videos).to.have.lengthOf(2)
461
462 const v1 = videos.find(v => v.name === 'video user 2')
463 const v2 = videos.find(v => v.name === 'video server 2')
464
465 expect(v1).to.be.undefined
466 expect(v2).to.be.undefined
467 }
468 }
469 })
470
471 it('Should hide its comments')
472
473 it('Should list blocked servers', async function () {
474 const res = await getServerBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt')
475 const blocks: ServerBlock[] = res.body.data
476
477 expect(res.body.total).to.equal(1)
478
479 const block = blocks[ 0 ]
480 expect(block.byAccount.displayName).to.equal('peertube')
481 expect(block.byAccount.name).to.equal('peertube')
482 expect(block.blockedServer.host).to.equal('localhost:9002')
483 })
484
485 it('Should unblock the remote server', async function () {
486 await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
487 })
488
489 it('Should list all videos', async function () {
490 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
491 await checkAllVideos(servers[ 0 ].url, token)
492 }
493 })
494
495 it('Should list the comments', async function () {
496 for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
497 await checkAllComments(servers[ 0 ].url, token, videoUUID1)
498 }
499 })
500 })
501 })
502
503 after(async function () {
504 killallServers(servers)
505
506 // Keep the logs if the test failed
507 if (this[ 'ok' ]) {
508 await flushTests()
509 }
510 })
511})
diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts
index 21d75da3e..52ba6984e 100644
--- a/server/tests/api/users/index.ts
+++ b/server/tests/api/users/index.ts
@@ -1,4 +1,6 @@
1import './users-verification'
2import './user-notifications'
3import './blocklist'
1import './user-subscriptions' 4import './user-subscriptions'
2import './users' 5import './users'
3import './users-verification'
4import './users-multiple-servers' 6import './users-multiple-servers'
diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts
new file mode 100644
index 000000000..69e51677e
--- /dev/null
+++ b/server/tests/api/users/user-notifications.ts
@@ -0,0 +1,1053 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 addVideoToBlacklist,
7 createUser,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 flushTests,
11 getMyUserInformation,
12 immutableAssign,
13 registerUser,
14 removeVideoFromBlacklist,
15 reportVideoAbuse,
16 updateMyUser,
17 updateVideo,
18 updateVideoChannel,
19 userLogin,
20 wait
21} from '../../../../shared/utils'
22import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
23import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
24import { waitJobs } from '../../../../shared/utils/server/jobs'
25import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io'
26import {
27 checkCommentMention,
28 CheckerBaseParams,
29 checkMyVideoImportIsFinished,
30 checkNewActorFollow,
31 checkNewBlacklistOnMyVideo,
32 checkNewCommentOnMyVideo,
33 checkNewVideoAbuseForModerators,
34 checkNewVideoFromSubscription,
35 checkUserRegistered,
36 checkVideoIsPublished,
37 getLastNotification,
38 getUserNotifications,
39 markAsReadNotifications,
40 updateMyNotificationSettings,
41 markAsReadAllNotifications
42} from '../../../../shared/utils/users/user-notifications'
43import {
44 User,
45 UserNotification,
46 UserNotificationSetting,
47 UserNotificationSettingValue,
48 UserNotificationType
49} from '../../../../shared/models/users'
50import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
51import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
52import { VideoPrivacy } from '../../../../shared/models/videos'
53import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
54import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
55import * as uuidv4 from 'uuid/v4'
56import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
57
58const expect = chai.expect
59
60async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
61 const name = 'remote video ' + uuidv4()
62
63 const data = Object.assign({ name }, additionalParams)
64 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
65
66 await waitJobs(servers)
67
68 return { uuid: res.body.video.uuid, name }
69}
70
71async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
72 const name = 'local video ' + uuidv4()
73
74 const data = Object.assign({ name }, additionalParams)
75 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
76
77 await waitJobs(servers)
78
79 return { uuid: res.body.video.uuid, name }
80}
81
82describe('Test users notifications', function () {
83 let servers: ServerInfo[] = []
84 let userAccessToken: string
85 let userNotifications: UserNotification[] = []
86 let adminNotifications: UserNotification[] = []
87 let adminNotificationsServer2: UserNotification[] = []
88 const emails: object[] = []
89 let channelId: number
90
91 const allNotificationSettings: UserNotificationSetting = {
92 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
93 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
94 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
95 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
96 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
97 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
101 }
102
103 before(async function () {
104 this.timeout(120000)
105
106 await MockSmtpServer.Instance.collectEmails(emails)
107
108 await flushTests()
109
110 const overrideConfig = {
111 smtp: {
112 hostname: 'localhost'
113 }
114 }
115 servers = await flushAndRunMultipleServers(2, overrideConfig)
116
117 // Get the access tokens
118 await setAccessTokensToServers(servers)
119
120 // Server 1 and server 2 follow each other
121 await doubleFollow(servers[0], servers[1])
122
123 await waitJobs(servers)
124
125 const user = {
126 username: 'user_1',
127 password: 'super password'
128 }
129 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
130 userAccessToken = await userLogin(servers[0], user)
131
132 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
133 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
134 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
135
136 {
137 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
138 socket.on('new-notification', n => userNotifications.push(n))
139 }
140 {
141 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
142 socket.on('new-notification', n => adminNotifications.push(n))
143 }
144 {
145 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
146 socket.on('new-notification', n => adminNotificationsServer2.push(n))
147 }
148
149 {
150 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
151 channelId = resChannel.body.videoChannels[0].id
152 }
153 })
154
155 describe('New video from my subscription notification', function () {
156 let baseParams: CheckerBaseParams
157
158 before(() => {
159 baseParams = {
160 server: servers[0],
161 emails,
162 socketNotifications: userNotifications,
163 token: userAccessToken
164 }
165 })
166
167 it('Should not send notifications if the user does not follow the video publisher', async function () {
168 this.timeout(10000)
169
170 await uploadVideoByLocalAccount(servers)
171
172 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
173 expect(notification).to.be.undefined
174
175 expect(emails).to.have.lengthOf(0)
176 expect(userNotifications).to.have.lengthOf(0)
177 })
178
179 it('Should send a new video notification if the user follows the local video publisher', async function () {
180 this.timeout(15000)
181
182 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
183 await waitJobs(servers)
184
185 const { name, uuid } = await uploadVideoByLocalAccount(servers)
186 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
187 })
188
189 it('Should send a new video notification from a remote account', async function () {
190 this.timeout(50000) // Server 2 has transcoding enabled
191
192 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
193 await waitJobs(servers)
194
195 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
196 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
197 })
198
199 it('Should send a new video notification on a scheduled publication', async function () {
200 this.timeout(20000)
201
202 // In 2 seconds
203 let updateAt = new Date(new Date().getTime() + 2000)
204
205 const data = {
206 privacy: VideoPrivacy.PRIVATE,
207 scheduleUpdate: {
208 updateAt: updateAt.toISOString(),
209 privacy: VideoPrivacy.PUBLIC
210 }
211 }
212 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
213
214 await wait(6000)
215 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
216 })
217
218 it('Should send a new video notification on a remote scheduled publication', async function () {
219 this.timeout(20000)
220
221 // In 2 seconds
222 let updateAt = new Date(new Date().getTime() + 2000)
223
224 const data = {
225 privacy: VideoPrivacy.PRIVATE,
226 scheduleUpdate: {
227 updateAt: updateAt.toISOString(),
228 privacy: VideoPrivacy.PUBLIC
229 }
230 }
231 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
232 await waitJobs(servers)
233
234 await wait(6000)
235 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
236 })
237
238 it('Should not send a notification before the video is published', async function () {
239 this.timeout(20000)
240
241 let updateAt = new Date(new Date().getTime() + 100000)
242
243 const data = {
244 privacy: VideoPrivacy.PRIVATE,
245 scheduleUpdate: {
246 updateAt: updateAt.toISOString(),
247 privacy: VideoPrivacy.PUBLIC
248 }
249 }
250 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
251
252 await wait(6000)
253 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
254 })
255
256 it('Should send a new video notification when a video becomes public', async function () {
257 this.timeout(10000)
258
259 const data = { privacy: VideoPrivacy.PRIVATE }
260 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
261
262 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
263
264 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
265
266 await wait(500)
267 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
268 })
269
270 it('Should send a new video notification when a remote video becomes public', async function () {
271 this.timeout(20000)
272
273 const data = { privacy: VideoPrivacy.PRIVATE }
274 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
275
276 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
277
278 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
279
280 await waitJobs(servers)
281 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
282 })
283
284 it('Should not send a new video notification when a video becomes unlisted', async function () {
285 this.timeout(20000)
286
287 const data = { privacy: VideoPrivacy.PRIVATE }
288 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
289
290 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
291
292 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
293 })
294
295 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
296 this.timeout(20000)
297
298 const data = { privacy: VideoPrivacy.PRIVATE }
299 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
300
301 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
302
303 await waitJobs(servers)
304 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
305 })
306
307 it('Should send a new video notification after a video import', async function () {
308 this.timeout(30000)
309
310 const name = 'video import ' + uuidv4()
311
312 const attributes = {
313 name,
314 channelId,
315 privacy: VideoPrivacy.PUBLIC,
316 targetUrl: getYoutubeVideoUrl()
317 }
318 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
319 const uuid = res.body.video.uuid
320
321 await waitJobs(servers)
322
323 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
324 })
325 })
326
327 describe('Comment on my video notifications', function () {
328 let baseParams: CheckerBaseParams
329
330 before(() => {
331 baseParams = {
332 server: servers[0],
333 emails,
334 socketNotifications: userNotifications,
335 token: userAccessToken
336 }
337 })
338
339 it('Should not send a new comment notification after a comment on another video', async function () {
340 this.timeout(10000)
341
342 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
343 const uuid = resVideo.body.video.uuid
344
345 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
346 const commentId = resComment.body.comment.id
347
348 await wait(500)
349 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
350 })
351
352 it('Should not send a new comment notification if I comment my own video', async function () {
353 this.timeout(10000)
354
355 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
356 const uuid = resVideo.body.video.uuid
357
358 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
359 const commentId = resComment.body.comment.id
360
361 await wait(500)
362 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
363 })
364
365 it('Should not send a new comment notification if the account is muted', async function () {
366 this.timeout(10000)
367
368 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
369
370 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
371 const uuid = resVideo.body.video.uuid
372
373 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
374 const commentId = resComment.body.comment.id
375
376 await wait(500)
377 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
378
379 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
380 })
381
382 it('Should send a new comment notification after a local comment on my video', async function () {
383 this.timeout(10000)
384
385 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
386 const uuid = resVideo.body.video.uuid
387
388 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
389 const commentId = resComment.body.comment.id
390
391 await wait(500)
392 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
393 })
394
395 it('Should send a new comment notification after a remote comment on my video', async function () {
396 this.timeout(10000)
397
398 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
399 const uuid = resVideo.body.video.uuid
400
401 await waitJobs(servers)
402
403 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
404 const commentId = resComment.body.comment.id
405
406 await waitJobs(servers)
407 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
408 })
409
410 it('Should send a new comment notification after a local reply on my video', async function () {
411 this.timeout(10000)
412
413 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
414 const uuid = resVideo.body.video.uuid
415
416 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
417 const threadId = resThread.body.comment.id
418
419 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
420 const commentId = resComment.body.comment.id
421
422 await wait(500)
423 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
424 })
425
426 it('Should send a new comment notification after a remote reply on my video', async function () {
427 this.timeout(10000)
428
429 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
430 const uuid = resVideo.body.video.uuid
431 await waitJobs(servers)
432
433 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
434 const threadId = resThread.body.comment.id
435
436 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
437 const commentId = resComment.body.comment.id
438
439 await waitJobs(servers)
440 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
441 })
442 })
443
444 describe('Mention notifications', function () {
445 let baseParams: CheckerBaseParams
446
447 before(async () => {
448 baseParams = {
449 server: servers[0],
450 emails,
451 socketNotifications: userNotifications,
452 token: userAccessToken
453 }
454
455 await updateMyUser({
456 url: servers[0].url,
457 accessToken: servers[0].accessToken,
458 displayName: 'super root name'
459 })
460
461 await updateMyUser({
462 url: servers[1].url,
463 accessToken: servers[1].accessToken,
464 displayName: 'super root 2 name'
465 })
466 })
467
468 it('Should not send a new mention comment notification if I mention the video owner', async function () {
469 this.timeout(10000)
470
471 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
472 const uuid = resVideo.body.video.uuid
473
474 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
475 const commentId = resComment.body.comment.id
476
477 await wait(500)
478 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
479 })
480
481 it('Should not send a new mention comment notification if I mention myself', async function () {
482 this.timeout(10000)
483
484 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
485 const uuid = resVideo.body.video.uuid
486
487 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
488 const commentId = resComment.body.comment.id
489
490 await wait(500)
491 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
492 })
493
494 it('Should not send a new mention notification if the account is muted', async function () {
495 this.timeout(10000)
496
497 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
498
499 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
500 const uuid = resVideo.body.video.uuid
501
502 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
503 const commentId = resComment.body.comment.id
504
505 await wait(500)
506 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
507
508 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
509 })
510
511 it('Should send a new mention notification after local comments', async function () {
512 this.timeout(10000)
513
514 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
515 const uuid = resVideo.body.video.uuid
516
517 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
518 const threadId = resThread.body.comment.id
519
520 await wait(500)
521 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
522
523 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
524 const commentId = resComment.body.comment.id
525
526 await wait(500)
527 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
528 })
529
530 it('Should send a new mention notification after remote comments', async function () {
531 this.timeout(20000)
532
533 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
534 const uuid = resVideo.body.video.uuid
535
536 await waitJobs(servers)
537 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
538 const threadId = resThread.body.comment.id
539
540 await waitJobs(servers)
541 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
542
543 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
544 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
545 const commentId = resComment.body.comment.id
546
547 await waitJobs(servers)
548 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
549 })
550 })
551
552 describe('Video abuse for moderators notification' , function () {
553 let baseParams: CheckerBaseParams
554
555 before(() => {
556 baseParams = {
557 server: servers[0],
558 emails,
559 socketNotifications: adminNotifications,
560 token: servers[0].accessToken
561 }
562 })
563
564 it('Should send a notification to moderators on local video abuse', async function () {
565 this.timeout(10000)
566
567 const name = 'video for abuse ' + uuidv4()
568 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
569 const uuid = resVideo.body.video.uuid
570
571 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
572
573 await waitJobs(servers)
574 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
575 })
576
577 it('Should send a notification to moderators on remote video abuse', async function () {
578 this.timeout(10000)
579
580 const name = 'video for abuse ' + uuidv4()
581 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
582 const uuid = resVideo.body.video.uuid
583
584 await waitJobs(servers)
585
586 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
587
588 await waitJobs(servers)
589 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
590 })
591 })
592
593 describe('Video blacklist on my video', function () {
594 let baseParams: CheckerBaseParams
595
596 before(() => {
597 baseParams = {
598 server: servers[0],
599 emails,
600 socketNotifications: userNotifications,
601 token: userAccessToken
602 }
603 })
604
605 it('Should send a notification to video owner on blacklist', async function () {
606 this.timeout(10000)
607
608 const name = 'video for abuse ' + uuidv4()
609 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
610 const uuid = resVideo.body.video.uuid
611
612 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
613
614 await waitJobs(servers)
615 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
616 })
617
618 it('Should send a notification to video owner on unblacklist', async function () {
619 this.timeout(10000)
620
621 const name = 'video for abuse ' + uuidv4()
622 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
623 const uuid = resVideo.body.video.uuid
624
625 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
626
627 await waitJobs(servers)
628 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
629 await waitJobs(servers)
630
631 await wait(500)
632 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
633 })
634 })
635
636 describe('My video is published', function () {
637 let baseParams: CheckerBaseParams
638
639 before(() => {
640 baseParams = {
641 server: servers[1],
642 emails,
643 socketNotifications: adminNotificationsServer2,
644 token: servers[1].accessToken
645 }
646 })
647
648 it('Should not send a notification if transcoding is not enabled', async function () {
649 this.timeout(10000)
650
651 const { name, uuid } = await uploadVideoByLocalAccount(servers)
652 await waitJobs(servers)
653
654 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
655 })
656
657 it('Should not send a notification if the wait transcoding is false', async function () {
658 this.timeout(50000)
659
660 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
661 await waitJobs(servers)
662
663 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
664 if (notification) {
665 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
666 }
667 })
668
669 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
670 this.timeout(50000)
671
672 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
673 await waitJobs(servers)
674
675 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
676 })
677
678 it('Should send a notification with a transcoded video', async function () {
679 this.timeout(50000)
680
681 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
682 await waitJobs(servers)
683
684 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
685 })
686
687 it('Should send a notification when an imported video is transcoded', async function () {
688 this.timeout(50000)
689
690 const name = 'video import ' + uuidv4()
691
692 const attributes = {
693 name,
694 channelId,
695 privacy: VideoPrivacy.PUBLIC,
696 targetUrl: getYoutubeVideoUrl(),
697 waitTranscoding: true
698 }
699 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
700 const uuid = res.body.video.uuid
701
702 await waitJobs(servers)
703 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
704 })
705
706 it('Should send a notification when the scheduled update has been proceeded', async function () {
707 this.timeout(70000)
708
709 // In 2 seconds
710 let updateAt = new Date(new Date().getTime() + 2000)
711
712 const data = {
713 privacy: VideoPrivacy.PRIVATE,
714 scheduleUpdate: {
715 updateAt: updateAt.toISOString(),
716 privacy: VideoPrivacy.PUBLIC
717 }
718 }
719 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
720
721 await wait(6000)
722 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
723 })
724
725 it('Should not send a notification before the video is published', async function () {
726 this.timeout(20000)
727
728 let updateAt = new Date(new Date().getTime() + 100000)
729
730 const data = {
731 privacy: VideoPrivacy.PRIVATE,
732 scheduleUpdate: {
733 updateAt: updateAt.toISOString(),
734 privacy: VideoPrivacy.PUBLIC
735 }
736 }
737 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
738
739 await wait(6000)
740 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
741 })
742 })
743
744 describe('My video is imported', function () {
745 let baseParams: CheckerBaseParams
746
747 before(() => {
748 baseParams = {
749 server: servers[0],
750 emails,
751 socketNotifications: adminNotifications,
752 token: servers[0].accessToken
753 }
754 })
755
756 it('Should send a notification when the video import failed', async function () {
757 this.timeout(70000)
758
759 const name = 'video import ' + uuidv4()
760
761 const attributes = {
762 name,
763 channelId,
764 privacy: VideoPrivacy.PRIVATE,
765 targetUrl: getBadVideoUrl()
766 }
767 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
768 const uuid = res.body.video.uuid
769
770 await waitJobs(servers)
771 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
772 })
773
774 it('Should send a notification when the video import succeeded', async function () {
775 this.timeout(70000)
776
777 const name = 'video import ' + uuidv4()
778
779 const attributes = {
780 name,
781 channelId,
782 privacy: VideoPrivacy.PRIVATE,
783 targetUrl: getYoutubeVideoUrl()
784 }
785 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
786 const uuid = res.body.video.uuid
787
788 await waitJobs(servers)
789 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
790 })
791 })
792
793 describe('New registration', function () {
794 let baseParams: CheckerBaseParams
795
796 before(() => {
797 baseParams = {
798 server: servers[0],
799 emails,
800 socketNotifications: adminNotifications,
801 token: servers[0].accessToken
802 }
803 })
804
805 it('Should send a notification only to moderators when a user registers on the instance', async function () {
806 this.timeout(10000)
807
808 await registerUser(servers[0].url, 'user_45', 'password')
809
810 await waitJobs(servers)
811
812 await checkUserRegistered(baseParams, 'user_45', 'presence')
813
814 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
815 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
816 })
817 })
818
819 describe('New actor follow', function () {
820 let baseParams: CheckerBaseParams
821 let myChannelName = 'super channel name'
822 let myUserName = 'super user name'
823
824 before(async () => {
825 baseParams = {
826 server: servers[0],
827 emails,
828 socketNotifications: userNotifications,
829 token: userAccessToken
830 }
831
832 await updateMyUser({
833 url: servers[0].url,
834 accessToken: servers[0].accessToken,
835 displayName: 'super root name'
836 })
837
838 await updateMyUser({
839 url: servers[0].url,
840 accessToken: userAccessToken,
841 displayName: myUserName
842 })
843
844 await updateMyUser({
845 url: servers[1].url,
846 accessToken: servers[1].accessToken,
847 displayName: 'super root 2 name'
848 })
849
850 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
851 })
852
853 it('Should notify when a local channel is following one of our channel', async function () {
854 this.timeout(10000)
855
856 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
857 await waitJobs(servers)
858
859 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
860
861 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
862 })
863
864 it('Should notify when a remote channel is following one of our channel', async function () {
865 this.timeout(10000)
866
867 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
868 await waitJobs(servers)
869
870 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
871
872 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
873 })
874
875 it('Should notify when a local account is following one of our channel', async function () {
876 this.timeout(10000)
877
878 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
879
880 await waitJobs(servers)
881
882 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
883 })
884
885 it('Should notify when a remote account is following one of our channel', async function () {
886 this.timeout(10000)
887
888 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
889
890 await waitJobs(servers)
891
892 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
893 })
894 })
895
896 describe('Mark as read', function () {
897 it('Should mark as read some notifications', async function () {
898 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
899 const ids = res.body.data.map(n => n.id)
900
901 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
902 })
903
904 it('Should have the notifications marked as read', async function () {
905 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
906
907 const notifications = res.body.data as UserNotification[]
908 expect(notifications[ 0 ].read).to.be.false
909 expect(notifications[ 1 ].read).to.be.false
910 expect(notifications[ 2 ].read).to.be.true
911 expect(notifications[ 3 ].read).to.be.true
912 expect(notifications[ 4 ].read).to.be.true
913 expect(notifications[ 5 ].read).to.be.false
914 })
915
916 it('Should only list read notifications', async function () {
917 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
918
919 const notifications = res.body.data as UserNotification[]
920 for (const notification of notifications) {
921 expect(notification.read).to.be.true
922 }
923 })
924
925 it('Should only list unread notifications', async function () {
926 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
927
928 const notifications = res.body.data as UserNotification[]
929 for (const notification of notifications) {
930 expect(notification.read).to.be.false
931 }
932 })
933
934 it('Should mark as read all notifications', async function () {
935 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
936
937 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
938
939 expect(res.body.total).to.equal(0)
940 expect(res.body.data).to.have.lengthOf(0)
941 })
942 })
943
944 describe('Notification settings', function () {
945 let baseParams: CheckerBaseParams
946
947 before(() => {
948 baseParams = {
949 server: servers[0],
950 emails,
951 socketNotifications: userNotifications,
952 token: userAccessToken
953 }
954 })
955
956 it('Should not have notifications', async function () {
957 this.timeout(10000)
958
959 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
960 newVideoFromSubscription: UserNotificationSettingValue.NONE
961 }))
962
963 {
964 const res = await getMyUserInformation(servers[0].url, userAccessToken)
965 const info = res.body as User
966 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
967 }
968
969 const { name, uuid } = await uploadVideoByLocalAccount(servers)
970
971 const check = { web: true, mail: true }
972 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
973 })
974
975 it('Should only have web notifications', async function () {
976 this.timeout(10000)
977
978 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
979 newVideoFromSubscription: UserNotificationSettingValue.WEB
980 }))
981
982 {
983 const res = await getMyUserInformation(servers[0].url, userAccessToken)
984 const info = res.body as User
985 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
986 }
987
988 const { name, uuid } = await uploadVideoByLocalAccount(servers)
989
990 {
991 const check = { mail: true, web: false }
992 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
993 }
994
995 {
996 const check = { mail: false, web: true }
997 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
998 }
999 })
1000
1001 it('Should only have mail notifications', async function () {
1002 this.timeout(10000)
1003
1004 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1005 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1006 }))
1007
1008 {
1009 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1010 const info = res.body as User
1011 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1012 }
1013
1014 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1015
1016 {
1017 const check = { mail: false, web: true }
1018 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1019 }
1020
1021 {
1022 const check = { mail: true, web: false }
1023 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1024 }
1025 })
1026
1027 it('Should have email and web notifications', async function () {
1028 this.timeout(10000)
1029
1030 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1031 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1032 }))
1033
1034 {
1035 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1036 const info = res.body as User
1037 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1038 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1039 )
1040 }
1041
1042 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1043
1044 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1045 })
1046 })
1047
1048 after(async function () {
1049 MockSmtpServer.Instance.kill()
1050
1051 killallServers(servers)
1052 })
1053})
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index 65b80540c..88a7187d6 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -2,18 +2,27 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { createUser, doubleFollow, flushAndRunMultipleServers, follow, getVideosList, unfollow, updateVideo, userLogin } from '../../utils' 5import {
6import { killallServers, ServerInfo, uploadVideo } from '../../utils/index' 6 createUser,
7import { setAccessTokensToServers } from '../../utils/users/login' 7 doubleFollow,
8 flushAndRunMultipleServers,
9 follow,
10 getVideosList,
11 unfollow,
12 updateVideo,
13 userLogin
14} from '../../../../shared/utils'
15import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
16import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
8import { Video, VideoChannel } from '../../../../shared/models/videos' 17import { Video, VideoChannel } from '../../../../shared/models/videos'
9import { waitJobs } from '../../utils/server/jobs' 18import { waitJobs } from '../../../../shared/utils/server/jobs'
10import { 19import {
11 addUserSubscription, 20 addUserSubscription,
12 listUserSubscriptions, 21 listUserSubscriptions,
13 listUserSubscriptionVideos, 22 listUserSubscriptionVideos,
14 removeUserSubscription, 23 removeUserSubscription,
15 getUserSubscription, areSubscriptionsExist 24 getUserSubscription, areSubscriptionsExist
16} from '../../utils/users/user-subscriptions' 25} from '../../../../shared/utils/users/user-subscriptions'
17 26
18const expect = chai.expect 27const expect = chai.expect
19 28
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index d8699db17..006d6cdf0 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -13,13 +13,13 @@ import {
13 removeUser, 13 removeUser,
14 updateMyUser, 14 updateMyUser,
15 userLogin 15 userLogin
16} from '../../utils' 16} from '../../../../shared/utils'
17import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index' 17import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/utils/index'
18import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts' 18import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/utils/users/accounts'
19import { setAccessTokensToServers } from '../../utils/users/login' 19import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
20import { User } from '../../../../shared/models/users' 20import { User } from '../../../../shared/models/users'
21import { VideoChannel } from '../../../../shared/models/videos' 21import { VideoChannel } from '../../../../shared/models/videos'
22import { waitJobs } from '../../utils/server/jobs' 22import { waitJobs } from '../../../../shared/utils/server/jobs'
23 23
24const expect = chai.expect 24const expect = chai.expect
25 25
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index fa5f5e371..babeda2b8 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -4,11 +4,11 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, 6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers,
7 userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig 7 userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait
8} from '../../utils' 8} from '../../../../shared/utils'
9import { setAccessTokensToServers } from '../../utils/users/login' 9import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
10import { mockSmtpServer } from '../../utils/miscs/email' 10import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
11import { waitJobs } from '../../utils/server/jobs' 11import { waitJobs } from '../../../../shared/utils/server/jobs'
12 12
13const expect = chai.expect 13const expect = chai.expect
14 14
@@ -30,7 +30,7 @@ describe('Test users account verification', function () {
30 before(async function () { 30 before(async function () {
31 this.timeout(30000) 31 this.timeout(30000)
32 32
33 await mockSmtpServer(emails) 33 await MockSmtpServer.Instance.collectEmails(emails)
34 34
35 await flushTests() 35 await flushTests()
36 36
@@ -123,6 +123,7 @@ describe('Test users account verification', function () {
123 }) 123 })
124 124
125 after(async function () { 125 after(async function () {
126 MockSmtpServer.Instance.kill()
126 killallServers([ server ]) 127 killallServers([ server ])
127 128
128 // Keep the logs if the test failed 129 // Keep the logs if the test failed
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 8b9c6b455..c4465d541 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -32,10 +32,10 @@ import {
32 updateUser, 32 updateUser,
33 uploadVideo, 33 uploadVideo,
34 userLogin 34 userLogin
35} from '../../utils/index' 35} from '../../../../shared/utils/index'
36import { follow } from '../../utils/server/follows' 36import { follow } from '../../../../shared/utils/server/follows'
37import { setAccessTokensToServers } from '../../utils/users/login' 37import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
38import { getMyVideos } from '../../utils/videos/videos' 38import { getMyVideos } from '../../../../shared/utils/videos/videos'
39 39
40const expect = chai.expect 40const expect = chai.expect
41 41
@@ -180,7 +180,7 @@ describe('Test users', function () {
180 it('Should be able to upload a video again') 180 it('Should be able to upload a video again')
181 181
182 it('Should be able to create a new user', async function () { 182 it('Should be able to create a new user', async function () {
183 await createUser(server.url, accessToken, user.username,user.password, 2 * 1024 * 1024) 183 await createUser(server.url, accessToken, user.username, user.password, 2 * 1024 * 1024)
184 }) 184 })
185 185
186 it('Should be able to login with this user', async function () { 186 it('Should be able to login with this user', async function () {
@@ -322,6 +322,40 @@ describe('Test users', function () {
322 expect(users[ 1 ].nsfwPolicy).to.equal('display') 322 expect(users[ 1 ].nsfwPolicy).to.equal('display')
323 }) 323 })
324 324
325 it('Should search user by username', async function () {
326 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
327 const users = res.body.data as User[]
328
329 expect(res.body.total).to.equal(1)
330 expect(users.length).to.equal(1)
331
332 expect(users[ 0 ].username).to.equal('root')
333 })
334
335 it('Should search user by email', async function () {
336 {
337 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
338 const users = res.body.data as User[]
339
340 expect(res.body.total).to.equal(1)
341 expect(users.length).to.equal(1)
342
343 expect(users[ 0 ].username).to.equal('user_1')
344 expect(users[ 0 ].email).to.equal('user_1@example.com')
345 }
346
347 {
348 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
349 const users = res.body.data as User[]
350
351 expect(res.body.total).to.equal(2)
352 expect(users.length).to.equal(2)
353
354 expect(users[ 0 ].username).to.equal('root')
355 expect(users[ 1 ].username).to.equal('user_1')
356 }
357 })
358
325 it('Should update my password', async function () { 359 it('Should update my password', async function () {
326 await updateMyUser({ 360 await updateMyUser({
327 url: server.url, 361 url: server.url,
@@ -444,6 +478,7 @@ describe('Test users', function () {
444 userId, 478 userId,
445 accessToken, 479 accessToken,
446 email: 'updated2@example.com', 480 email: 'updated2@example.com',
481 emailVerified: true,
447 videoQuota: 42, 482 videoQuota: 42,
448 role: UserRole.MODERATOR 483 role: UserRole.MODERATOR
449 }) 484 })
@@ -453,6 +488,7 @@ describe('Test users', function () {
453 488
454 expect(user.username).to.equal('user_1') 489 expect(user.username).to.equal('user_1')
455 expect(user.email).to.equal('updated2@example.com') 490 expect(user.email).to.equal('updated2@example.com')
491 expect(user.emailVerified).to.be.true
456 expect(user.nsfwPolicy).to.equal('do_not_list') 492 expect(user.nsfwPolicy).to.equal('do_not_list')
457 expect(user.videoQuota).to.equal(42) 493 expect(user.videoQuota).to.equal(42)
458 expect(user.roleLabel).to.equal('Moderator') 494 expect(user.roleLabel).to.equal('Moderator')
@@ -465,8 +501,20 @@ describe('Test users', function () {
465 accessTokenUser = await userLogin(server, user) 501 accessTokenUser = await userLogin(server, user)
466 }) 502 })
467 503
468 it('Should not be able to delete a user by a moderator', async function () { 504 it('Should be able to update another user password', async function () {
469 await removeUser(server.url, 2, accessTokenUser, 403) 505 await updateUser({
506 url: server.url,
507 userId,
508 accessToken,
509 password: 'password updated'
510 })
511
512 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
513
514 await userLogin(server, user, 400)
515
516 user.password = 'password updated'
517 accessTokenUser = await userLogin(server, user)
470 }) 518 })
471 519
472 it('Should be able to list video blacklist by a moderator', async function () { 520 it('Should be able to list video blacklist by a moderator', async function () {