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