1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 checkMyVideoImportIsFinished,
9 checkNewVideoFromSubscription,
10 checkVideoIsPublished,
13 prepareNotificationsTest,
14 uploadRandomVideoOnServers
15 } from '@server/tests/shared'
16 import { buildUUID, wait } from '@shared/core-utils'
17 import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
18 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
20 const expect = chai.expect
22 describe('Test user notifications', function () {
23 let servers: PeerTubeServer[] = []
24 let userAccessToken: string
25 let userNotifications: UserNotification[] = []
26 let adminNotifications: UserNotification[] = []
27 let adminNotificationsServer2: UserNotification[] = []
28 let emails: object[] = []
31 before(async function () {
34 const res = await prepareNotificationsTest(3)
36 userAccessToken = res.userAccessToken
38 userNotifications = res.userNotifications
39 adminNotifications = res.adminNotifications
40 adminNotificationsServer2 = res.adminNotificationsServer2
41 channelId = res.channelId
44 describe('New video from my subscription notification', function () {
45 let baseParams: CheckerBaseParams
51 socketNotifications: userNotifications,
52 token: userAccessToken
56 it('Should not send notifications if the user does not follow the video publisher', async function () {
59 await uploadRandomVideoOnServers(servers, 1)
61 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
62 expect(notification).to.be.undefined
64 expect(emails).to.have.lengthOf(0)
65 expect(userNotifications).to.have.lengthOf(0)
68 it('Should send a new video notification if the user follows the local video publisher', async function () {
71 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
72 await waitJobs(servers)
74 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
75 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
78 it('Should send a new video notification from a remote account', async function () {
79 this.timeout(150000) // Server 2 has transcoding enabled
81 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
82 await waitJobs(servers)
84 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
85 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
88 it('Should send a new video notification on a scheduled publication', async function () {
92 const updateAt = new Date(new Date().getTime() + 2000)
95 privacy: VideoPrivacy.PRIVATE,
97 updateAt: updateAt.toISOString(),
98 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
101 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
104 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
107 it('Should send a new video notification on a remote scheduled publication', async function () {
111 const updateAt = new Date(new Date().getTime() + 2000)
114 privacy: VideoPrivacy.PRIVATE,
116 updateAt: updateAt.toISOString(),
117 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
120 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
121 await waitJobs(servers)
124 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
127 it('Should not send a notification before the video is published', async function () {
130 const updateAt = new Date(new Date().getTime() + 1000000)
133 privacy: VideoPrivacy.PRIVATE,
135 updateAt: updateAt.toISOString(),
136 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
139 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
142 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
145 it('Should send a new video notification when a video becomes public', async function () {
148 const data = { privacy: VideoPrivacy.PRIVATE }
149 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
151 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
153 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
155 await waitJobs(servers)
156 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
159 it('Should send a new video notification when a remote video becomes public', async function () {
162 const data = { privacy: VideoPrivacy.PRIVATE }
163 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
165 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
167 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
169 await waitJobs(servers)
170 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
173 it('Should not send a new video notification when a video becomes unlisted', async function () {
176 const data = { privacy: VideoPrivacy.PRIVATE }
177 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
179 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
181 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
184 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
187 const data = { privacy: VideoPrivacy.PRIVATE }
188 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
190 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
192 await waitJobs(servers)
193 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
196 it('Should send a new video notification after a video import', async function () {
199 const name = 'video import ' + buildUUID()
204 privacy: VideoPrivacy.PUBLIC,
205 targetUrl: FIXTURE_URLS.goodVideo
207 const { video } = await servers[0].imports.importVideo({ attributes })
209 await waitJobs(servers)
211 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
215 describe('My video is published', function () {
216 let baseParams: CheckerBaseParams
222 socketNotifications: adminNotificationsServer2,
223 token: servers[1].accessToken
227 it('Should not send a notification if transcoding is not enabled', async function () {
230 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
231 await waitJobs(servers)
233 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
236 it('Should not send a notification if the wait transcoding is false', async function () {
237 this.timeout(100_000)
239 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
240 await waitJobs(servers)
242 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
244 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
248 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
251 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
252 await waitJobs(servers)
254 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
257 it('Should send a notification with a transcoded video', async function () {
260 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
261 await waitJobs(servers)
263 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
266 it('Should send a notification when an imported video is transcoded', async function () {
269 const name = 'video import ' + buildUUID()
274 privacy: VideoPrivacy.PUBLIC,
275 targetUrl: FIXTURE_URLS.goodVideo,
276 waitTranscoding: true
278 const { video } = await servers[1].imports.importVideo({ attributes })
280 await waitJobs(servers)
281 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
284 it('Should send a notification when the scheduled update has been proceeded', async function () {
288 const updateAt = new Date(new Date().getTime() + 2000)
291 privacy: VideoPrivacy.PRIVATE,
293 updateAt: updateAt.toISOString(),
294 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
297 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
300 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
303 it('Should not send a notification before the video is published', async function () {
306 const updateAt = new Date(new Date().getTime() + 1000000)
309 privacy: VideoPrivacy.PRIVATE,
311 updateAt: updateAt.toISOString(),
312 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
315 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
318 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
322 describe('My video is imported', function () {
323 let baseParams: CheckerBaseParams
329 socketNotifications: adminNotifications,
330 token: servers[0].accessToken
334 it('Should send a notification when the video import failed', async function () {
337 const name = 'video import ' + buildUUID()
342 privacy: VideoPrivacy.PRIVATE,
343 targetUrl: FIXTURE_URLS.badVideo
345 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
347 await waitJobs(servers)
349 const url = FIXTURE_URLS.badVideo
350 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
353 it('Should send a notification when the video import succeeded', async function () {
356 const name = 'video import ' + buildUUID()
361 privacy: VideoPrivacy.PRIVATE,
362 targetUrl: FIXTURE_URLS.goodVideo
364 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
366 await waitJobs(servers)
368 const url = FIXTURE_URLS.goodVideo
369 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
373 describe('New actor follow', function () {
374 let baseParams: CheckerBaseParams
375 const myChannelName = 'super channel name'
376 const myUserName = 'super user name'
382 socketNotifications: userNotifications,
383 token: userAccessToken
386 await servers[0].users.updateMe({ displayName: 'super root name' })
388 await servers[0].users.updateMe({
389 token: userAccessToken,
390 displayName: myUserName
393 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
395 await servers[0].channels.update({
396 token: userAccessToken,
397 channelName: 'user_1_channel',
398 attributes: { displayName: myChannelName }
402 it('Should notify when a local channel is following one of our channel', async function () {
405 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
406 await waitJobs(servers)
408 await checkNewActorFollow({
410 followType: 'channel',
411 followerName: 'root',
412 followerDisplayName: 'super root name',
413 followingDisplayName: myChannelName,
414 checkType: 'presence'
417 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
420 it('Should notify when a remote channel is following one of our channel', async function () {
423 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
424 await waitJobs(servers)
426 await checkNewActorFollow({
428 followType: 'channel',
429 followerName: 'root',
430 followerDisplayName: 'super root 2 name',
431 followingDisplayName: myChannelName,
432 checkType: 'presence'
435 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
438 // PeerTube does not support accout -> account follows
439 // it('Should notify when a local account is following one of our channel', async function () {
440 // this.timeout(50000)
442 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
444 // await waitJobs(servers)
446 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
449 // it('Should notify when a remote account is following one of our channel', async function () {
450 // this.timeout(50000)
452 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
454 // await waitJobs(servers)
456 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
460 after(async function () {
461 MockSmtpServer.Instance.kill()
463 await cleanupTests(servers)