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,
21 uploadRandomVideoOnServers,
24 } from '@shared/extra-utils'
25 import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
27 const expect = chai.expect
29 describe('Test user notifications', function () {
30 let servers: ServerInfo[] = []
31 let userAccessToken: string
32 let userNotifications: UserNotification[] = []
33 let adminNotifications: UserNotification[] = []
34 let adminNotificationsServer2: UserNotification[] = []
35 let emails: object[] = []
38 before(async function () {
41 const res = await prepareNotificationsTest(3)
43 userAccessToken = res.userAccessToken
45 userNotifications = res.userNotifications
46 adminNotifications = res.adminNotifications
47 adminNotificationsServer2 = res.adminNotificationsServer2
48 channelId = res.channelId
51 describe('New video from my subscription notification', function () {
52 let baseParams: CheckerBaseParams
58 socketNotifications: userNotifications,
59 token: userAccessToken
63 it('Should not send notifications if the user does not follow the video publisher', async function () {
66 await uploadRandomVideoOnServers(servers, 1)
68 const notification = await getLastNotification(servers[0].url, userAccessToken)
69 expect(notification).to.be.undefined
71 expect(emails).to.have.lengthOf(0)
72 expect(userNotifications).to.have.lengthOf(0)
75 it('Should send a new video notification if the user follows the local video publisher', async function () {
78 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
79 await waitJobs(servers)
81 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
82 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
85 it('Should send a new video notification from a remote account', async function () {
86 this.timeout(150000) // Server 2 has transcoding enabled
88 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
89 await waitJobs(servers)
91 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2)
92 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
95 it('Should send a new video notification on a scheduled publication', async function () {
99 const updateAt = new Date(new Date().getTime() + 2000)
102 privacy: VideoPrivacy.PRIVATE,
104 updateAt: updateAt.toISOString(),
105 privacy: VideoPrivacy.PUBLIC
108 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
111 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
114 it('Should send a new video notification on a remote scheduled publication', async function () {
118 const updateAt = new Date(new Date().getTime() + 2000)
121 privacy: VideoPrivacy.PRIVATE,
123 updateAt: updateAt.toISOString(),
124 privacy: VideoPrivacy.PUBLIC
127 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
128 await waitJobs(servers)
131 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
134 it('Should not send a notification before the video is published', async function () {
137 const updateAt = new Date(new Date().getTime() + 1000000)
140 privacy: VideoPrivacy.PRIVATE,
142 updateAt: updateAt.toISOString(),
143 privacy: VideoPrivacy.PUBLIC
146 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
149 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
152 it('Should send a new video notification when a video becomes public', async function () {
155 const data = { privacy: VideoPrivacy.PRIVATE }
156 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
158 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
160 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
162 await waitJobs(servers)
163 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
166 it('Should send a new video notification when a remote video becomes public', async function () {
169 const data = { privacy: VideoPrivacy.PRIVATE }
170 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
172 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
174 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
176 await waitJobs(servers)
177 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
180 it('Should not send a new video notification when a video becomes unlisted', async function () {
183 const data = { privacy: VideoPrivacy.PRIVATE }
184 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
186 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
188 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
191 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
194 const data = { privacy: VideoPrivacy.PRIVATE }
195 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
197 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
199 await waitJobs(servers)
200 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
203 it('Should send a new video notification after a video import', async function () {
206 const name = 'video import ' + buildUUID()
211 privacy: VideoPrivacy.PUBLIC,
212 targetUrl: ImportsCommand.getGoodVideoUrl()
214 const { video } = await servers[0].importsCommand.importVideo({ attributes })
216 await waitJobs(servers)
218 await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
222 describe('My video is published', function () {
223 let baseParams: CheckerBaseParams
229 socketNotifications: adminNotificationsServer2,
230 token: servers[1].accessToken
234 it('Should not send a notification if transcoding is not enabled', async function () {
237 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
238 await waitJobs(servers)
240 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
243 it('Should not send a notification if the wait transcoding is false', async function () {
246 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
247 await waitJobs(servers)
249 const notification = await getLastNotification(servers[0].url, userAccessToken)
251 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
255 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
258 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
259 await waitJobs(servers)
261 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
264 it('Should send a notification with a transcoded video', async function () {
267 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
268 await waitJobs(servers)
270 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
273 it('Should send a notification when an imported video is transcoded', async function () {
276 const name = 'video import ' + buildUUID()
281 privacy: VideoPrivacy.PUBLIC,
282 targetUrl: ImportsCommand.getGoodVideoUrl(),
283 waitTranscoding: true
285 const { video } = await servers[1].importsCommand.importVideo({ attributes })
287 await waitJobs(servers)
288 await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
291 it('Should send a notification when the scheduled update has been proceeded', async function () {
295 const updateAt = new Date(new Date().getTime() + 2000)
298 privacy: VideoPrivacy.PRIVATE,
300 updateAt: updateAt.toISOString(),
301 privacy: VideoPrivacy.PUBLIC
304 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
307 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
310 it('Should not send a notification before the video is published', async function () {
313 const updateAt = new Date(new Date().getTime() + 1000000)
316 privacy: VideoPrivacy.PRIVATE,
318 updateAt: updateAt.toISOString(),
319 privacy: VideoPrivacy.PUBLIC
322 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
325 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
329 describe('My video is imported', function () {
330 let baseParams: CheckerBaseParams
336 socketNotifications: adminNotifications,
337 token: servers[0].accessToken
341 it('Should send a notification when the video import failed', async function () {
344 const name = 'video import ' + buildUUID()
349 privacy: VideoPrivacy.PRIVATE,
350 targetUrl: ImportsCommand.getBadVideoUrl()
352 const { video } = await servers[0].importsCommand.importVideo({ attributes })
354 await waitJobs(servers)
355 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence')
358 it('Should send a notification when the video import succeeded', async function () {
361 const name = 'video import ' + buildUUID()
366 privacy: VideoPrivacy.PRIVATE,
367 targetUrl: ImportsCommand.getGoodVideoUrl()
369 const { video } = await servers[0].importsCommand.importVideo({ attributes })
371 await waitJobs(servers)
372 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence')
376 describe('New actor follow', function () {
377 let baseParams: CheckerBaseParams
378 const myChannelName = 'super channel name'
379 const myUserName = 'super user name'
385 socketNotifications: userNotifications,
386 token: userAccessToken
391 accessToken: servers[0].accessToken,
392 displayName: 'super root name'
397 accessToken: userAccessToken,
398 displayName: myUserName
403 accessToken: servers[1].accessToken,
404 displayName: 'super root 2 name'
407 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
410 it('Should notify when a local channel is following one of our channel', async function () {
413 await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
414 await waitJobs(servers)
416 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
418 await servers[0].subscriptionsCommand.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].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
425 await waitJobs(servers)
427 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
429 await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
432 // PeerTube does not support accout -> account follows
433 // it('Should notify when a local account is following one of our channel', async function () {
434 // this.timeout(50000)
436 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
438 // await waitJobs(servers)
440 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
443 // it('Should notify when a remote account is following one of our channel', async function () {
444 // this.timeout(50000)
446 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
448 // await waitJobs(servers)
450 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
454 after(async function () {
455 MockSmtpServer.Instance.kill()
457 await cleanupTests(servers)