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