]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | addVideoToBlacklist, | |
7 | cleanupTests, | |
8 | createUser, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
11 | follow, | |
12 | getCustomConfig, | |
13 | getMyUserInformation, | |
14 | getVideoCommentThreads, | |
15 | getVideoThreadComments, | |
16 | immutableAssign, | |
17 | registerUser, | |
18 | removeVideoFromBlacklist, | |
19 | reportVideoAbuse, | |
20 | updateCustomConfig, | |
21 | updateMyUser, | |
22 | updateVideo, | |
23 | updateVideoChannel, | |
24 | userLogin, | |
25 | wait | |
26 | } from '../../../../shared/extra-utils' | |
27 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | |
28 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | |
29 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
30 | import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io' | |
31 | import { | |
32 | checkCommentMention, | |
33 | CheckerBaseParams, | |
34 | checkMyVideoImportIsFinished, | |
35 | checkNewActorFollow, | |
36 | checkNewBlacklistOnMyVideo, | |
37 | checkNewCommentOnMyVideo, | |
38 | checkNewInstanceFollower, | |
39 | checkNewVideoAbuseForModerators, | |
40 | checkNewVideoFromSubscription, | |
41 | checkUserRegistered, | |
42 | checkVideoAutoBlacklistForModerators, | |
43 | checkVideoIsPublished, | |
44 | getLastNotification, | |
45 | getUserNotifications, | |
46 | markAsReadAllNotifications, | |
47 | markAsReadNotifications, | |
48 | updateMyNotificationSettings | |
49 | } from '../../../../shared/extra-utils/users/user-notifications' | |
50 | import { | |
51 | User, | |
52 | UserNotification, | |
53 | UserNotificationSetting, | |
54 | UserNotificationSettingValue, | |
55 | UserNotificationType | |
56 | } from '../../../../shared/models/users' | |
57 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | |
58 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | |
59 | import { VideoPrivacy } from '../../../../shared/models/videos' | |
60 | import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' | |
61 | import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
62 | import * as uuidv4 from 'uuid/v4' | |
63 | import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist' | |
64 | import { CustomConfig } from '../../../../shared/models/server' | |
65 | import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | |
66 | ||
67 | const expect = chai.expect | |
68 | ||
69 | async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) { | |
70 | const name = 'remote video ' + uuidv4() | |
71 | ||
72 | const data = Object.assign({ name }, additionalParams) | |
73 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data) | |
74 | ||
75 | await waitJobs(servers) | |
76 | ||
77 | return { uuid: res.body.video.uuid, name } | |
78 | } | |
79 | ||
80 | async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) { | |
81 | const name = 'local video ' + uuidv4() | |
82 | ||
83 | const data = Object.assign({ name }, additionalParams) | |
84 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data) | |
85 | ||
86 | await waitJobs(servers) | |
87 | ||
88 | return { uuid: res.body.video.uuid, name } | |
89 | } | |
90 | ||
91 | describe('Test users notifications', function () { | |
92 | let servers: ServerInfo[] = [] | |
93 | let userAccessToken: string | |
94 | let userNotifications: UserNotification[] = [] | |
95 | let adminNotifications: UserNotification[] = [] | |
96 | let adminNotificationsServer2: UserNotification[] = [] | |
97 | const emails: object[] = [] | |
98 | let channelId: number | |
99 | ||
100 | const allNotificationSettings: UserNotificationSetting = { | |
101 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
102 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
103 | videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
104 | videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
105 | blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
106 | myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
107 | myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
108 | commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
109 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
110 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | |
111 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | |
112 | } | |
113 | ||
114 | before(async function () { | |
115 | this.timeout(120000) | |
116 | ||
117 | const port = await MockSmtpServer.Instance.collectEmails(emails) | |
118 | ||
119 | const overrideConfig = { | |
120 | smtp: { | |
121 | hostname: 'localhost', | |
122 | port | |
123 | } | |
124 | } | |
125 | servers = await flushAndRunMultipleServers(3, overrideConfig) | |
126 | ||
127 | // Get the access tokens | |
128 | await setAccessTokensToServers(servers) | |
129 | ||
130 | // Server 1 and server 2 follow each other | |
131 | await doubleFollow(servers[0], servers[1]) | |
132 | ||
133 | await waitJobs(servers) | |
134 | ||
135 | const user = { | |
136 | username: 'user_1', | |
137 | password: 'super password' | |
138 | } | |
139 | await createUser({ | |
140 | url: servers[ 0 ].url, | |
141 | accessToken: servers[ 0 ].accessToken, | |
142 | username: user.username, | |
143 | password: user.password, | |
144 | videoQuota: 10 * 1000 * 1000 | |
145 | }) | |
146 | userAccessToken = await userLogin(servers[0], user) | |
147 | ||
148 | await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) | |
149 | await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings) | |
150 | await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings) | |
151 | ||
152 | { | |
153 | const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken) | |
154 | socket.on('new-notification', n => userNotifications.push(n)) | |
155 | } | |
156 | { | |
157 | const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken) | |
158 | socket.on('new-notification', n => adminNotifications.push(n)) | |
159 | } | |
160 | { | |
161 | const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken) | |
162 | socket.on('new-notification', n => adminNotificationsServer2.push(n)) | |
163 | } | |
164 | ||
165 | { | |
166 | const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
167 | channelId = resChannel.body.videoChannels[0].id | |
168 | } | |
169 | }) | |
170 | ||
171 | describe('New video from my subscription notification', function () { | |
172 | let baseParams: CheckerBaseParams | |
173 | ||
174 | before(() => { | |
175 | baseParams = { | |
176 | server: servers[0], | |
177 | emails, | |
178 | socketNotifications: userNotifications, | |
179 | token: userAccessToken | |
180 | } | |
181 | }) | |
182 | ||
183 | it('Should not send notifications if the user does not follow the video publisher', async function () { | |
184 | this.timeout(10000) | |
185 | ||
186 | await uploadVideoByLocalAccount(servers) | |
187 | ||
188 | const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) | |
189 | expect(notification).to.be.undefined | |
190 | ||
191 | expect(emails).to.have.lengthOf(0) | |
192 | expect(userNotifications).to.have.lengthOf(0) | |
193 | }) | |
194 | ||
195 | it('Should send a new video notification if the user follows the local video publisher', async function () { | |
196 | this.timeout(15000) | |
197 | ||
198 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) | |
199 | await waitJobs(servers) | |
200 | ||
201 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | |
202 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
203 | }) | |
204 | ||
205 | it('Should send a new video notification from a remote account', async function () { | |
206 | this.timeout(50000) // Server 2 has transcoding enabled | |
207 | ||
208 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) | |
209 | await waitJobs(servers) | |
210 | ||
211 | const { name, uuid } = await uploadVideoByRemoteAccount(servers) | |
212 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
213 | }) | |
214 | ||
215 | it('Should send a new video notification on a scheduled publication', async function () { | |
216 | this.timeout(20000) | |
217 | ||
218 | // In 2 seconds | |
219 | let updateAt = new Date(new Date().getTime() + 2000) | |
220 | ||
221 | const data = { | |
222 | privacy: VideoPrivacy.PRIVATE, | |
223 | scheduleUpdate: { | |
224 | updateAt: updateAt.toISOString(), | |
225 | privacy: VideoPrivacy.PUBLIC | |
226 | } | |
227 | } | |
228 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | |
229 | ||
230 | await wait(6000) | |
231 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
232 | }) | |
233 | ||
234 | it('Should send a new video notification on a remote scheduled publication', async function () { | |
235 | this.timeout(50000) | |
236 | ||
237 | // In 2 seconds | |
238 | let updateAt = new Date(new Date().getTime() + 2000) | |
239 | ||
240 | const data = { | |
241 | privacy: VideoPrivacy.PRIVATE, | |
242 | scheduleUpdate: { | |
243 | updateAt: updateAt.toISOString(), | |
244 | privacy: VideoPrivacy.PUBLIC | |
245 | } | |
246 | } | |
247 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | |
248 | await waitJobs(servers) | |
249 | ||
250 | await wait(6000) | |
251 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
252 | }) | |
253 | ||
254 | it('Should not send a notification before the video is published', async function () { | |
255 | this.timeout(20000) | |
256 | ||
257 | let updateAt = new Date(new Date().getTime() + 1000000) | |
258 | ||
259 | const data = { | |
260 | privacy: VideoPrivacy.PRIVATE, | |
261 | scheduleUpdate: { | |
262 | updateAt: updateAt.toISOString(), | |
263 | privacy: VideoPrivacy.PUBLIC | |
264 | } | |
265 | } | |
266 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | |
267 | ||
268 | await wait(6000) | |
269 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | |
270 | }) | |
271 | ||
272 | it('Should send a new video notification when a video becomes public', async function () { | |
273 | this.timeout(10000) | |
274 | ||
275 | const data = { privacy: VideoPrivacy.PRIVATE } | |
276 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | |
277 | ||
278 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | |
279 | ||
280 | await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) | |
281 | ||
282 | await wait(500) | |
283 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
284 | }) | |
285 | ||
286 | it('Should send a new video notification when a remote video becomes public', async function () { | |
287 | this.timeout(20000) | |
288 | ||
289 | const data = { privacy: VideoPrivacy.PRIVATE } | |
290 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | |
291 | ||
292 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | |
293 | ||
294 | await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) | |
295 | ||
296 | await waitJobs(servers) | |
297 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
298 | }) | |
299 | ||
300 | it('Should not send a new video notification when a video becomes unlisted', async function () { | |
301 | this.timeout(20000) | |
302 | ||
303 | const data = { privacy: VideoPrivacy.PRIVATE } | |
304 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | |
305 | ||
306 | await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) | |
307 | ||
308 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | |
309 | }) | |
310 | ||
311 | it('Should not send a new video notification when a remote video becomes unlisted', async function () { | |
312 | this.timeout(20000) | |
313 | ||
314 | const data = { privacy: VideoPrivacy.PRIVATE } | |
315 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | |
316 | ||
317 | await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) | |
318 | ||
319 | await waitJobs(servers) | |
320 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | |
321 | }) | |
322 | ||
323 | it('Should send a new video notification after a video import', async function () { | |
324 | this.timeout(100000) | |
325 | ||
326 | const name = 'video import ' + uuidv4() | |
327 | ||
328 | const attributes = { | |
329 | name, | |
330 | channelId, | |
331 | privacy: VideoPrivacy.PUBLIC, | |
332 | targetUrl: getYoutubeVideoUrl() | |
333 | } | |
334 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
335 | const uuid = res.body.video.uuid | |
336 | ||
337 | await waitJobs(servers) | |
338 | ||
339 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
340 | }) | |
341 | }) | |
342 | ||
343 | describe('Comment on my video notifications', function () { | |
344 | let baseParams: CheckerBaseParams | |
345 | ||
346 | before(() => { | |
347 | baseParams = { | |
348 | server: servers[0], | |
349 | emails, | |
350 | socketNotifications: userNotifications, | |
351 | token: userAccessToken | |
352 | } | |
353 | }) | |
354 | ||
355 | it('Should not send a new comment notification after a comment on another video', async function () { | |
356 | this.timeout(10000) | |
357 | ||
358 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | |
359 | const uuid = resVideo.body.video.uuid | |
360 | ||
361 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | |
362 | const commentId = resComment.body.comment.id | |
363 | ||
364 | await wait(500) | |
365 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | |
366 | }) | |
367 | ||
368 | it('Should not send a new comment notification if I comment my own video', async function () { | |
369 | this.timeout(10000) | |
370 | ||
371 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
372 | const uuid = resVideo.body.video.uuid | |
373 | ||
374 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') | |
375 | const commentId = resComment.body.comment.id | |
376 | ||
377 | await wait(500) | |
378 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | |
379 | }) | |
380 | ||
381 | it('Should not send a new comment notification if the account is muted', async function () { | |
382 | this.timeout(10000) | |
383 | ||
384 | await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') | |
385 | ||
386 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
387 | const uuid = resVideo.body.video.uuid | |
388 | ||
389 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | |
390 | const commentId = resComment.body.comment.id | |
391 | ||
392 | await wait(500) | |
393 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | |
394 | ||
395 | await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') | |
396 | }) | |
397 | ||
398 | it('Should send a new comment notification after a local comment on my video', async function () { | |
399 | this.timeout(10000) | |
400 | ||
401 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
402 | const uuid = resVideo.body.video.uuid | |
403 | ||
404 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | |
405 | const commentId = resComment.body.comment.id | |
406 | ||
407 | await wait(500) | |
408 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | |
409 | }) | |
410 | ||
411 | it('Should send a new comment notification after a remote comment on my video', async function () { | |
412 | this.timeout(10000) | |
413 | ||
414 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
415 | const uuid = resVideo.body.video.uuid | |
416 | ||
417 | await waitJobs(servers) | |
418 | ||
419 | await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') | |
420 | ||
421 | await waitJobs(servers) | |
422 | ||
423 | const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | |
424 | expect(resComment.body.data).to.have.lengthOf(1) | |
425 | const commentId = resComment.body.data[0].id | |
426 | ||
427 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | |
428 | }) | |
429 | ||
430 | it('Should send a new comment notification after a local reply on my video', async function () { | |
431 | this.timeout(10000) | |
432 | ||
433 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
434 | const uuid = resVideo.body.video.uuid | |
435 | ||
436 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | |
437 | const threadId = resThread.body.comment.id | |
438 | ||
439 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') | |
440 | const commentId = resComment.body.comment.id | |
441 | ||
442 | await wait(500) | |
443 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | |
444 | }) | |
445 | ||
446 | it('Should send a new comment notification after a remote reply on my video', async function () { | |
447 | this.timeout(10000) | |
448 | ||
449 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
450 | const uuid = resVideo.body.video.uuid | |
451 | await waitJobs(servers) | |
452 | ||
453 | { | |
454 | const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment') | |
455 | const threadId = resThread.body.comment.id | |
456 | await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply') | |
457 | } | |
458 | ||
459 | await waitJobs(servers) | |
460 | ||
461 | const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | |
462 | expect(resThread.body.data).to.have.lengthOf(1) | |
463 | const threadId = resThread.body.data[0].id | |
464 | ||
465 | const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId) | |
466 | const tree = resComments.body as VideoCommentThreadTree | |
467 | ||
468 | expect(tree.children).to.have.lengthOf(1) | |
469 | const commentId = tree.children[0].comment.id | |
470 | ||
471 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | |
472 | }) | |
473 | }) | |
474 | ||
475 | describe('Mention notifications', function () { | |
476 | let baseParams: CheckerBaseParams | |
477 | ||
478 | before(async () => { | |
479 | baseParams = { | |
480 | server: servers[0], | |
481 | emails, | |
482 | socketNotifications: userNotifications, | |
483 | token: userAccessToken | |
484 | } | |
485 | ||
486 | await updateMyUser({ | |
487 | url: servers[0].url, | |
488 | accessToken: servers[0].accessToken, | |
489 | displayName: 'super root name' | |
490 | }) | |
491 | ||
492 | await updateMyUser({ | |
493 | url: servers[1].url, | |
494 | accessToken: servers[1].accessToken, | |
495 | displayName: 'super root 2 name' | |
496 | }) | |
497 | }) | |
498 | ||
499 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | |
500 | this.timeout(10000) | |
501 | ||
502 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | |
503 | const uuid = resVideo.body.video.uuid | |
504 | ||
505 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | |
506 | const commentId = resComment.body.comment.id | |
507 | ||
508 | await wait(500) | |
509 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | |
510 | }) | |
511 | ||
512 | it('Should not send a new mention comment notification if I mention myself', async function () { | |
513 | this.timeout(10000) | |
514 | ||
515 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | |
516 | const uuid = resVideo.body.video.uuid | |
517 | ||
518 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') | |
519 | const commentId = resComment.body.comment.id | |
520 | ||
521 | await wait(500) | |
522 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | |
523 | }) | |
524 | ||
525 | it('Should not send a new mention notification if the account is muted', async function () { | |
526 | this.timeout(10000) | |
527 | ||
528 | await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') | |
529 | ||
530 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | |
531 | const uuid = resVideo.body.video.uuid | |
532 | ||
533 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | |
534 | const commentId = resComment.body.comment.id | |
535 | ||
536 | await wait(500) | |
537 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | |
538 | ||
539 | await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') | |
540 | }) | |
541 | ||
542 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | |
543 | this.timeout(20000) | |
544 | ||
545 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | |
546 | const uuid = resVideo.body.video.uuid | |
547 | ||
548 | await waitJobs(servers) | |
549 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello') | |
550 | const threadId = resThread.body.comment.id | |
551 | ||
552 | await waitJobs(servers) | |
553 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') | |
554 | }) | |
555 | ||
556 | it('Should send a new mention notification after local comments', async function () { | |
557 | this.timeout(10000) | |
558 | ||
559 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | |
560 | const uuid = resVideo.body.video.uuid | |
561 | ||
562 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') | |
563 | const threadId = resThread.body.comment.id | |
564 | ||
565 | await wait(500) | |
566 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') | |
567 | ||
568 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') | |
569 | const commentId = resComment.body.comment.id | |
570 | ||
571 | await wait(500) | |
572 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') | |
573 | }) | |
574 | ||
575 | it('Should send a new mention notification after remote comments', async function () { | |
576 | this.timeout(20000) | |
577 | ||
578 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | |
579 | const uuid = resVideo.body.video.uuid | |
580 | ||
581 | await waitJobs(servers) | |
582 | ||
583 | const text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1` | |
584 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) | |
585 | const server2ThreadId = resThread.body.comment.id | |
586 | ||
587 | await waitJobs(servers) | |
588 | ||
589 | const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | |
590 | expect(resThread2.body.data).to.have.lengthOf(1) | |
591 | const server1ThreadId = resThread2.body.data[0].id | |
592 | await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') | |
593 | ||
594 | const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}` | |
595 | await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) | |
596 | ||
597 | await waitJobs(servers) | |
598 | ||
599 | const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId) | |
600 | const tree = resComments.body as VideoCommentThreadTree | |
601 | ||
602 | expect(tree.children).to.have.lengthOf(1) | |
603 | const commentId = tree.children[0].comment.id | |
604 | ||
605 | await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') | |
606 | }) | |
607 | }) | |
608 | ||
609 | describe('Video abuse for moderators notification' , function () { | |
610 | let baseParams: CheckerBaseParams | |
611 | ||
612 | before(() => { | |
613 | baseParams = { | |
614 | server: servers[0], | |
615 | emails, | |
616 | socketNotifications: adminNotifications, | |
617 | token: servers[0].accessToken | |
618 | } | |
619 | }) | |
620 | ||
621 | it('Should send a notification to moderators on local video abuse', async function () { | |
622 | this.timeout(10000) | |
623 | ||
624 | const name = 'video for abuse ' + uuidv4() | |
625 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
626 | const uuid = resVideo.body.video.uuid | |
627 | ||
628 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') | |
629 | ||
630 | await waitJobs(servers) | |
631 | await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') | |
632 | }) | |
633 | ||
634 | it('Should send a notification to moderators on remote video abuse', async function () { | |
635 | this.timeout(10000) | |
636 | ||
637 | const name = 'video for abuse ' + uuidv4() | |
638 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
639 | const uuid = resVideo.body.video.uuid | |
640 | ||
641 | await waitJobs(servers) | |
642 | ||
643 | await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') | |
644 | ||
645 | await waitJobs(servers) | |
646 | await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') | |
647 | }) | |
648 | }) | |
649 | ||
650 | describe('Video blacklist on my video', function () { | |
651 | let baseParams: CheckerBaseParams | |
652 | ||
653 | before(() => { | |
654 | baseParams = { | |
655 | server: servers[0], | |
656 | emails, | |
657 | socketNotifications: userNotifications, | |
658 | token: userAccessToken | |
659 | } | |
660 | }) | |
661 | ||
662 | it('Should send a notification to video owner on blacklist', async function () { | |
663 | this.timeout(10000) | |
664 | ||
665 | const name = 'video for abuse ' + uuidv4() | |
666 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
667 | const uuid = resVideo.body.video.uuid | |
668 | ||
669 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
670 | ||
671 | await waitJobs(servers) | |
672 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') | |
673 | }) | |
674 | ||
675 | it('Should send a notification to video owner on unblacklist', async function () { | |
676 | this.timeout(10000) | |
677 | ||
678 | const name = 'video for abuse ' + uuidv4() | |
679 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
680 | const uuid = resVideo.body.video.uuid | |
681 | ||
682 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
683 | ||
684 | await waitJobs(servers) | |
685 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
686 | await waitJobs(servers) | |
687 | ||
688 | await wait(500) | |
689 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') | |
690 | }) | |
691 | }) | |
692 | ||
693 | describe('My video is published', function () { | |
694 | let baseParams: CheckerBaseParams | |
695 | ||
696 | before(() => { | |
697 | baseParams = { | |
698 | server: servers[1], | |
699 | emails, | |
700 | socketNotifications: adminNotificationsServer2, | |
701 | token: servers[1].accessToken | |
702 | } | |
703 | }) | |
704 | ||
705 | it('Should not send a notification if transcoding is not enabled', async function () { | |
706 | this.timeout(10000) | |
707 | ||
708 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | |
709 | await waitJobs(servers) | |
710 | ||
711 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | |
712 | }) | |
713 | ||
714 | it('Should not send a notification if the wait transcoding is false', async function () { | |
715 | this.timeout(50000) | |
716 | ||
717 | await uploadVideoByRemoteAccount(servers, { waitTranscoding: false }) | |
718 | await waitJobs(servers) | |
719 | ||
720 | const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) | |
721 | if (notification) { | |
722 | expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) | |
723 | } | |
724 | }) | |
725 | ||
726 | it('Should send a notification even if the video is not transcoded in other resolutions', async function () { | |
727 | this.timeout(50000) | |
728 | ||
729 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) | |
730 | await waitJobs(servers) | |
731 | ||
732 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | |
733 | }) | |
734 | ||
735 | it('Should send a notification with a transcoded video', async function () { | |
736 | this.timeout(50000) | |
737 | ||
738 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true }) | |
739 | await waitJobs(servers) | |
740 | ||
741 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | |
742 | }) | |
743 | ||
744 | it('Should send a notification when an imported video is transcoded', async function () { | |
745 | this.timeout(50000) | |
746 | ||
747 | const name = 'video import ' + uuidv4() | |
748 | ||
749 | const attributes = { | |
750 | name, | |
751 | channelId, | |
752 | privacy: VideoPrivacy.PUBLIC, | |
753 | targetUrl: getYoutubeVideoUrl(), | |
754 | waitTranscoding: true | |
755 | } | |
756 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
757 | const uuid = res.body.video.uuid | |
758 | ||
759 | await waitJobs(servers) | |
760 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | |
761 | }) | |
762 | ||
763 | it('Should send a notification when the scheduled update has been proceeded', async function () { | |
764 | this.timeout(70000) | |
765 | ||
766 | // In 2 seconds | |
767 | let updateAt = new Date(new Date().getTime() + 2000) | |
768 | ||
769 | const data = { | |
770 | privacy: VideoPrivacy.PRIVATE, | |
771 | scheduleUpdate: { | |
772 | updateAt: updateAt.toISOString(), | |
773 | privacy: VideoPrivacy.PUBLIC | |
774 | } | |
775 | } | |
776 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | |
777 | ||
778 | await wait(6000) | |
779 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | |
780 | }) | |
781 | ||
782 | it('Should not send a notification before the video is published', async function () { | |
783 | this.timeout(20000) | |
784 | ||
785 | let updateAt = new Date(new Date().getTime() + 1000000) | |
786 | ||
787 | const data = { | |
788 | privacy: VideoPrivacy.PRIVATE, | |
789 | scheduleUpdate: { | |
790 | updateAt: updateAt.toISOString(), | |
791 | privacy: VideoPrivacy.PUBLIC | |
792 | } | |
793 | } | |
794 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | |
795 | ||
796 | await wait(6000) | |
797 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | |
798 | }) | |
799 | }) | |
800 | ||
801 | describe('My video is imported', function () { | |
802 | let baseParams: CheckerBaseParams | |
803 | ||
804 | before(() => { | |
805 | baseParams = { | |
806 | server: servers[0], | |
807 | emails, | |
808 | socketNotifications: adminNotifications, | |
809 | token: servers[0].accessToken | |
810 | } | |
811 | }) | |
812 | ||
813 | it('Should send a notification when the video import failed', async function () { | |
814 | this.timeout(70000) | |
815 | ||
816 | const name = 'video import ' + uuidv4() | |
817 | ||
818 | const attributes = { | |
819 | name, | |
820 | channelId, | |
821 | privacy: VideoPrivacy.PRIVATE, | |
822 | targetUrl: getBadVideoUrl() | |
823 | } | |
824 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
825 | const uuid = res.body.video.uuid | |
826 | ||
827 | await waitJobs(servers) | |
828 | await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') | |
829 | }) | |
830 | ||
831 | it('Should send a notification when the video import succeeded', async function () { | |
832 | this.timeout(70000) | |
833 | ||
834 | const name = 'video import ' + uuidv4() | |
835 | ||
836 | const attributes = { | |
837 | name, | |
838 | channelId, | |
839 | privacy: VideoPrivacy.PRIVATE, | |
840 | targetUrl: getYoutubeVideoUrl() | |
841 | } | |
842 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
843 | const uuid = res.body.video.uuid | |
844 | ||
845 | await waitJobs(servers) | |
846 | await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence') | |
847 | }) | |
848 | }) | |
849 | ||
850 | describe('New registration', function () { | |
851 | let baseParams: CheckerBaseParams | |
852 | ||
853 | before(() => { | |
854 | baseParams = { | |
855 | server: servers[0], | |
856 | emails, | |
857 | socketNotifications: adminNotifications, | |
858 | token: servers[0].accessToken | |
859 | } | |
860 | }) | |
861 | ||
862 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | |
863 | this.timeout(10000) | |
864 | ||
865 | await registerUser(servers[0].url, 'user_45', 'password') | |
866 | ||
867 | await waitJobs(servers) | |
868 | ||
869 | await checkUserRegistered(baseParams, 'user_45', 'presence') | |
870 | ||
871 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | |
872 | await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') | |
873 | }) | |
874 | }) | |
875 | ||
876 | describe('New instance follower', function () { | |
877 | let baseParams: CheckerBaseParams | |
878 | ||
879 | before(async () => { | |
880 | baseParams = { | |
881 | server: servers[0], | |
882 | emails, | |
883 | socketNotifications: adminNotifications, | |
884 | token: servers[0].accessToken | |
885 | } | |
886 | }) | |
887 | ||
888 | it('Should send a notification only to admin when there is a new instance follower', async function () { | |
889 | this.timeout(20000) | |
890 | ||
891 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | |
892 | ||
893 | await waitJobs(servers) | |
894 | ||
895 | await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') | |
896 | ||
897 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | |
898 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') | |
899 | }) | |
900 | }) | |
901 | ||
902 | describe('New actor follow', function () { | |
903 | let baseParams: CheckerBaseParams | |
904 | let myChannelName = 'super channel name' | |
905 | let myUserName = 'super user name' | |
906 | ||
907 | before(async () => { | |
908 | baseParams = { | |
909 | server: servers[0], | |
910 | emails, | |
911 | socketNotifications: userNotifications, | |
912 | token: userAccessToken | |
913 | } | |
914 | ||
915 | await updateMyUser({ | |
916 | url: servers[0].url, | |
917 | accessToken: servers[0].accessToken, | |
918 | displayName: 'super root name' | |
919 | }) | |
920 | ||
921 | await updateMyUser({ | |
922 | url: servers[0].url, | |
923 | accessToken: userAccessToken, | |
924 | displayName: myUserName | |
925 | }) | |
926 | ||
927 | await updateMyUser({ | |
928 | url: servers[1].url, | |
929 | accessToken: servers[1].accessToken, | |
930 | displayName: 'super root 2 name' | |
931 | }) | |
932 | ||
933 | await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) | |
934 | }) | |
935 | ||
936 | it('Should notify when a local channel is following one of our channel', async function () { | |
937 | this.timeout(10000) | |
938 | ||
939 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
940 | await waitJobs(servers) | |
941 | ||
942 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') | |
943 | ||
944 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
945 | }) | |
946 | ||
947 | it('Should notify when a remote channel is following one of our channel', async function () { | |
948 | this.timeout(10000) | |
949 | ||
950 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
951 | await waitJobs(servers) | |
952 | ||
953 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') | |
954 | ||
955 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
956 | }) | |
957 | ||
958 | it('Should notify when a local account is following one of our channel', async function () { | |
959 | this.timeout(10000) | |
960 | ||
961 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port) | |
962 | ||
963 | await waitJobs(servers) | |
964 | ||
965 | await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence') | |
966 | }) | |
967 | ||
968 | it('Should notify when a remote account is following one of our channel', async function () { | |
969 | this.timeout(10000) | |
970 | ||
971 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port) | |
972 | ||
973 | await waitJobs(servers) | |
974 | ||
975 | await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence') | |
976 | }) | |
977 | }) | |
978 | ||
979 | describe('Video-related notifications when video auto-blacklist is enabled', function () { | |
980 | let userBaseParams: CheckerBaseParams | |
981 | let adminBaseParamsServer1: CheckerBaseParams | |
982 | let adminBaseParamsServer2: CheckerBaseParams | |
983 | let videoUUID: string | |
984 | let videoName: string | |
985 | let currentCustomConfig: CustomConfig | |
986 | ||
987 | before(async () => { | |
988 | ||
989 | adminBaseParamsServer1 = { | |
990 | server: servers[0], | |
991 | emails, | |
992 | socketNotifications: adminNotifications, | |
993 | token: servers[0].accessToken | |
994 | } | |
995 | ||
996 | adminBaseParamsServer2 = { | |
997 | server: servers[1], | |
998 | emails, | |
999 | socketNotifications: adminNotificationsServer2, | |
1000 | token: servers[1].accessToken | |
1001 | } | |
1002 | ||
1003 | userBaseParams = { | |
1004 | server: servers[0], | |
1005 | emails, | |
1006 | socketNotifications: userNotifications, | |
1007 | token: userAccessToken | |
1008 | } | |
1009 | ||
1010 | const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) | |
1011 | currentCustomConfig = resCustomConfig.body | |
1012 | const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { | |
1013 | autoBlacklist: { | |
1014 | videos: { | |
1015 | ofUsers: { | |
1016 | enabled: true | |
1017 | } | |
1018 | } | |
1019 | } | |
1020 | }) | |
1021 | // enable transcoding otherwise own publish notification after transcoding not expected | |
1022 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | |
1023 | await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) | |
1024 | ||
1025 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
1026 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
1027 | ||
1028 | }) | |
1029 | ||
1030 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | |
1031 | this.timeout(20000) | |
1032 | ||
1033 | videoName = 'video with auto-blacklist ' + uuidv4() | |
1034 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) | |
1035 | videoUUID = resVideo.body.video.uuid | |
1036 | ||
1037 | await waitJobs(servers) | |
1038 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | |
1039 | }) | |
1040 | ||
1041 | it('Should not send video publish notification if auto-blacklisted', async function () { | |
1042 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | |
1043 | }) | |
1044 | ||
1045 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | |
1046 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | |
1047 | }) | |
1048 | ||
1049 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | |
1050 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | |
1051 | }) | |
1052 | ||
1053 | it('Should send video published and unblacklist after video unblacklisted', async function () { | |
1054 | this.timeout(20000) | |
1055 | ||
1056 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) | |
1057 | ||
1058 | await waitJobs(servers) | |
1059 | ||
1060 | // FIXME: Can't test as two notifications sent to same user and util only checks last one | |
1061 | // One notification might be better anyways | |
1062 | // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') | |
1063 | // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') | |
1064 | }) | |
1065 | ||
1066 | it('Should send a local user subscription notification after removed from blacklist', async function () { | |
1067 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | |
1068 | }) | |
1069 | ||
1070 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | |
1071 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | |
1072 | }) | |
1073 | ||
1074 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | |
1075 | this.timeout(20000) | |
1076 | ||
1077 | let updateAt = new Date(new Date().getTime() + 1000000) | |
1078 | ||
1079 | const name = 'video with auto-blacklist and future schedule ' + uuidv4() | |
1080 | ||
1081 | const data = { | |
1082 | name, | |
1083 | privacy: VideoPrivacy.PRIVATE, | |
1084 | scheduleUpdate: { | |
1085 | updateAt: updateAt.toISOString(), | |
1086 | privacy: VideoPrivacy.PUBLIC | |
1087 | } | |
1088 | } | |
1089 | ||
1090 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | |
1091 | const uuid = resVideo.body.video.uuid | |
1092 | ||
1093 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
1094 | ||
1095 | await waitJobs(servers) | |
1096 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | |
1097 | ||
1098 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | |
1099 | // One notification might be better anyways | |
1100 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
1101 | ||
1102 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | |
1103 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | |
1104 | }) | |
1105 | ||
1106 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | |
1107 | this.timeout(20000) | |
1108 | ||
1109 | // In 2 seconds | |
1110 | let updateAt = new Date(new Date().getTime() + 2000) | |
1111 | ||
1112 | const name = 'video with schedule done and still auto-blacklisted ' + uuidv4() | |
1113 | ||
1114 | const data = { | |
1115 | name, | |
1116 | privacy: VideoPrivacy.PRIVATE, | |
1117 | scheduleUpdate: { | |
1118 | updateAt: updateAt.toISOString(), | |
1119 | privacy: VideoPrivacy.PUBLIC | |
1120 | } | |
1121 | } | |
1122 | ||
1123 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | |
1124 | const uuid = resVideo.body.video.uuid | |
1125 | ||
1126 | await wait(6000) | |
1127 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
1128 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | |
1129 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | |
1130 | }) | |
1131 | ||
1132 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | |
1133 | this.timeout(20000) | |
1134 | ||
1135 | const name = 'video without auto-blacklist ' + uuidv4() | |
1136 | ||
1137 | // admin with blacklist right will not be auto-blacklisted | |
1138 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) | |
1139 | const uuid = resVideo.body.video.uuid | |
1140 | ||
1141 | await waitJobs(servers) | |
1142 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | |
1143 | }) | |
1144 | ||
1145 | after(async () => { | |
1146 | await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) | |
1147 | ||
1148 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
1149 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
1150 | }) | |
1151 | }) | |
1152 | ||
1153 | describe('Mark as read', function () { | |
1154 | it('Should mark as read some notifications', async function () { | |
1155 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) | |
1156 | const ids = res.body.data.map(n => n.id) | |
1157 | ||
1158 | await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids) | |
1159 | }) | |
1160 | ||
1161 | it('Should have the notifications marked as read', async function () { | |
1162 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10) | |
1163 | ||
1164 | const notifications = res.body.data as UserNotification[] | |
1165 | expect(notifications[ 0 ].read).to.be.false | |
1166 | expect(notifications[ 1 ].read).to.be.false | |
1167 | expect(notifications[ 2 ].read).to.be.true | |
1168 | expect(notifications[ 3 ].read).to.be.true | |
1169 | expect(notifications[ 4 ].read).to.be.true | |
1170 | expect(notifications[ 5 ].read).to.be.false | |
1171 | }) | |
1172 | ||
1173 | it('Should only list read notifications', async function () { | |
1174 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false) | |
1175 | ||
1176 | const notifications = res.body.data as UserNotification[] | |
1177 | for (const notification of notifications) { | |
1178 | expect(notification.read).to.be.true | |
1179 | } | |
1180 | }) | |
1181 | ||
1182 | it('Should only list unread notifications', async function () { | |
1183 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true) | |
1184 | ||
1185 | const notifications = res.body.data as UserNotification[] | |
1186 | for (const notification of notifications) { | |
1187 | expect(notification.read).to.be.false | |
1188 | } | |
1189 | }) | |
1190 | ||
1191 | it('Should mark as read all notifications', async function () { | |
1192 | await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken) | |
1193 | ||
1194 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true) | |
1195 | ||
1196 | expect(res.body.total).to.equal(0) | |
1197 | expect(res.body.data).to.have.lengthOf(0) | |
1198 | }) | |
1199 | }) | |
1200 | ||
1201 | describe('Notification settings', function () { | |
1202 | let baseParams: CheckerBaseParams | |
1203 | ||
1204 | before(() => { | |
1205 | baseParams = { | |
1206 | server: servers[0], | |
1207 | emails, | |
1208 | socketNotifications: userNotifications, | |
1209 | token: userAccessToken | |
1210 | } | |
1211 | }) | |
1212 | ||
1213 | it('Should not have notifications', async function () { | |
1214 | this.timeout(20000) | |
1215 | ||
1216 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | |
1217 | newVideoFromSubscription: UserNotificationSettingValue.NONE | |
1218 | })) | |
1219 | ||
1220 | { | |
1221 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
1222 | const info = res.body as User | |
1223 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) | |
1224 | } | |
1225 | ||
1226 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | |
1227 | ||
1228 | const check = { web: true, mail: true } | |
1229 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | |
1230 | }) | |
1231 | ||
1232 | it('Should only have web notifications', async function () { | |
1233 | this.timeout(20000) | |
1234 | ||
1235 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | |
1236 | newVideoFromSubscription: UserNotificationSettingValue.WEB | |
1237 | })) | |
1238 | ||
1239 | { | |
1240 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
1241 | const info = res.body as User | |
1242 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) | |
1243 | } | |
1244 | ||
1245 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | |
1246 | ||
1247 | { | |
1248 | const check = { mail: true, web: false } | |
1249 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | |
1250 | } | |
1251 | ||
1252 | { | |
1253 | const check = { mail: false, web: true } | |
1254 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') | |
1255 | } | |
1256 | }) | |
1257 | ||
1258 | it('Should only have mail notifications', async function () { | |
1259 | this.timeout(20000) | |
1260 | ||
1261 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | |
1262 | newVideoFromSubscription: UserNotificationSettingValue.EMAIL | |
1263 | })) | |
1264 | ||
1265 | { | |
1266 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
1267 | const info = res.body as User | |
1268 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) | |
1269 | } | |
1270 | ||
1271 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | |
1272 | ||
1273 | { | |
1274 | const check = { mail: false, web: true } | |
1275 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | |
1276 | } | |
1277 | ||
1278 | { | |
1279 | const check = { mail: true, web: false } | |
1280 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') | |
1281 | } | |
1282 | }) | |
1283 | ||
1284 | it('Should have email and web notifications', async function () { | |
1285 | this.timeout(20000) | |
1286 | ||
1287 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | |
1288 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | |
1289 | })) | |
1290 | ||
1291 | { | |
1292 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
1293 | const info = res.body as User | |
1294 | expect(info.notificationSettings.newVideoFromSubscription).to.equal( | |
1295 | UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | |
1296 | ) | |
1297 | } | |
1298 | ||
1299 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | |
1300 | ||
1301 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | |
1302 | }) | |
1303 | }) | |
1304 | ||
1305 | after(async function () { | |
1306 | MockSmtpServer.Instance.kill() | |
1307 | ||
1308 | await cleanupTests(servers) | |
1309 | }) | |
1310 | }) |