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