]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/notifications/user-notifications.ts
Add video edition finished notification
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / user-notifications.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 CheckerBaseParams,
7 checkMyVideoImportIsFinished,
8 checkNewActorFollow,
9 checkNewVideoFromSubscription,
10 checkVideoEditionIsFinished,
11 checkVideoIsPublished,
12 FIXTURE_URLS,
13 MockSmtpServer,
14 prepareNotificationsTest,
15 uploadRandomVideoOnServers
16 } from '@server/tests/shared'
17 import { wait } from '@shared/core-utils'
18 import { buildUUID } from '@shared/extra-utils'
19 import { UserNotification, UserNotificationType, VideoEditorTask, VideoPrivacy } from '@shared/models'
20 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
21
22 const expect = chai.expect
23
24 describe('Test user notifications', function () {
25 let servers: PeerTubeServer[] = []
26 let userAccessToken: string
27
28 let userNotifications: UserNotification[] = []
29 let adminNotifications: UserNotification[] = []
30 let adminNotificationsServer2: UserNotification[] = []
31 let emails: object[] = []
32
33 let channelId: number
34
35 before(async function () {
36 this.timeout(120000)
37
38 const res = await prepareNotificationsTest(3)
39 emails = res.emails
40 userAccessToken = res.userAccessToken
41 servers = res.servers
42 userNotifications = res.userNotifications
43 adminNotifications = res.adminNotifications
44 adminNotificationsServer2 = res.adminNotificationsServer2
45 channelId = res.channelId
46 })
47
48 describe('New video from my subscription notification', function () {
49 let baseParams: CheckerBaseParams
50
51 before(() => {
52 baseParams = {
53 server: servers[0],
54 emails,
55 socketNotifications: userNotifications,
56 token: userAccessToken
57 }
58 })
59
60 it('Should not send notifications if the user does not follow the video publisher', async function () {
61 this.timeout(50000)
62
63 await uploadRandomVideoOnServers(servers, 1)
64
65 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
66 expect(notification).to.be.undefined
67
68 expect(emails).to.have.lengthOf(0)
69 expect(userNotifications).to.have.lengthOf(0)
70 })
71
72 it('Should send a new video notification if the user follows the local video publisher', async function () {
73 this.timeout(15000)
74
75 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
76 await waitJobs(servers)
77
78 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
79 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
80 })
81
82 it('Should send a new video notification from a remote account', async function () {
83 this.timeout(150000) // Server 2 has transcoding enabled
84
85 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
86 await waitJobs(servers)
87
88 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
89 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
90 })
91
92 it('Should send a new video notification on a scheduled publication', async function () {
93 this.timeout(50000)
94
95 // In 2 seconds
96 const updateAt = new Date(new Date().getTime() + 2000)
97
98 const data = {
99 privacy: VideoPrivacy.PRIVATE,
100 scheduleUpdate: {
101 updateAt: updateAt.toISOString(),
102 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
103 }
104 }
105 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
106
107 await wait(6000)
108 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
109 })
110
111 it('Should send a new video notification on a remote scheduled publication', async function () {
112 this.timeout(100000)
113
114 // In 2 seconds
115 const updateAt = new Date(new Date().getTime() + 2000)
116
117 const data = {
118 privacy: VideoPrivacy.PRIVATE,
119 scheduleUpdate: {
120 updateAt: updateAt.toISOString(),
121 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
122 }
123 }
124 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
125 await waitJobs(servers)
126
127 await wait(6000)
128 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
129 })
130
131 it('Should not send a notification before the video is published', async function () {
132 this.timeout(150000)
133
134 const updateAt = new Date(new Date().getTime() + 1000000)
135
136 const data = {
137 privacy: VideoPrivacy.PRIVATE,
138 scheduleUpdate: {
139 updateAt: updateAt.toISOString(),
140 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
141 }
142 }
143 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
144
145 await wait(6000)
146 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
147 })
148
149 it('Should send a new video notification when a video becomes public', async function () {
150 this.timeout(50000)
151
152 const data = { privacy: VideoPrivacy.PRIVATE }
153 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
154
155 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
156
157 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
158
159 await waitJobs(servers)
160 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
161 })
162
163 it('Should send a new video notification when a remote video becomes public', async function () {
164 this.timeout(50000)
165
166 const data = { privacy: VideoPrivacy.PRIVATE }
167 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
168
169 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
170
171 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
172
173 await waitJobs(servers)
174 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
175 })
176
177 it('Should not send a new video notification when a video becomes unlisted', async function () {
178 this.timeout(50000)
179
180 const data = { privacy: VideoPrivacy.PRIVATE }
181 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
182
183 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
184
185 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
186 })
187
188 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
189 this.timeout(50000)
190
191 const data = { privacy: VideoPrivacy.PRIVATE }
192 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
193
194 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
195
196 await waitJobs(servers)
197 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
198 })
199
200 it('Should send a new video notification after a video import', async function () {
201 this.timeout(100000)
202
203 const name = 'video import ' + buildUUID()
204
205 const attributes = {
206 name,
207 channelId,
208 privacy: VideoPrivacy.PUBLIC,
209 targetUrl: FIXTURE_URLS.goodVideo
210 }
211 const { video } = await servers[0].imports.importVideo({ attributes })
212
213 await waitJobs(servers)
214
215 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
216 })
217 })
218
219 describe('My video is published', function () {
220 let baseParams: CheckerBaseParams
221
222 before(() => {
223 baseParams = {
224 server: servers[1],
225 emails,
226 socketNotifications: adminNotificationsServer2,
227 token: servers[1].accessToken
228 }
229 })
230
231 it('Should not send a notification if transcoding is not enabled', async function () {
232 this.timeout(50000)
233
234 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
235 await waitJobs(servers)
236
237 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
238 })
239
240 it('Should not send a notification if the wait transcoding is false', async function () {
241 this.timeout(100_000)
242
243 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
244 await waitJobs(servers)
245
246 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
247 if (notification) {
248 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
249 }
250 })
251
252 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
253 this.timeout(50000)
254
255 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
256 await waitJobs(servers)
257
258 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
259 })
260
261 it('Should send a notification with a transcoded video', async function () {
262 this.timeout(50000)
263
264 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
265 await waitJobs(servers)
266
267 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
268 })
269
270 it('Should send a notification when an imported video is transcoded', async function () {
271 this.timeout(120000)
272
273 const name = 'video import ' + buildUUID()
274
275 const attributes = {
276 name,
277 channelId,
278 privacy: VideoPrivacy.PUBLIC,
279 targetUrl: FIXTURE_URLS.goodVideo,
280 waitTranscoding: true
281 }
282 const { video } = await servers[1].imports.importVideo({ attributes })
283
284 await waitJobs(servers)
285 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
286 })
287
288 it('Should send a notification when the scheduled update has been proceeded', async function () {
289 this.timeout(70000)
290
291 // In 2 seconds
292 const updateAt = new Date(new Date().getTime() + 2000)
293
294 const data = {
295 privacy: VideoPrivacy.PRIVATE,
296 scheduleUpdate: {
297 updateAt: updateAt.toISOString(),
298 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
299 }
300 }
301 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
302
303 await wait(6000)
304 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
305 })
306
307 it('Should not send a notification before the video is published', async function () {
308 this.timeout(50000)
309
310 const updateAt = new Date(new Date().getTime() + 1000000)
311
312 const data = {
313 privacy: VideoPrivacy.PRIVATE,
314 scheduleUpdate: {
315 updateAt: updateAt.toISOString(),
316 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
317 }
318 }
319 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
320
321 await wait(6000)
322 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
323 })
324 })
325
326 describe('Video editor', function () {
327 let baseParams: CheckerBaseParams
328
329 before(() => {
330 baseParams = {
331 server: servers[1],
332 emails,
333 socketNotifications: adminNotificationsServer2,
334 token: servers[1].accessToken
335 }
336 })
337
338 it('Should send a notification after editor edition', async function () {
339 this.timeout(240000)
340
341 const { name, shortUUID, id } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
342
343 await waitJobs(servers)
344 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
345
346 const tasks: VideoEditorTask[] = [
347 {
348 name: 'cut',
349 options: {
350 start: 0,
351 end: 1
352 }
353 }
354 ]
355 await servers[1].videoEditor.createEditionTasks({ videoId: id, tasks })
356 await waitJobs(servers)
357
358 await checkVideoEditionIsFinished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
359 })
360 })
361
362 describe('My video is imported', function () {
363 let baseParams: CheckerBaseParams
364
365 before(() => {
366 baseParams = {
367 server: servers[0],
368 emails,
369 socketNotifications: adminNotifications,
370 token: servers[0].accessToken
371 }
372 })
373
374 it('Should send a notification when the video import failed', async function () {
375 this.timeout(70000)
376
377 const name = 'video import ' + buildUUID()
378
379 const attributes = {
380 name,
381 channelId,
382 privacy: VideoPrivacy.PRIVATE,
383 targetUrl: FIXTURE_URLS.badVideo
384 }
385 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
386
387 await waitJobs(servers)
388
389 const url = FIXTURE_URLS.badVideo
390 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
391 })
392
393 it('Should send a notification when the video import succeeded', async function () {
394 this.timeout(70000)
395
396 const name = 'video import ' + buildUUID()
397
398 const attributes = {
399 name,
400 channelId,
401 privacy: VideoPrivacy.PRIVATE,
402 targetUrl: FIXTURE_URLS.goodVideo
403 }
404 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
405
406 await waitJobs(servers)
407
408 const url = FIXTURE_URLS.goodVideo
409 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
410 })
411 })
412
413 describe('New actor follow', function () {
414 let baseParams: CheckerBaseParams
415 const myChannelName = 'super channel name'
416 const myUserName = 'super user name'
417
418 before(async () => {
419 baseParams = {
420 server: servers[0],
421 emails,
422 socketNotifications: userNotifications,
423 token: userAccessToken
424 }
425
426 await servers[0].users.updateMe({ displayName: 'super root name' })
427
428 await servers[0].users.updateMe({
429 token: userAccessToken,
430 displayName: myUserName
431 })
432
433 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
434
435 await servers[0].channels.update({
436 token: userAccessToken,
437 channelName: 'user_1_channel',
438 attributes: { displayName: myChannelName }
439 })
440 })
441
442 it('Should notify when a local channel is following one of our channel', async function () {
443 this.timeout(50000)
444
445 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
446 await waitJobs(servers)
447
448 await checkNewActorFollow({
449 ...baseParams,
450 followType: 'channel',
451 followerName: 'root',
452 followerDisplayName: 'super root name',
453 followingDisplayName: myChannelName,
454 checkType: 'presence'
455 })
456
457 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
458 })
459
460 it('Should notify when a remote channel is following one of our channel', async function () {
461 this.timeout(50000)
462
463 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
464 await waitJobs(servers)
465
466 await checkNewActorFollow({
467 ...baseParams,
468 followType: 'channel',
469 followerName: 'root',
470 followerDisplayName: 'super root 2 name',
471 followingDisplayName: myChannelName,
472 checkType: 'presence'
473 })
474
475 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
476 })
477
478 // PeerTube does not support accout -> account follows
479 // it('Should notify when a local account is following one of our channel', async function () {
480 // this.timeout(50000)
481 //
482 // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
483 //
484 // await waitJobs(servers)
485 //
486 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
487 // })
488
489 // it('Should notify when a remote account is following one of our channel', async function () {
490 // this.timeout(50000)
491 //
492 // await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
493 //
494 // await waitJobs(servers)
495 //
496 // await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
497 // })
498 })
499
500 after(async function () {
501 MockSmtpServer.Instance.kill()
502
503 await cleanupTests(servers)
504 })
505 })