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,
20 uploadRandomVideoOnServers,
23 } from '@shared/extra-utils'
24 import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports'
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: getGoodVideoUrl()
214 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
215 const uuid = res.body.video.uuid
217 await waitJobs(servers)
219 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
223 describe('My video is published', function () {
224 let baseParams: CheckerBaseParams
230 socketNotifications: adminNotificationsServer2,
231 token: servers[1].accessToken
235 it('Should not send a notification if transcoding is not enabled', async function () {
238 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
239 await waitJobs(servers)
241 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
244 it('Should not send a notification if the wait transcoding is false', async function () {
247 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
248 await waitJobs(servers)
250 const notification = await getLastNotification(servers[0].url, userAccessToken)
252 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
256 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
259 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
260 await waitJobs(servers)
262 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
265 it('Should send a notification with a transcoded video', async function () {
268 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
269 await waitJobs(servers)
271 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
274 it('Should send a notification when an imported video is transcoded', async function () {
277 const name = 'video import ' + buildUUID()
282 privacy: VideoPrivacy.PUBLIC,
283 targetUrl: getGoodVideoUrl(),
284 waitTranscoding: true
286 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
287 const uuid = res.body.video.uuid
289 await waitJobs(servers)
290 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
293 it('Should send a notification when the scheduled update has been proceeded', async function () {
297 const updateAt = new Date(new Date().getTime() + 2000)
300 privacy: VideoPrivacy.PRIVATE,
302 updateAt: updateAt.toISOString(),
303 privacy: VideoPrivacy.PUBLIC
306 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
309 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
312 it('Should not send a notification before the video is published', async function () {
315 const updateAt = new Date(new Date().getTime() + 1000000)
318 privacy: VideoPrivacy.PRIVATE,
320 updateAt: updateAt.toISOString(),
321 privacy: VideoPrivacy.PUBLIC
324 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
327 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
331 describe('My video is imported', function () {
332 let baseParams: CheckerBaseParams
338 socketNotifications: adminNotifications,
339 token: servers[0].accessToken
343 it('Should send a notification when the video import failed', async function () {
346 const name = 'video import ' + buildUUID()
351 privacy: VideoPrivacy.PRIVATE,
352 targetUrl: getBadVideoUrl()
354 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
355 const uuid = res.body.video.uuid
357 await waitJobs(servers)
358 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
361 it('Should send a notification when the video import succeeded', async function () {
364 const name = 'video import ' + buildUUID()
369 privacy: VideoPrivacy.PRIVATE,
370 targetUrl: getGoodVideoUrl()
372 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
373 const uuid = res.body.video.uuid
375 await waitJobs(servers)
376 await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence')
380 describe('New actor follow', function () {
381 let baseParams: CheckerBaseParams
382 const myChannelName = 'super channel name'
383 const myUserName = 'super user name'
389 socketNotifications: userNotifications,
390 token: userAccessToken
395 accessToken: servers[0].accessToken,
396 displayName: 'super root name'
401 accessToken: userAccessToken,
402 displayName: myUserName
407 accessToken: servers[1].accessToken,
408 displayName: 'super root 2 name'
411 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
414 it('Should notify when a local channel is following one of our channel', async function () {
417 await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
418 await waitJobs(servers)
420 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
422 await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
425 it('Should notify when a remote channel is following one of our channel', async function () {
428 await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
429 await waitJobs(servers)
431 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
433 await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
436 // PeerTube does not support accout -> account follows
437 // it('Should notify when a local account is following one of our channel', async function () {
438 // this.timeout(50000)
440 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
442 // await waitJobs(servers)
444 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
447 // it('Should notify when a remote account is following one of our channel', async function () {
448 // this.timeout(50000)
450 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
452 // await waitJobs(servers)
454 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
458 after(async function () {
459 MockSmtpServer.Instance.kill()
461 await cleanupTests(servers)