]>
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 C |
6 | import { |
7 | CheckerBaseParams, | |
f7cc67b4 C |
8 | checkMyVideoImportIsFinished, |
9 | checkNewActorFollow, | |
cef534ed | 10 | checkNewVideoFromSubscription, |
f7cc67b4 | 11 | checkVideoIsPublished, |
2c27e704 | 12 | cleanupTests, |
6910f20f | 13 | ImportsCommand, |
2c27e704 C |
14 | MockSmtpServer, |
15 | prepareNotificationsTest, | |
16 | ServerInfo, | |
17 | updateMyUser, | |
18 | updateVideo, | |
2c27e704 C |
19 | uploadRandomVideoOnServers, |
20 | wait, | |
21 | waitJobs | |
22 | } from '@shared/extra-utils' | |
2c27e704 | 23 | import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' |
cef534ed C |
24 | |
25 | const expect = chai.expect | |
26 | ||
8eb07b01 | 27 | describe('Test user notifications', function () { |
cef534ed C |
28 | let servers: ServerInfo[] = [] |
29 | let userAccessToken: string | |
8eb07b01 C |
30 | let userNotifications: UserNotification[] = [] |
31 | let adminNotifications: UserNotification[] = [] | |
32 | let adminNotificationsServer2: UserNotification[] = [] | |
33 | let emails: object[] = [] | |
dc133480 C |
34 | let channelId: number |
35 | ||
cef534ed C |
36 | before(async function () { |
37 | this.timeout(120000) | |
38 | ||
8eb07b01 C |
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 | |
cef534ed C |
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 () { | |
59fd824c | 62 | this.timeout(50000) |
f7effe8d | 63 | |
8eb07b01 | 64 | await uploadRandomVideoOnServers(servers, 1) |
cef534ed | 65 | |
dd0ebb71 | 66 | const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken }) |
cef534ed C |
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 () { | |
89ada4e2 | 74 | this.timeout(15000) |
2f1548fd | 75 | |
2c27e704 | 76 | await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) |
2f1548fd | 77 | await waitJobs(servers) |
cef534ed | 78 | |
8eb07b01 | 79 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) |
dc133480 | 80 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
cef534ed C |
81 | }) |
82 | ||
83 | it('Should send a new video notification from a remote account', async function () { | |
83befebe | 84 | this.timeout(150000) // Server 2 has transcoding enabled |
cef534ed | 85 | |
2c27e704 | 86 | await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) |
2f1548fd | 87 | await waitJobs(servers) |
cef534ed | 88 | |
8eb07b01 | 89 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) |
dc133480 | 90 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
cef534ed C |
91 | }) |
92 | ||
93 | it('Should send a new video notification on a scheduled publication', async function () { | |
59fd824c | 94 | this.timeout(50000) |
cef534ed | 95 | |
cef534ed | 96 | // In 2 seconds |
a1587156 | 97 | const updateAt = new Date(new Date().getTime() + 2000) |
cef534ed C |
98 | |
99 | const data = { | |
100 | privacy: VideoPrivacy.PRIVATE, | |
101 | scheduleUpdate: { | |
102 | updateAt: updateAt.toISOString(), | |
103 | privacy: VideoPrivacy.PUBLIC | |
104 | } | |
105 | } | |
8eb07b01 | 106 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
cef534ed C |
107 | |
108 | await wait(6000) | |
dc133480 | 109 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
cef534ed C |
110 | }) |
111 | ||
112 | it('Should send a new video notification on a remote scheduled publication', async function () { | |
8ace6805 | 113 | this.timeout(100000) |
cef534ed | 114 | |
cef534ed | 115 | // In 2 seconds |
a1587156 | 116 | const updateAt = new Date(new Date().getTime() + 2000) |
cef534ed C |
117 | |
118 | const data = { | |
119 | privacy: VideoPrivacy.PRIVATE, | |
120 | scheduleUpdate: { | |
121 | updateAt: updateAt.toISOString(), | |
122 | privacy: VideoPrivacy.PUBLIC | |
123 | } | |
124 | } | |
8eb07b01 | 125 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
e8d246d5 | 126 | await waitJobs(servers) |
cef534ed C |
127 | |
128 | await wait(6000) | |
dc133480 | 129 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
cef534ed C |
130 | }) |
131 | ||
132 | it('Should not send a notification before the video is published', async function () { | |
59fd824c | 133 | this.timeout(50000) |
cef534ed | 134 | |
a1587156 | 135 | const updateAt = new Date(new Date().getTime() + 1000000) |
cef534ed C |
136 | |
137 | const data = { | |
138 | privacy: VideoPrivacy.PRIVATE, | |
139 | scheduleUpdate: { | |
140 | updateAt: updateAt.toISOString(), | |
141 | privacy: VideoPrivacy.PUBLIC | |
142 | } | |
143 | } | |
8eb07b01 | 144 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
cef534ed C |
145 | |
146 | await wait(6000) | |
dc133480 | 147 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
cef534ed C |
148 | }) |
149 | ||
150 | it('Should send a new video notification when a video becomes public', async function () { | |
59fd824c | 151 | this.timeout(50000) |
cef534ed | 152 | |
cef534ed | 153 | const data = { privacy: VideoPrivacy.PRIVATE } |
8eb07b01 | 154 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
cef534ed | 155 | |
dc133480 | 156 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
cef534ed C |
157 | |
158 | await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) | |
159 | ||
9f39c546 | 160 | await waitJobs(servers) |
dc133480 | 161 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
cef534ed C |
162 | }) |
163 | ||
164 | it('Should send a new video notification when a remote video becomes public', async function () { | |
59fd824c | 165 | this.timeout(50000) |
cef534ed | 166 | |
cef534ed | 167 | const data = { privacy: VideoPrivacy.PRIVATE } |
8eb07b01 | 168 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
cef534ed | 169 | |
dc133480 | 170 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
cef534ed C |
171 | |
172 | await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) | |
173 | ||
174 | await waitJobs(servers) | |
dc133480 | 175 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
cef534ed C |
176 | }) |
177 | ||
178 | it('Should not send a new video notification when a video becomes unlisted', async function () { | |
59fd824c | 179 | this.timeout(50000) |
cef534ed | 180 | |
cef534ed | 181 | const data = { privacy: VideoPrivacy.PRIVATE } |
8eb07b01 | 182 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
cef534ed C |
183 | |
184 | await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) | |
185 | ||
dc133480 | 186 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
cef534ed C |
187 | }) |
188 | ||
189 | it('Should not send a new video notification when a remote video becomes unlisted', async function () { | |
59fd824c | 190 | this.timeout(50000) |
cef534ed | 191 | |
cef534ed | 192 | const data = { privacy: VideoPrivacy.PRIVATE } |
8eb07b01 | 193 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
cef534ed C |
194 | |
195 | await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) | |
196 | ||
197 | await waitJobs(servers) | |
dc133480 | 198 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
cef534ed C |
199 | }) |
200 | ||
201 | it('Should send a new video notification after a video import', async function () { | |
7ccddd7b | 202 | this.timeout(100000) |
cef534ed | 203 | |
d4a8e7a6 | 204 | const name = 'video import ' + buildUUID() |
cef534ed C |
205 | |
206 | const attributes = { | |
dc133480 | 207 | name, |
cef534ed C |
208 | channelId, |
209 | privacy: VideoPrivacy.PUBLIC, | |
6910f20f | 210 | targetUrl: ImportsCommand.getGoodVideoUrl() |
cef534ed | 211 | } |
6910f20f | 212 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
cef534ed C |
213 | |
214 | await waitJobs(servers) | |
215 | ||
6910f20f | 216 | await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence') |
cef534ed C |
217 | }) |
218 | }) | |
219 | ||
dc133480 C |
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 () { | |
59fd824c | 233 | this.timeout(50000) |
f7effe8d | 234 | |
8eb07b01 | 235 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) |
dc133480 C |
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 | ||
8eb07b01 | 244 | await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) |
dc133480 C |
245 | await waitJobs(servers) |
246 | ||
dd0ebb71 | 247 | const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken }) |
dc133480 C |
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 | ||
8eb07b01 | 256 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) |
dc133480 C |
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 | ||
8eb07b01 | 265 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) |
dc133480 C |
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 | ||
d4a8e7a6 | 274 | const name = 'video import ' + buildUUID() |
dc133480 C |
275 | |
276 | const attributes = { | |
277 | name, | |
278 | channelId, | |
279 | privacy: VideoPrivacy.PUBLIC, | |
6910f20f | 280 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
dc133480 C |
281 | waitTranscoding: true |
282 | } | |
6910f20f | 283 | const { video } = await servers[1].importsCommand.importVideo({ attributes }) |
dc133480 C |
284 | |
285 | await waitJobs(servers) | |
6910f20f | 286 | await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') |
dc133480 C |
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 | |
a1587156 | 293 | const updateAt = new Date(new Date().getTime() + 2000) |
dc133480 C |
294 | |
295 | const data = { | |
296 | privacy: VideoPrivacy.PRIVATE, | |
297 | scheduleUpdate: { | |
298 | updateAt: updateAt.toISOString(), | |
299 | privacy: VideoPrivacy.PUBLIC | |
300 | } | |
301 | } | |
8eb07b01 | 302 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
dc133480 C |
303 | |
304 | await wait(6000) | |
305 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | |
306 | }) | |
f7effe8d JM |
307 | |
308 | it('Should not send a notification before the video is published', async function () { | |
94d721ef | 309 | this.timeout(50000) |
f7effe8d | 310 | |
a1587156 | 311 | const updateAt = new Date(new Date().getTime() + 1000000) |
f7effe8d JM |
312 | |
313 | const data = { | |
314 | privacy: VideoPrivacy.PRIVATE, | |
315 | scheduleUpdate: { | |
316 | updateAt: updateAt.toISOString(), | |
317 | privacy: VideoPrivacy.PUBLIC | |
318 | } | |
319 | } | |
8eb07b01 | 320 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
f7effe8d JM |
321 | |
322 | await wait(6000) | |
323 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | |
324 | }) | |
dc133480 C |
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 | ||
d4a8e7a6 | 342 | const name = 'video import ' + buildUUID() |
dc133480 C |
343 | |
344 | const attributes = { | |
345 | name, | |
346 | channelId, | |
347 | privacy: VideoPrivacy.PRIVATE, | |
6910f20f | 348 | targetUrl: ImportsCommand.getBadVideoUrl() |
dc133480 | 349 | } |
6910f20f | 350 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
dc133480 C |
351 | |
352 | await waitJobs(servers) | |
6910f20f | 353 | await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') |
dc133480 C |
354 | }) |
355 | ||
356 | it('Should send a notification when the video import succeeded', async function () { | |
357 | this.timeout(70000) | |
358 | ||
d4a8e7a6 | 359 | const name = 'video import ' + buildUUID() |
dc133480 C |
360 | |
361 | const attributes = { | |
362 | name, | |
363 | channelId, | |
364 | privacy: VideoPrivacy.PRIVATE, | |
6910f20f | 365 | targetUrl: ImportsCommand.getGoodVideoUrl() |
dc133480 | 366 | } |
6910f20f | 367 | const { video } = await servers[0].importsCommand.importVideo({ attributes }) |
dc133480 C |
368 | |
369 | await waitJobs(servers) | |
6910f20f | 370 | await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') |
cef534ed C |
371 | }) |
372 | }) | |
373 | ||
f7cc67b4 C |
374 | describe('New actor follow', function () { |
375 | let baseParams: CheckerBaseParams | |
a1587156 C |
376 | const myChannelName = 'super channel name' |
377 | const myUserName = 'super user name' | |
f7cc67b4 C |
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 | ||
a5461888 C |
405 | await servers[0].channelsCommand.update({ |
406 | token: userAccessToken, | |
407 | channelName: 'user_1_channel', | |
408 | attributes: { displayName: myChannelName } | |
409 | }) | |
f7cc67b4 C |
410 | }) |
411 | ||
412 | it('Should notify when a local channel is following one of our channel', async function () { | |
59fd824c | 413 | this.timeout(50000) |
f7cc67b4 | 414 | |
2c27e704 | 415 | await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
f7cc67b4 C |
416 | await waitJobs(servers) |
417 | ||
418 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') | |
419 | ||
2c27e704 | 420 | await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
f7cc67b4 C |
421 | }) |
422 | ||
423 | it('Should notify when a remote channel is following one of our channel', async function () { | |
59fd824c | 424 | this.timeout(50000) |
f7cc67b4 | 425 | |
2c27e704 | 426 | await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
f7cc67b4 C |
427 | await waitJobs(servers) |
428 | ||
429 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') | |
430 | ||
2c27e704 | 431 | await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
f7cc67b4 C |
432 | }) |
433 | ||
0dd57e4d C |
434 | // PeerTube does not support accout -> account follows |
435 | // it('Should notify when a local account is following one of our channel', async function () { | |
59fd824c | 436 | // this.timeout(50000) |
0dd57e4d C |
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 | // }) | |
f7cc67b4 | 444 | |
6ed2e4ea | 445 | // it('Should notify when a remote account is following one of our channel', async function () { |
59fd824c | 446 | // this.timeout(50000) |
6ed2e4ea C |
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 | // }) | |
f7cc67b4 C |
454 | }) |
455 | ||
7c3b7976 | 456 | after(async function () { |
89ada4e2 C |
457 | MockSmtpServer.Instance.kill() |
458 | ||
7c3b7976 | 459 | await cleanupTests(servers) |
cef534ed C |
460 | }) |
461 | }) |