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