1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 checkMyVideoImportIsFinished,
9 checkNewVideoFromSubscription,
10 checkVideoStudioEditionIsFinished,
11 checkVideoIsPublished,
14 prepareNotificationsTest,
15 uploadRandomVideoOnServers
16 } from '@server/tests/shared'
17 import { wait } from '@shared/core-utils'
18 import { buildUUID } from '@shared/extra-utils'
19 import { UserNotification, UserNotificationType, VideoStudioTask, VideoPrivacy } from '@shared/models'
20 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
22 const expect = chai.expect
24 describe('Test user notifications', function () {
25 let servers: PeerTubeServer[] = []
26 let userAccessToken: string
28 let userNotifications: UserNotification[] = []
29 let adminNotifications: UserNotification[] = []
30 let adminNotificationsServer2: UserNotification[] = []
31 let emails: object[] = []
35 before(async function () {
38 const res = await prepareNotificationsTest(3)
40 userAccessToken = res.userAccessToken
42 userNotifications = res.userNotifications
43 adminNotifications = res.adminNotifications
44 adminNotificationsServer2 = res.adminNotificationsServer2
45 channelId = res.channelId
48 describe('New video from my subscription notification', function () {
49 let baseParams: CheckerBaseParams
55 socketNotifications: userNotifications,
56 token: userAccessToken
60 it('Should not send notifications if the user does not follow the video publisher', async function () {
63 await uploadRandomVideoOnServers(servers, 1)
65 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
66 expect(notification).to.be.undefined
68 expect(emails).to.have.lengthOf(0)
69 expect(userNotifications).to.have.lengthOf(0)
72 it('Should send a new video notification if the user follows the local video publisher', async function () {
75 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
76 await waitJobs(servers)
78 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
79 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
82 it('Should send a new video notification from a remote account', async function () {
83 this.timeout(150000) // Server 2 has transcoding enabled
85 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
86 await waitJobs(servers)
88 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
89 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
92 it('Should send a new video notification on a scheduled publication', async function () {
96 const updateAt = new Date(new Date().getTime() + 2000)
99 privacy: VideoPrivacy.PRIVATE,
101 updateAt: updateAt.toISOString(),
102 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
105 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
108 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
111 it('Should send a new video notification on a remote scheduled publication', async function () {
115 const updateAt = new Date(new Date().getTime() + 2000)
118 privacy: VideoPrivacy.PRIVATE,
120 updateAt: updateAt.toISOString(),
121 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
124 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
125 await waitJobs(servers)
128 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
131 it('Should not send a notification before the video is published', async function () {
134 const updateAt = new Date(new Date().getTime() + 1000000)
137 privacy: VideoPrivacy.PRIVATE,
139 updateAt: updateAt.toISOString(),
140 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
143 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
146 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
149 it('Should send a new video notification when a video becomes public', async function () {
152 const data = { privacy: VideoPrivacy.PRIVATE }
153 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
155 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
157 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
159 await waitJobs(servers)
160 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
163 it('Should send a new video notification when a remote video becomes public', async function () {
166 const data = { privacy: VideoPrivacy.PRIVATE }
167 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
169 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
171 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
173 await waitJobs(servers)
174 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
177 it('Should not send a new video notification when a video becomes unlisted', async function () {
180 const data = { privacy: VideoPrivacy.PRIVATE }
181 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
183 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
185 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
188 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
191 const data = { privacy: VideoPrivacy.PRIVATE }
192 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
194 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
196 await waitJobs(servers)
197 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
200 it('Should send a new video notification after a video import', async function () {
203 const name = 'video import ' + buildUUID()
208 privacy: VideoPrivacy.PUBLIC,
209 targetUrl: FIXTURE_URLS.goodVideo
211 const { video } = await servers[0].imports.importVideo({ attributes })
213 await waitJobs(servers)
215 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
219 describe('My video is published', function () {
220 let baseParams: CheckerBaseParams
226 socketNotifications: adminNotificationsServer2,
227 token: servers[1].accessToken
231 it('Should not send a notification if transcoding is not enabled', async function () {
234 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
235 await waitJobs(servers)
237 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
240 it('Should not send a notification if the wait transcoding is false', async function () {
241 this.timeout(100_000)
243 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
244 await waitJobs(servers)
246 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
248 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
252 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
255 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
256 await waitJobs(servers)
258 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
261 it('Should send a notification with a transcoded video', async function () {
264 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
265 await waitJobs(servers)
267 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
270 it('Should send a notification when an imported video is transcoded', async function () {
273 const name = 'video import ' + buildUUID()
278 privacy: VideoPrivacy.PUBLIC,
279 targetUrl: FIXTURE_URLS.goodVideo,
280 waitTranscoding: true
282 const { video } = await servers[1].imports.importVideo({ attributes })
284 await waitJobs(servers)
285 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
288 it('Should send a notification when the scheduled update has been proceeded', async function () {
292 const updateAt = new Date(new Date().getTime() + 2000)
295 privacy: VideoPrivacy.PRIVATE,
297 updateAt: updateAt.toISOString(),
298 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
301 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
304 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
307 it('Should not send a notification before the video is published', async function () {
310 const updateAt = new Date(new Date().getTime() + 1000000)
313 privacy: VideoPrivacy.PRIVATE,
315 updateAt: updateAt.toISOString(),
316 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
319 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
322 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
326 describe('Video studio', function () {
327 let baseParams: CheckerBaseParams
333 socketNotifications: adminNotificationsServer2,
334 token: servers[1].accessToken
338 it('Should send a notification after studio edition', async function () {
341 const { name, shortUUID, id } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
343 await waitJobs(servers)
344 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
346 const tasks: VideoStudioTask[] = [
355 await servers[1].videoStudio.createEditionTasks({ videoId: id, tasks })
356 await waitJobs(servers)
358 await checkVideoStudioEditionIsFinished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
362 describe('My video is imported', function () {
363 let baseParams: CheckerBaseParams
369 socketNotifications: adminNotifications,
370 token: servers[0].accessToken
374 it('Should send a notification when the video import failed', async function () {
377 const name = 'video import ' + buildUUID()
382 privacy: VideoPrivacy.PRIVATE,
383 targetUrl: FIXTURE_URLS.badVideo
385 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
387 await waitJobs(servers)
389 const url = FIXTURE_URLS.badVideo
390 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
393 it('Should send a notification when the video import succeeded', async function () {
396 const name = 'video import ' + buildUUID()
401 privacy: VideoPrivacy.PRIVATE,
402 targetUrl: FIXTURE_URLS.goodVideo
404 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
406 await waitJobs(servers)
408 const url = FIXTURE_URLS.goodVideo
409 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
413 describe('New actor follow', function () {
414 let baseParams: CheckerBaseParams
415 const myChannelName = 'super channel name'
416 const myUserName = 'super user name'
422 socketNotifications: userNotifications,
423 token: userAccessToken
426 await servers[0].users.updateMe({ displayName: 'super root name' })
428 await servers[0].users.updateMe({
429 token: userAccessToken,
430 displayName: myUserName
433 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
435 await servers[0].channels.update({
436 token: userAccessToken,
437 channelName: 'user_1_channel',
438 attributes: { displayName: myChannelName }
442 it('Should notify when a local channel is following one of our channel', async function () {
445 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
446 await waitJobs(servers)
448 await checkNewActorFollow({
450 followType: 'channel',
451 followerName: 'root',
452 followerDisplayName: 'super root name',
453 followingDisplayName: myChannelName,
454 checkType: 'presence'
457 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
460 it('Should notify when a remote channel is following one of our channel', async function () {
463 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
464 await waitJobs(servers)
466 await checkNewActorFollow({
468 followType: 'channel',
469 followerName: 'root',
470 followerDisplayName: 'super root 2 name',
471 followingDisplayName: myChannelName,
472 checkType: 'presence'
475 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
478 // PeerTube does not support accout -> account follows
479 // it('Should notify when a local account is following one of our channel', async function () {
480 // this.timeout(50000)
482 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
484 // await waitJobs(servers)
486 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
489 // it('Should notify when a remote account is following one of our channel', async function () {
490 // this.timeout(50000)
492 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
494 // await waitJobs(servers)
496 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
500 after(async function () {
501 MockSmtpServer.Instance.kill()
503 await cleanupTests(servers)