]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/notifications/user-notifications.ts
Add video edition finished notification
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / user-notifications.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
cef534ed 2
cef534ed 3import 'mocha'
8eb07b01 4import * as chai from 'chai'
cef534ed
C
5import {
6 CheckerBaseParams,
f7cc67b4
C
7 checkMyVideoImportIsFinished,
8 checkNewActorFollow,
cef534ed 9 checkNewVideoFromSubscription,
1808a1f8 10 checkVideoEditionIsFinished,
f7cc67b4 11 checkVideoIsPublished,
59bbcced 12 FIXTURE_URLS,
2c27e704 13 MockSmtpServer,
59bbcced 14 prepareNotificationsTest,
c55e3d72
C
15 uploadRandomVideoOnServers
16} from '@server/tests/shared'
0628157f
C
17import { wait } from '@shared/core-utils'
18import { buildUUID } from '@shared/extra-utils'
1808a1f8 19import { UserNotification, UserNotificationType, VideoEditorTask, VideoPrivacy } from '@shared/models'
c55e3d72 20import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
cef534ed
C
21
22const expect = chai.expect
23
8eb07b01 24describe('Test user notifications', function () {
254d3579 25 let servers: PeerTubeServer[] = []
cef534ed 26 let userAccessToken: string
1808a1f8 27
8eb07b01
C
28 let userNotifications: UserNotification[] = []
29 let adminNotifications: UserNotification[] = []
30 let adminNotificationsServer2: UserNotification[] = []
31 let emails: object[] = []
1808a1f8 32
dc133480
C
33 let channelId: number
34
cef534ed
C
35 before(async function () {
36 this.timeout(120000)
37
8eb07b01
C
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
cef534ed
C
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 () {
59fd824c 61 this.timeout(50000)
f7effe8d 62
8eb07b01 63 await uploadRandomVideoOnServers(servers, 1)
cef534ed 64
5d3c5f27 65 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
cef534ed
C
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 () {
89ada4e2 73 this.timeout(15000)
2f1548fd 74
89d241a7 75 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
2f1548fd 76 await waitJobs(servers)
cef534ed 77
29837f88
C
78 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
79 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
cef534ed
C
80 })
81
82 it('Should send a new video notification from a remote account', async function () {
83befebe 83 this.timeout(150000) // Server 2 has transcoding enabled
cef534ed 84
89d241a7 85 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
2f1548fd 86 await waitJobs(servers)
cef534ed 87
29837f88
C
88 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
89 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
cef534ed
C
90 })
91
92 it('Should send a new video notification on a scheduled publication', async function () {
59fd824c 93 this.timeout(50000)
cef534ed 94
cef534ed 95 // In 2 seconds
a1587156 96 const updateAt = new Date(new Date().getTime() + 2000)
cef534ed
C
97
98 const data = {
99 privacy: VideoPrivacy.PRIVATE,
100 scheduleUpdate: {
101 updateAt: updateAt.toISOString(),
d23dd9fb 102 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
cef534ed
C
103 }
104 }
29837f88 105 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
cef534ed
C
106
107 await wait(6000)
29837f88 108 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
cef534ed
C
109 })
110
111 it('Should send a new video notification on a remote scheduled publication', async function () {
8ace6805 112 this.timeout(100000)
cef534ed 113
cef534ed 114 // In 2 seconds
a1587156 115 const updateAt = new Date(new Date().getTime() + 2000)
cef534ed
C
116
117 const data = {
118 privacy: VideoPrivacy.PRIVATE,
119 scheduleUpdate: {
120 updateAt: updateAt.toISOString(),
d23dd9fb 121 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
cef534ed
C
122 }
123 }
29837f88 124 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
e8d246d5 125 await waitJobs(servers)
cef534ed
C
126
127 await wait(6000)
29837f88 128 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
cef534ed
C
129 })
130
131 it('Should not send a notification before the video is published', async function () {
21d68e68 132 this.timeout(150000)
cef534ed 133
a1587156 134 const updateAt = new Date(new Date().getTime() + 1000000)
cef534ed
C
135
136 const data = {
137 privacy: VideoPrivacy.PRIVATE,
138 scheduleUpdate: {
139 updateAt: updateAt.toISOString(),
d23dd9fb 140 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
cef534ed
C
141 }
142 }
29837f88 143 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
cef534ed
C
144
145 await wait(6000)
29837f88 146 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
cef534ed
C
147 })
148
149 it('Should send a new video notification when a video becomes public', async function () {
59fd824c 150 this.timeout(50000)
cef534ed 151
cef534ed 152 const data = { privacy: VideoPrivacy.PRIVATE }
29837f88 153 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
cef534ed 154
29837f88 155 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
cef534ed 156
89d241a7 157 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
cef534ed 158
9f39c546 159 await waitJobs(servers)
29837f88 160 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
cef534ed
C
161 })
162
163 it('Should send a new video notification when a remote video becomes public', async function () {
59fd824c 164 this.timeout(50000)
cef534ed 165
cef534ed 166 const data = { privacy: VideoPrivacy.PRIVATE }
29837f88 167 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
cef534ed 168
29837f88 169 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
cef534ed 170
89d241a7 171 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
cef534ed
C
172
173 await waitJobs(servers)
29837f88 174 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
cef534ed
C
175 })
176
177 it('Should not send a new video notification when a video becomes unlisted', async function () {
59fd824c 178 this.timeout(50000)
cef534ed 179
cef534ed 180 const data = { privacy: VideoPrivacy.PRIVATE }
29837f88 181 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
cef534ed 182
89d241a7 183 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
cef534ed 184
29837f88 185 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
cef534ed
C
186 })
187
188 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
59fd824c 189 this.timeout(50000)
cef534ed 190
cef534ed 191 const data = { privacy: VideoPrivacy.PRIVATE }
29837f88 192 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
cef534ed 193
89d241a7 194 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
cef534ed
C
195
196 await waitJobs(servers)
29837f88 197 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
cef534ed
C
198 })
199
200 it('Should send a new video notification after a video import', async function () {
7ccddd7b 201 this.timeout(100000)
cef534ed 202
d4a8e7a6 203 const name = 'video import ' + buildUUID()
cef534ed
C
204
205 const attributes = {
dc133480 206 name,
cef534ed
C
207 channelId,
208 privacy: VideoPrivacy.PUBLIC,
59bbcced 209 targetUrl: FIXTURE_URLS.goodVideo
cef534ed 210 }
89d241a7 211 const { video } = await servers[0].imports.importVideo({ attributes })
cef534ed
C
212
213 await waitJobs(servers)
214
29837f88 215 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
cef534ed
C
216 })
217 })
218
dc133480
C
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 () {
59fd824c 232 this.timeout(50000)
f7effe8d 233
29837f88 234 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
dc133480
C
235 await waitJobs(servers)
236
29837f88 237 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
dc133480
C
238 })
239
240 it('Should not send a notification if the wait transcoding is false', async function () {
5d3c5f27 241 this.timeout(100_000)
dc133480 242
8eb07b01 243 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
dc133480
C
244 await waitJobs(servers)
245
5d3c5f27 246 const notification = await servers[0].notifications.getLatest({ token: userAccessToken })
dc133480
C
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
29837f88 255 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
dc133480
C
256 await waitJobs(servers)
257
29837f88 258 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
dc133480
C
259 })
260
261 it('Should send a notification with a transcoded video', async function () {
262 this.timeout(50000)
263
29837f88 264 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
dc133480
C
265 await waitJobs(servers)
266
29837f88 267 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
dc133480
C
268 })
269
270 it('Should send a notification when an imported video is transcoded', async function () {
33675a47 271 this.timeout(120000)
dc133480 272
d4a8e7a6 273 const name = 'video import ' + buildUUID()
dc133480
C
274
275 const attributes = {
276 name,
277 channelId,
278 privacy: VideoPrivacy.PUBLIC,
59bbcced 279 targetUrl: FIXTURE_URLS.goodVideo,
dc133480
C
280 waitTranscoding: true
281 }
89d241a7 282 const { video } = await servers[1].imports.importVideo({ attributes })
dc133480
C
283
284 await waitJobs(servers)
29837f88 285 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
dc133480
C
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
a1587156 292 const updateAt = new Date(new Date().getTime() + 2000)
dc133480
C
293
294 const data = {
295 privacy: VideoPrivacy.PRIVATE,
296 scheduleUpdate: {
297 updateAt: updateAt.toISOString(),
d23dd9fb 298 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
dc133480
C
299 }
300 }
29837f88 301 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
dc133480
C
302
303 await wait(6000)
29837f88 304 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
dc133480 305 })
f7effe8d
JM
306
307 it('Should not send a notification before the video is published', async function () {
94d721ef 308 this.timeout(50000)
f7effe8d 309
a1587156 310 const updateAt = new Date(new Date().getTime() + 1000000)
f7effe8d
JM
311
312 const data = {
313 privacy: VideoPrivacy.PRIVATE,
314 scheduleUpdate: {
315 updateAt: updateAt.toISOString(),
d23dd9fb 316 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
f7effe8d
JM
317 }
318 }
29837f88 319 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
f7effe8d
JM
320
321 await wait(6000)
29837f88 322 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
f7effe8d 323 })
dc133480
C
324 })
325
1808a1f8
C
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
dc133480
C
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
d4a8e7a6 377 const name = 'video import ' + buildUUID()
dc133480
C
378
379 const attributes = {
380 name,
381 channelId,
382 privacy: VideoPrivacy.PRIVATE,
59bbcced 383 targetUrl: FIXTURE_URLS.badVideo
dc133480 384 }
29837f88 385 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
dc133480
C
386
387 await waitJobs(servers)
29837f88
C
388
389 const url = FIXTURE_URLS.badVideo
390 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
dc133480
C
391 })
392
393 it('Should send a notification when the video import succeeded', async function () {
394 this.timeout(70000)
395
d4a8e7a6 396 const name = 'video import ' + buildUUID()
dc133480
C
397
398 const attributes = {
399 name,
400 channelId,
401 privacy: VideoPrivacy.PRIVATE,
59bbcced 402 targetUrl: FIXTURE_URLS.goodVideo
dc133480 403 }
29837f88 404 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
dc133480
C
405
406 await waitJobs(servers)
29837f88
C
407
408 const url = FIXTURE_URLS.goodVideo
409 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
cef534ed
C
410 })
411 })
412
f7cc67b4
C
413 describe('New actor follow', function () {
414 let baseParams: CheckerBaseParams
a1587156
C
415 const myChannelName = 'super channel name'
416 const myUserName = 'super user name'
f7cc67b4
C
417
418 before(async () => {
419 baseParams = {
420 server: servers[0],
421 emails,
422 socketNotifications: userNotifications,
423 token: userAccessToken
424 }
425
89d241a7 426 await servers[0].users.updateMe({ displayName: 'super root name' })
f7cc67b4 427
89d241a7 428 await servers[0].users.updateMe({
7926c5f9 429 token: userAccessToken,
f7cc67b4
C
430 displayName: myUserName
431 })
432
89d241a7 433 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
f7cc67b4 434
89d241a7 435 await servers[0].channels.update({
a5461888
C
436 token: userAccessToken,
437 channelName: 'user_1_channel',
438 attributes: { displayName: myChannelName }
439 })
f7cc67b4
C
440 })
441
442 it('Should notify when a local channel is following one of our channel', async function () {
59fd824c 443 this.timeout(50000)
f7cc67b4 444
89d241a7 445 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
f7cc67b4
C
446 await waitJobs(servers)
447
29837f88
C
448 await checkNewActorFollow({
449 ...baseParams,
450 followType: 'channel',
451 followerName: 'root',
452 followerDisplayName: 'super root name',
453 followingDisplayName: myChannelName,
454 checkType: 'presence'
455 })
f7cc67b4 456
89d241a7 457 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
f7cc67b4
C
458 })
459
460 it('Should notify when a remote channel is following one of our channel', async function () {
59fd824c 461 this.timeout(50000)
f7cc67b4 462
89d241a7 463 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
f7cc67b4
C
464 await waitJobs(servers)
465
29837f88
C
466 await checkNewActorFollow({
467 ...baseParams,
468 followType: 'channel',
469 followerName: 'root',
470 followerDisplayName: 'super root 2 name',
471 followingDisplayName: myChannelName,
472 checkType: 'presence'
473 })
f7cc67b4 474
89d241a7 475 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
f7cc67b4
C
476 })
477
0dd57e4d
C
478 // PeerTube does not support accout -> account follows
479 // it('Should notify when a local account is following one of our channel', async function () {
59fd824c 480 // this.timeout(50000)
0dd57e4d
C
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 // })
f7cc67b4 488
6ed2e4ea 489 // it('Should notify when a remote account is following one of our channel', async function () {
59fd824c 490 // this.timeout(50000)
6ed2e4ea
C
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 // })
f7cc67b4
C
498 })
499
7c3b7976 500 after(async function () {
89ada4e2
C
501 MockSmtpServer.Instance.kill()
502
7c3b7976 503 await cleanupTests(servers)
cef534ed
C
504 })
505})