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,
15 prepareNotificationsTest,
19 uploadRandomVideoOnServers,
22 } from '@shared/extra-utils'
23 import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
25 const expect = chai.expect
27 describe('Test user notifications', function () {
28 let servers: ServerInfo[] = []
29 let userAccessToken: string
30 let userNotifications: UserNotification[] = []
31 let adminNotifications: UserNotification[] = []
32 let adminNotificationsServer2: UserNotification[] = []
33 let emails: object[] = []
36 before(async function () {
39 const res = await prepareNotificationsTest(3)
41 userAccessToken = res.userAccessToken
43 userNotifications = res.userNotifications
44 adminNotifications = res.adminNotifications
45 adminNotificationsServer2 = res.adminNotificationsServer2
46 channelId = res.channelId
49 describe('New video from my subscription notification', function () {
50 let baseParams: CheckerBaseParams
56 socketNotifications: userNotifications,
57 token: userAccessToken
61 it('Should not send notifications if the user does not follow the video publisher', async function () {
64 await uploadRandomVideoOnServers(servers, 1)
66 const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken })
67 expect(notification).to.be.undefined
69 expect(emails).to.have.lengthOf(0)
70 expect(userNotifications).to.have.lengthOf(0)
73 it('Should send a new video notification if the user follows the local video publisher', async function () {
76 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
77 await waitJobs(servers)
79 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
80 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
83 it('Should send a new video notification from a remote account', async function () {
84 this.timeout(150000) // Server 2 has transcoding enabled
86 await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
87 await waitJobs(servers)
89 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2)
90 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
93 it('Should send a new video notification on a scheduled publication', async function () {
97 const updateAt = new Date(new Date().getTime() + 2000)
100 privacy: VideoPrivacy.PRIVATE,
102 updateAt: updateAt.toISOString(),
103 privacy: VideoPrivacy.PUBLIC
106 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
109 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
112 it('Should send a new video notification on a remote scheduled publication', async function () {
116 const updateAt = new Date(new Date().getTime() + 2000)
119 privacy: VideoPrivacy.PRIVATE,
121 updateAt: updateAt.toISOString(),
122 privacy: VideoPrivacy.PUBLIC
125 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
126 await waitJobs(servers)
129 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
132 it('Should not send a notification before the video is published', async function () {
135 const updateAt = new Date(new Date().getTime() + 1000000)
138 privacy: VideoPrivacy.PRIVATE,
140 updateAt: updateAt.toISOString(),
141 privacy: VideoPrivacy.PUBLIC
144 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
147 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
150 it('Should send a new video notification when a video becomes public', async function () {
153 const data = { privacy: VideoPrivacy.PRIVATE }
154 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
156 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
158 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
160 await waitJobs(servers)
161 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
164 it('Should send a new video notification when a remote video becomes public', async function () {
167 const data = { privacy: VideoPrivacy.PRIVATE }
168 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
170 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
172 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
174 await waitJobs(servers)
175 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
178 it('Should not send a new video notification when a video becomes unlisted', async function () {
181 const data = { privacy: VideoPrivacy.PRIVATE }
182 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
184 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
186 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
189 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
192 const data = { privacy: VideoPrivacy.PRIVATE }
193 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
195 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
197 await waitJobs(servers)
198 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
201 it('Should send a new video notification after a video import', async function () {
204 const name = 'video import ' + buildUUID()
209 privacy: VideoPrivacy.PUBLIC,
210 targetUrl: ImportsCommand.getGoodVideoUrl()
212 const { video } = await servers[0].importsCommand.importVideo({ attributes })
214 await waitJobs(servers)
216 await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
220 describe('My video is published', function () {
221 let baseParams: CheckerBaseParams
227 socketNotifications: adminNotificationsServer2,
228 token: servers[1].accessToken
232 it('Should not send a notification if transcoding is not enabled', async function () {
235 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
236 await waitJobs(servers)
238 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
241 it('Should not send a notification if the wait transcoding is false', async function () {
244 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
245 await waitJobs(servers)
247 const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken })
249 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
253 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
256 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
257 await waitJobs(servers)
259 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
262 it('Should send a notification with a transcoded video', async function () {
265 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
266 await waitJobs(servers)
268 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
271 it('Should send a notification when an imported video is transcoded', async function () {
274 const name = 'video import ' + buildUUID()
279 privacy: VideoPrivacy.PUBLIC,
280 targetUrl: ImportsCommand.getGoodVideoUrl(),
281 waitTranscoding: true
283 const { video } = await servers[1].importsCommand.importVideo({ attributes })
285 await waitJobs(servers)
286 await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
289 it('Should send a notification when the scheduled update has been proceeded', async function () {
293 const updateAt = new Date(new Date().getTime() + 2000)
296 privacy: VideoPrivacy.PRIVATE,
298 updateAt: updateAt.toISOString(),
299 privacy: VideoPrivacy.PUBLIC
302 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
305 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
308 it('Should not send a notification before the video is published', async function () {
311 const updateAt = new Date(new Date().getTime() + 1000000)
314 privacy: VideoPrivacy.PRIVATE,
316 updateAt: updateAt.toISOString(),
317 privacy: VideoPrivacy.PUBLIC
320 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
323 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
327 describe('My video is imported', function () {
328 let baseParams: CheckerBaseParams
334 socketNotifications: adminNotifications,
335 token: servers[0].accessToken
339 it('Should send a notification when the video import failed', async function () {
342 const name = 'video import ' + buildUUID()
347 privacy: VideoPrivacy.PRIVATE,
348 targetUrl: ImportsCommand.getBadVideoUrl()
350 const { video } = await servers[0].importsCommand.importVideo({ attributes })
352 await waitJobs(servers)
353 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence')
356 it('Should send a notification when the video import succeeded', async function () {
359 const name = 'video import ' + buildUUID()
364 privacy: VideoPrivacy.PRIVATE,
365 targetUrl: ImportsCommand.getGoodVideoUrl()
367 const { video } = await servers[0].importsCommand.importVideo({ attributes })
369 await waitJobs(servers)
370 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, '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
389 accessToken: servers[0].accessToken,
390 displayName: 'super root name'
395 accessToken: userAccessToken,
396 displayName: myUserName
401 accessToken: servers[1].accessToken,
402 displayName: 'super root 2 name'
405 await servers[0].channelsCommand.update({
406 token: userAccessToken,
407 channelName: 'user_1_channel',
408 attributes: { displayName: myChannelName }
412 it('Should notify when a local channel is following one of our channel', async function () {
415 await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
416 await waitJobs(servers)
418 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
420 await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
423 it('Should notify when a remote channel is following one of our channel', async function () {
426 await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
427 await waitJobs(servers)
429 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
431 await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
434 // PeerTube does not support accout -> account follows
435 // it('Should notify when a local account is following one of our channel', async function () {
436 // this.timeout(50000)
438 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
440 // await waitJobs(servers)
442 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
445 // it('Should notify when a remote account is following one of our channel', async function () {
446 // this.timeout(50000)
448 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
450 // await waitJobs(servers)
452 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
456 after(async function () {
457 MockSmtpServer.Instance.kill()
459 await cleanupTests(servers)