1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
6 checkMyVideoImportIsFinished,
8 checkNewVideoFromSubscription,
10 checkVideoStudioEditionIsFinished,
13 prepareNotificationsTest,
14 uploadRandomVideoOnServers
15 } from '@server/tests/shared'
16 import { wait } from '@shared/core-utils'
17 import { buildUUID } from '@shared/extra-utils'
18 import { UserNotification, UserNotificationType, VideoPrivacy, VideoStudioTask } from '@shared/models'
19 import { cleanupTests, findExternalSavedVideo, PeerTubeServer, stopFfmpeg, waitJobs } from '@shared/server-commands'
21 const expect = chai.expect
23 describe('Test user notifications', function () {
24 let servers: PeerTubeServer[] = []
25 let userAccessToken: string
27 let userNotifications: UserNotification[] = []
28 let adminNotifications: UserNotification[] = []
29 let adminNotificationsServer2: UserNotification[] = []
30 let emails: object[] = []
34 before(async function () {
37 const res = await prepareNotificationsTest(3)
39 userAccessToken = res.userAccessToken
41 userNotifications = res.userNotifications
42 adminNotifications = res.adminNotifications
43 adminNotificationsServer2 = res.adminNotificationsServer2
44 channelId = res.channelId
47 describe('New video from my subscription notification', function () {
48 let baseParams: CheckerBaseParams
54 socketNotifications: userNotifications,
55 token: userAccessToken
59 it('Should not send notifications if the user does not follow the video publisher', async function () {
62 await uploadRandomVideoOnServers(servers, 1)
64 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
65 expect(notification).to.be.undefined
67 expect(emails).to.have.lengthOf(0)
68 expect(userNotifications).to.have.lengthOf(0)
71 it('Should send a new video notification if the user follows the local video publisher', async function () {
74 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
75 await waitJobs(servers)
77 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
78 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
81 it('Should send a new video notification from a remote account', async function () {
82 this.timeout(150000) // Server 2 has transcoding enabled
84 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
85 await waitJobs(servers)
87 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
88 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
91 it('Should send a new video notification on a scheduled publication', async function () {
95 const updateAt = new Date(new Date().getTime() + 2000)
98 privacy: VideoPrivacy.PRIVATE,
100 updateAt: updateAt.toISOString(),
101 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
104 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
107 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
110 it('Should send a new video notification on a remote scheduled publication', async function () {
114 const updateAt = new Date(new Date().getTime() + 2000)
117 privacy: VideoPrivacy.PRIVATE,
119 updateAt: updateAt.toISOString(),
120 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
123 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
124 await waitJobs(servers)
127 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
130 it('Should not send a notification before the video is published', async function () {
133 const updateAt = new Date(new Date().getTime() + 1000000)
136 privacy: VideoPrivacy.PRIVATE,
138 updateAt: updateAt.toISOString(),
139 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
142 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
145 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
148 it('Should send a new video notification when a video becomes public', async function () {
151 const data = { privacy: VideoPrivacy.PRIVATE }
152 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
154 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
156 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
158 await waitJobs(servers)
159 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
162 it('Should send a new video notification when a remote video becomes public', async function () {
165 const data = { privacy: VideoPrivacy.PRIVATE }
166 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
168 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
170 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
172 await waitJobs(servers)
173 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
176 it('Should not send a new video notification when a video becomes unlisted', async function () {
179 const data = { privacy: VideoPrivacy.PRIVATE }
180 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
182 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
184 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
187 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
190 const data = { privacy: VideoPrivacy.PRIVATE }
191 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
193 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
195 await waitJobs(servers)
196 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
199 it('Should send a new video notification after a video import', async function () {
202 const name = 'video import ' + buildUUID()
207 privacy: VideoPrivacy.PUBLIC,
208 targetUrl: FIXTURE_URLS.goodVideo
210 const { video } = await servers[0].imports.importVideo({ attributes })
212 await waitJobs(servers)
214 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
218 describe('My video is published', function () {
219 let baseParams: CheckerBaseParams
225 socketNotifications: adminNotificationsServer2,
226 token: servers[1].accessToken
230 it('Should not send a notification if transcoding is not enabled', async function () {
233 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
234 await waitJobs(servers)
236 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
239 it('Should not send a notification if the wait transcoding is false', async function () {
240 this.timeout(100_000)
242 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
243 await waitJobs(servers)
245 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
247 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
251 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
254 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
255 await waitJobs(servers)
257 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
260 it('Should send a notification with a transcoded video', async function () {
263 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
264 await waitJobs(servers)
266 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
269 it('Should send a notification when an imported video is transcoded', async function () {
272 const name = 'video import ' + buildUUID()
277 privacy: VideoPrivacy.PUBLIC,
278 targetUrl: FIXTURE_URLS.goodVideo,
279 waitTranscoding: true
281 const { video } = await servers[1].imports.importVideo({ attributes })
283 await waitJobs(servers)
284 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
287 it('Should send a notification when the scheduled update has been proceeded', async function () {
291 const updateAt = new Date(new Date().getTime() + 2000)
294 privacy: VideoPrivacy.PRIVATE,
296 updateAt: updateAt.toISOString(),
297 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
300 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
303 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
306 it('Should not send a notification before the video is published', async function () {
309 const updateAt = new Date(new Date().getTime() + 1000000)
312 privacy: VideoPrivacy.PRIVATE,
314 updateAt: updateAt.toISOString(),
315 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
318 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
321 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
325 describe('My live replay is published', function () {
327 let baseParams: CheckerBaseParams
333 socketNotifications: adminNotificationsServer2,
334 token: servers[1].accessToken
338 it('Should send a notification is a live replay of a non permanent live is published', async function () {
341 const { shortUUID } = await servers[1].live.create({
343 name: 'non permanent live',
344 privacy: VideoPrivacy.PUBLIC,
345 channelId: servers[1].store.channel.id,
351 const ffmpegCommand = await servers[1].live.sendRTMPStreamInVideo({ videoId: shortUUID })
353 await waitJobs(servers)
354 await servers[1].live.waitUntilPublished({ videoId: shortUUID })
356 await stopFfmpeg(ffmpegCommand)
357 await servers[1].live.waitUntilReplacedByReplay({ videoId: shortUUID })
359 await waitJobs(servers)
360 await checkVideoIsPublished({ ...baseParams, videoName: 'non permanent live', shortUUID, checkType: 'presence' })
363 it('Should send a notification is a live replay of a permanent live is published', async function () {
366 const { shortUUID } = await servers[1].live.create({
368 name: 'permanent live',
369 privacy: VideoPrivacy.PUBLIC,
370 channelId: servers[1].store.channel.id,
376 const ffmpegCommand = await servers[1].live.sendRTMPStreamInVideo({ videoId: shortUUID })
378 await waitJobs(servers)
379 await servers[1].live.waitUntilPublished({ videoId: shortUUID })
381 const liveDetails = await servers[1].videos.get({ id: shortUUID })
383 await stopFfmpeg(ffmpegCommand)
385 await servers[1].live.waitUntilWaiting({ videoId: shortUUID })
386 await waitJobs(servers)
388 const video = await findExternalSavedVideo(servers[1], liveDetails)
389 expect(video).to.exist
391 await checkVideoIsPublished({ ...baseParams, videoName: video.name, shortUUID: video.shortUUID, checkType: 'presence' })
395 describe('Video studio', function () {
396 let baseParams: CheckerBaseParams
402 socketNotifications: adminNotificationsServer2,
403 token: servers[1].accessToken
407 it('Should send a notification after studio edition', async function () {
410 const { name, shortUUID, id } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
412 await waitJobs(servers)
413 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
415 const tasks: VideoStudioTask[] = [
424 await servers[1].videoStudio.createEditionTasks({ videoId: id, tasks })
425 await waitJobs(servers)
427 await checkVideoStudioEditionIsFinished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
431 describe('My video is imported', function () {
432 let baseParams: CheckerBaseParams
438 socketNotifications: adminNotifications,
439 token: servers[0].accessToken
443 it('Should send a notification when the video import failed', async function () {
446 const name = 'video import ' + buildUUID()
451 privacy: VideoPrivacy.PRIVATE,
452 targetUrl: FIXTURE_URLS.badVideo
454 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
456 await waitJobs(servers)
458 const url = FIXTURE_URLS.badVideo
459 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
462 it('Should send a notification when the video import succeeded', async function () {
465 const name = 'video import ' + buildUUID()
470 privacy: VideoPrivacy.PRIVATE,
471 targetUrl: FIXTURE_URLS.goodVideo
473 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
475 await waitJobs(servers)
477 const url = FIXTURE_URLS.goodVideo
478 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
482 describe('New actor follow', function () {
483 let baseParams: CheckerBaseParams
484 const myChannelName = 'super channel name'
485 const myUserName = 'super user name'
491 socketNotifications: userNotifications,
492 token: userAccessToken
495 await servers[0].users.updateMe({ displayName: 'super root name' })
497 await servers[0].users.updateMe({
498 token: userAccessToken,
499 displayName: myUserName
502 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
504 await servers[0].channels.update({
505 token: userAccessToken,
506 channelName: 'user_1_channel',
507 attributes: { displayName: myChannelName }
511 it('Should notify when a local channel is following one of our channel', async function () {
514 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
515 await waitJobs(servers)
517 await checkNewActorFollow({
519 followType: 'channel',
520 followerName: 'root',
521 followerDisplayName: 'super root name',
522 followingDisplayName: myChannelName,
523 checkType: 'presence'
526 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
529 it('Should notify when a remote channel is following one of our channel', async function () {
532 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
533 await waitJobs(servers)
535 await checkNewActorFollow({
537 followType: 'channel',
538 followerName: 'root',
539 followerDisplayName: 'super root 2 name',
540 followingDisplayName: myChannelName,
541 checkType: 'presence'
544 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
547 // PeerTube does not support account -> account follows
548 // it('Should notify when a local account is following one of our channel', async function () {
549 // this.timeout(50000)
551 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
553 // await waitJobs(servers)
555 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
558 // it('Should notify when a remote account is following one of our channel', async function () {
559 // this.timeout(50000)
561 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
563 // await waitJobs(servers)
565 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
569 after(async function () {
570 MockSmtpServer.Instance.kill()
572 await cleanupTests(servers)