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