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 { wait } from '@shared/core-utils'
17 import { buildUUID } from '@shared/extra-utils'
18 import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
19 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
21 const expect = chai.expect
23 describe('Test user notifications', function () {
24 let servers: PeerTubeServer[] = []
25 let userAccessToken: string
26 let userNotifications: UserNotification[] = []
27 let adminNotifications: UserNotification[] = []
28 let adminNotificationsServer2: UserNotification[] = []
29 let emails: object[] = []
32 before(async function () {
35 const res = await prepareNotificationsTest(3)
37 userAccessToken = res.userAccessToken
39 userNotifications = res.userNotifications
40 adminNotifications = res.adminNotifications
41 adminNotificationsServer2 = res.adminNotificationsServer2
42 channelId = res.channelId
45 describe('New video from my subscription notification', function () {
46 let baseParams: CheckerBaseParams
52 socketNotifications: userNotifications,
53 token: userAccessToken
57 it('Should not send notifications if the user does not follow the video publisher', async function () {
60 await uploadRandomVideoOnServers(servers, 1)
62 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
63 expect(notification).to.be.undefined
65 expect(emails).to.have.lengthOf(0)
66 expect(userNotifications).to.have.lengthOf(0)
69 it('Should send a new video notification if the user follows the local video publisher', async function () {
72 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
73 await waitJobs(servers)
75 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
76 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
79 it('Should send a new video notification from a remote account', async function () {
80 this.timeout(150000) // Server 2 has transcoding enabled
82 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
83 await waitJobs(servers)
85 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
86 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
89 it('Should send a new video notification on a scheduled publication', async function () {
93 const updateAt = new Date(new Date().getTime() + 2000)
96 privacy: VideoPrivacy.PRIVATE,
98 updateAt: updateAt.toISOString(),
99 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
102 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
105 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
108 it('Should send a new video notification on a remote scheduled publication', async function () {
112 const updateAt = new Date(new Date().getTime() + 2000)
115 privacy: VideoPrivacy.PRIVATE,
117 updateAt: updateAt.toISOString(),
118 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
121 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
122 await waitJobs(servers)
125 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
128 it('Should not send a notification before the video is published', async function () {
131 const updateAt = new Date(new Date().getTime() + 1000000)
134 privacy: VideoPrivacy.PRIVATE,
136 updateAt: updateAt.toISOString(),
137 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
140 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
143 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
146 it('Should send a new video notification when a video becomes public', async function () {
149 const data = { privacy: VideoPrivacy.PRIVATE }
150 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
152 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
154 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
156 await waitJobs(servers)
157 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
160 it('Should send a new video notification when a remote video becomes public', async function () {
163 const data = { privacy: VideoPrivacy.PRIVATE }
164 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
166 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
168 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
170 await waitJobs(servers)
171 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
174 it('Should not send a new video notification when a video becomes unlisted', async function () {
177 const data = { privacy: VideoPrivacy.PRIVATE }
178 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
180 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
182 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
185 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
188 const data = { privacy: VideoPrivacy.PRIVATE }
189 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
191 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
193 await waitJobs(servers)
194 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
197 it('Should send a new video notification after a video import', async function () {
200 const name = 'video import ' + buildUUID()
205 privacy: VideoPrivacy.PUBLIC,
206 targetUrl: FIXTURE_URLS.goodVideo
208 const { video } = await servers[0].imports.importVideo({ attributes })
210 await waitJobs(servers)
212 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
216 describe('My video is published', function () {
217 let baseParams: CheckerBaseParams
223 socketNotifications: adminNotificationsServer2,
224 token: servers[1].accessToken
228 it('Should not send a notification if transcoding is not enabled', async function () {
231 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
232 await waitJobs(servers)
234 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
237 it('Should not send a notification if the wait transcoding is false', async function () {
238 this.timeout(100_000)
240 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
241 await waitJobs(servers)
243 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
245 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
249 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
252 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
253 await waitJobs(servers)
255 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
258 it('Should send a notification with a transcoded video', async function () {
261 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
262 await waitJobs(servers)
264 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
267 it('Should send a notification when an imported video is transcoded', async function () {
270 const name = 'video import ' + buildUUID()
275 privacy: VideoPrivacy.PUBLIC,
276 targetUrl: FIXTURE_URLS.goodVideo,
277 waitTranscoding: true
279 const { video } = await servers[1].imports.importVideo({ attributes })
281 await waitJobs(servers)
282 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
285 it('Should send a notification when the scheduled update has been proceeded', async function () {
289 const updateAt = new Date(new Date().getTime() + 2000)
292 privacy: VideoPrivacy.PRIVATE,
294 updateAt: updateAt.toISOString(),
295 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
298 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
301 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
304 it('Should not send a notification before the video is published', async function () {
307 const updateAt = new Date(new Date().getTime() + 1000000)
310 privacy: VideoPrivacy.PRIVATE,
312 updateAt: updateAt.toISOString(),
313 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
316 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
319 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
323 describe('My video is imported', function () {
324 let baseParams: CheckerBaseParams
330 socketNotifications: adminNotifications,
331 token: servers[0].accessToken
335 it('Should send a notification when the video import failed', async function () {
338 const name = 'video import ' + buildUUID()
343 privacy: VideoPrivacy.PRIVATE,
344 targetUrl: FIXTURE_URLS.badVideo
346 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
348 await waitJobs(servers)
350 const url = FIXTURE_URLS.badVideo
351 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
354 it('Should send a notification when the video import succeeded', async function () {
357 const name = 'video import ' + buildUUID()
362 privacy: VideoPrivacy.PRIVATE,
363 targetUrl: FIXTURE_URLS.goodVideo
365 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
367 await waitJobs(servers)
369 const url = FIXTURE_URLS.goodVideo
370 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
374 describe('New actor follow', function () {
375 let baseParams: CheckerBaseParams
376 const myChannelName = 'super channel name'
377 const myUserName = 'super user name'
383 socketNotifications: userNotifications,
384 token: userAccessToken
387 await servers[0].users.updateMe({ displayName: 'super root name' })
389 await servers[0].users.updateMe({
390 token: userAccessToken,
391 displayName: myUserName
394 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
396 await servers[0].channels.update({
397 token: userAccessToken,
398 channelName: 'user_1_channel',
399 attributes: { displayName: myChannelName }
403 it('Should notify when a local channel is following one of our channel', async function () {
406 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
407 await waitJobs(servers)
409 await checkNewActorFollow({
411 followType: 'channel',
412 followerName: 'root',
413 followerDisplayName: 'super root name',
414 followingDisplayName: myChannelName,
415 checkType: 'presence'
418 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
421 it('Should notify when a remote channel is following one of our channel', async function () {
424 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
425 await waitJobs(servers)
427 await checkNewActorFollow({
429 followType: 'channel',
430 followerName: 'root',
431 followerDisplayName: 'super root 2 name',
432 followingDisplayName: myChannelName,
433 checkType: 'presence'
436 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
439 // PeerTube does not support accout -> account follows
440 // it('Should notify when a local account is following one of our channel', async function () {
441 // this.timeout(50000)
443 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
445 // await waitJobs(servers)
447 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
450 // it('Should notify when a remote account is following one of our channel', async function () {
451 // this.timeout(50000)
453 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
455 // await waitJobs(servers)
457 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
461 after(async function () {
462 MockSmtpServer.Instance.kill()
464 await cleanupTests(servers)