1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { buildUUID } from '@server/helpers/uuid'
8 checkMyVideoImportIsFinished,
10 checkNewVideoFromSubscription,
11 checkVideoIsPublished,
16 prepareNotificationsTest,
20 uploadRandomVideoOnServers,
23 } from '@shared/extra-utils'
24 import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
26 const expect = chai.expect
28 describe('Test user notifications', function () {
29 let servers: ServerInfo[] = []
30 let userAccessToken: string
31 let userNotifications: UserNotification[] = []
32 let adminNotifications: UserNotification[] = []
33 let adminNotificationsServer2: UserNotification[] = []
34 let emails: object[] = []
37 before(async function () {
40 const res = await prepareNotificationsTest(3)
42 userAccessToken = res.userAccessToken
44 userNotifications = res.userNotifications
45 adminNotifications = res.adminNotifications
46 adminNotificationsServer2 = res.adminNotificationsServer2
47 channelId = res.channelId
50 describe('New video from my subscription notification', function () {
51 let baseParams: CheckerBaseParams
57 socketNotifications: userNotifications,
58 token: userAccessToken
62 it('Should not send notifications if the user does not follow the video publisher', async function () {
65 await uploadRandomVideoOnServers(servers, 1)
67 const notification = await getLastNotification(servers[0].url, userAccessToken)
68 expect(notification).to.be.undefined
70 expect(emails).to.have.lengthOf(0)
71 expect(userNotifications).to.have.lengthOf(0)
74 it('Should send a new video notification if the user follows the local video publisher', async function () {
77 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
78 await waitJobs(servers)
80 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
81 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
84 it('Should send a new video notification from a remote account', async function () {
85 this.timeout(150000) // Server 2 has transcoding enabled
87 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
88 await waitJobs(servers)
90 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2)
91 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
94 it('Should send a new video notification on a scheduled publication', async function () {
98 const updateAt = new Date(new Date().getTime() + 2000)
101 privacy: VideoPrivacy.PRIVATE,
103 updateAt: updateAt.toISOString(),
104 privacy: VideoPrivacy.PUBLIC
107 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
110 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
113 it('Should send a new video notification on a remote scheduled publication', async function () {
117 const updateAt = new Date(new Date().getTime() + 2000)
120 privacy: VideoPrivacy.PRIVATE,
122 updateAt: updateAt.toISOString(),
123 privacy: VideoPrivacy.PUBLIC
126 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
127 await waitJobs(servers)
130 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
133 it('Should not send a notification before the video is published', async function () {
136 const updateAt = new Date(new Date().getTime() + 1000000)
139 privacy: VideoPrivacy.PRIVATE,
141 updateAt: updateAt.toISOString(),
142 privacy: VideoPrivacy.PUBLIC
145 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
148 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
151 it('Should send a new video notification when a video becomes public', async function () {
154 const data = { privacy: VideoPrivacy.PRIVATE }
155 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
157 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
159 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
161 await waitJobs(servers)
162 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
165 it('Should send a new video notification when a remote video becomes public', async function () {
168 const data = { privacy: VideoPrivacy.PRIVATE }
169 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
171 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
173 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
175 await waitJobs(servers)
176 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
179 it('Should not send a new video notification when a video becomes unlisted', async function () {
182 const data = { privacy: VideoPrivacy.PRIVATE }
183 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
185 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
187 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
190 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
193 const data = { privacy: VideoPrivacy.PRIVATE }
194 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
196 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
198 await waitJobs(servers)
199 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
202 it('Should send a new video notification after a video import', async function () {
205 const name = 'video import ' + buildUUID()
210 privacy: VideoPrivacy.PUBLIC,
211 targetUrl: ImportsCommand.getGoodVideoUrl()
213 const { video } = await servers[0].importsCommand.importVideo({ attributes })
215 await waitJobs(servers)
217 await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
221 describe('My video is published', function () {
222 let baseParams: CheckerBaseParams
228 socketNotifications: adminNotificationsServer2,
229 token: servers[1].accessToken
233 it('Should not send a notification if transcoding is not enabled', async function () {
236 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
237 await waitJobs(servers)
239 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
242 it('Should not send a notification if the wait transcoding is false', async function () {
245 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
246 await waitJobs(servers)
248 const notification = await getLastNotification(servers[0].url, userAccessToken)
250 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
254 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
257 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
258 await waitJobs(servers)
260 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
263 it('Should send a notification with a transcoded video', async function () {
266 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
267 await waitJobs(servers)
269 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
272 it('Should send a notification when an imported video is transcoded', async function () {
275 const name = 'video import ' + buildUUID()
280 privacy: VideoPrivacy.PUBLIC,
281 targetUrl: ImportsCommand.getGoodVideoUrl(),
282 waitTranscoding: true
284 const { video } = await servers[1].importsCommand.importVideo({ attributes })
286 await waitJobs(servers)
287 await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
290 it('Should send a notification when the scheduled update has been proceeded', async function () {
294 const updateAt = new Date(new Date().getTime() + 2000)
297 privacy: VideoPrivacy.PRIVATE,
299 updateAt: updateAt.toISOString(),
300 privacy: VideoPrivacy.PUBLIC
303 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
306 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
309 it('Should not send a notification before the video is published', async function () {
312 const updateAt = new Date(new Date().getTime() + 1000000)
315 privacy: VideoPrivacy.PRIVATE,
317 updateAt: updateAt.toISOString(),
318 privacy: VideoPrivacy.PUBLIC
321 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
324 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
328 describe('My video is imported', function () {
329 let baseParams: CheckerBaseParams
335 socketNotifications: adminNotifications,
336 token: servers[0].accessToken
340 it('Should send a notification when the video import failed', async function () {
343 const name = 'video import ' + buildUUID()
348 privacy: VideoPrivacy.PRIVATE,
349 targetUrl: ImportsCommand.getBadVideoUrl()
351 const { video } = await servers[0].importsCommand.importVideo({ attributes })
353 await waitJobs(servers)
354 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence')
357 it('Should send a notification when the video import succeeded', async function () {
360 const name = 'video import ' + buildUUID()
365 privacy: VideoPrivacy.PRIVATE,
366 targetUrl: ImportsCommand.getGoodVideoUrl()
368 const { video } = await servers[0].importsCommand.importVideo({ attributes })
370 await waitJobs(servers)
371 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence')
375 describe('New actor follow', function () {
376 let baseParams: CheckerBaseParams
377 const myChannelName = 'super channel name'
378 const myUserName = 'super user name'
384 socketNotifications: userNotifications,
385 token: userAccessToken
390 accessToken: servers[0].accessToken,
391 displayName: 'super root name'
396 accessToken: userAccessToken,
397 displayName: myUserName
402 accessToken: servers[1].accessToken,
403 displayName: 'super root 2 name'
406 await servers[0].channelsCommand.update({
407 token: userAccessToken,
408 channelName: 'user_1_channel',
409 attributes: { displayName: myChannelName }
413 it('Should notify when a local channel is following one of our channel', async function () {
416 await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
417 await waitJobs(servers)
419 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
421 await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
424 it('Should notify when a remote channel is following one of our channel', async function () {
427 await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
428 await waitJobs(servers)
430 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
432 await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
435 // PeerTube does not support accout -> account follows
436 // it('Should notify when a local account is following one of our channel', async function () {
437 // this.timeout(50000)
439 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
441 // await waitJobs(servers)
443 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
446 // it('Should notify when a remote account is following one of our channel', async function () {
447 // this.timeout(50000)
449 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
451 // await waitJobs(servers)
453 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
457 after(async function () {
458 MockSmtpServer.Instance.kill()
460 await cleanupTests(servers)