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