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