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