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