aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications/user-notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/notifications/user-notifications.ts')
-rw-r--r--server/tests/api/notifications/user-notifications.ts115
1 files changed, 49 insertions, 66 deletions
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index e981c1718..ca592d466 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -4,34 +4,26 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { buildUUID } from '@server/helpers/uuid' 5import { buildUUID } from '@server/helpers/uuid'
6import { 6import {
7 cleanupTests,
8 updateMyUser,
9 updateVideo,
10 updateVideoChannel,
11 uploadRandomVideoOnServers,
12 wait
13} from '../../../../shared/extra-utils'
14import { ServerInfo } from '../../../../shared/extra-utils/index'
15import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
16import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
17import {
18 CheckerBaseParams, 7 CheckerBaseParams,
19 checkMyVideoImportIsFinished, 8 checkMyVideoImportIsFinished,
20 checkNewActorFollow, 9 checkNewActorFollow,
21 checkNewVideoFromSubscription, 10 checkNewVideoFromSubscription,
22 checkVideoIsPublished, 11 checkVideoIsPublished,
23 getLastNotification, 12 cleanupTests,
24 prepareNotificationsTest 13 FIXTURE_URLS,
25} from '../../../../shared/extra-utils/users/user-notifications' 14 MockSmtpServer,
26import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 15 PeerTubeServer,
27import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 16 prepareNotificationsTest,
28import { UserNotification, UserNotificationType } from '../../../../shared/models/users' 17 uploadRandomVideoOnServers,
29import { VideoPrivacy } from '../../../../shared/models/videos' 18 wait,
19 waitJobs
20} from '@shared/extra-utils'
21import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
30 22
31const expect = chai.expect 23const expect = chai.expect
32 24
33describe('Test user notifications', function () { 25describe('Test user notifications', function () {
34 let servers: ServerInfo[] = [] 26 let servers: PeerTubeServer[] = []
35 let userAccessToken: string 27 let userAccessToken: string
36 let userNotifications: UserNotification[] = [] 28 let userNotifications: UserNotification[] = []
37 let adminNotifications: UserNotification[] = [] 29 let adminNotifications: UserNotification[] = []
@@ -69,7 +61,7 @@ describe('Test user notifications', function () {
69 61
70 await uploadRandomVideoOnServers(servers, 1) 62 await uploadRandomVideoOnServers(servers, 1)
71 63
72 const notification = await getLastNotification(servers[0].url, userAccessToken) 64 const notification = await servers[0].notifications.getLastest({ token: userAccessToken })
73 expect(notification).to.be.undefined 65 expect(notification).to.be.undefined
74 66
75 expect(emails).to.have.lengthOf(0) 67 expect(emails).to.have.lengthOf(0)
@@ -79,7 +71,7 @@ describe('Test user notifications', function () {
79 it('Should send a new video notification if the user follows the local video publisher', async function () { 71 it('Should send a new video notification if the user follows the local video publisher', async function () {
80 this.timeout(15000) 72 this.timeout(15000)
81 73
82 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) 74 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
83 await waitJobs(servers) 75 await waitJobs(servers)
84 76
85 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) 77 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
@@ -89,7 +81,7 @@ describe('Test user notifications', function () {
89 it('Should send a new video notification from a remote account', async function () { 81 it('Should send a new video notification from a remote account', async function () {
90 this.timeout(150000) // Server 2 has transcoding enabled 82 this.timeout(150000) // Server 2 has transcoding enabled
91 83
92 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) 84 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
93 await waitJobs(servers) 85 await waitJobs(servers)
94 86
95 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) 87 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2)
@@ -106,7 +98,7 @@ describe('Test user notifications', function () {
106 privacy: VideoPrivacy.PRIVATE, 98 privacy: VideoPrivacy.PRIVATE,
107 scheduleUpdate: { 99 scheduleUpdate: {
108 updateAt: updateAt.toISOString(), 100 updateAt: updateAt.toISOString(),
109 privacy: VideoPrivacy.PUBLIC 101 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
110 } 102 }
111 } 103 }
112 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 104 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
@@ -125,7 +117,7 @@ describe('Test user notifications', function () {
125 privacy: VideoPrivacy.PRIVATE, 117 privacy: VideoPrivacy.PRIVATE,
126 scheduleUpdate: { 118 scheduleUpdate: {
127 updateAt: updateAt.toISOString(), 119 updateAt: updateAt.toISOString(),
128 privacy: VideoPrivacy.PUBLIC 120 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
129 } 121 }
130 } 122 }
131 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 123 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@@ -144,7 +136,7 @@ describe('Test user notifications', function () {
144 privacy: VideoPrivacy.PRIVATE, 136 privacy: VideoPrivacy.PRIVATE,
145 scheduleUpdate: { 137 scheduleUpdate: {
146 updateAt: updateAt.toISOString(), 138 updateAt: updateAt.toISOString(),
147 privacy: VideoPrivacy.PUBLIC 139 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
148 } 140 }
149 } 141 }
150 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 142 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
@@ -161,7 +153,7 @@ describe('Test user notifications', function () {
161 153
162 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 154 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
163 155
164 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 156 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
165 157
166 await waitJobs(servers) 158 await waitJobs(servers)
167 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 159 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
@@ -175,7 +167,7 @@ describe('Test user notifications', function () {
175 167
176 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 168 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
177 169
178 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 170 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
179 171
180 await waitJobs(servers) 172 await waitJobs(servers)
181 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 173 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
@@ -187,7 +179,7 @@ describe('Test user notifications', function () {
187 const data = { privacy: VideoPrivacy.PRIVATE } 179 const data = { privacy: VideoPrivacy.PRIVATE }
188 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 180 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
189 181
190 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 182 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
191 183
192 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 184 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
193 }) 185 })
@@ -198,7 +190,7 @@ describe('Test user notifications', function () {
198 const data = { privacy: VideoPrivacy.PRIVATE } 190 const data = { privacy: VideoPrivacy.PRIVATE }
199 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 191 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
200 192
201 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 193 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
202 194
203 await waitJobs(servers) 195 await waitJobs(servers)
204 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 196 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
@@ -213,14 +205,13 @@ describe('Test user notifications', function () {
213 name, 205 name,
214 channelId, 206 channelId,
215 privacy: VideoPrivacy.PUBLIC, 207 privacy: VideoPrivacy.PUBLIC,
216 targetUrl: getGoodVideoUrl() 208 targetUrl: FIXTURE_URLS.goodVideo
217 } 209 }
218 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 210 const { video } = await servers[0].imports.importVideo({ attributes })
219 const uuid = res.body.video.uuid
220 211
221 await waitJobs(servers) 212 await waitJobs(servers)
222 213
223 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 214 await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
224 }) 215 })
225 }) 216 })
226 217
@@ -251,7 +242,7 @@ describe('Test user notifications', function () {
251 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) 242 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
252 await waitJobs(servers) 243 await waitJobs(servers)
253 244
254 const notification = await getLastNotification(servers[0].url, userAccessToken) 245 const notification = await servers[0].notifications.getLastest({ token: userAccessToken })
255 if (notification) { 246 if (notification) {
256 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) 247 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
257 } 248 }
@@ -284,14 +275,13 @@ describe('Test user notifications', function () {
284 name, 275 name,
285 channelId, 276 channelId,
286 privacy: VideoPrivacy.PUBLIC, 277 privacy: VideoPrivacy.PUBLIC,
287 targetUrl: getGoodVideoUrl(), 278 targetUrl: FIXTURE_URLS.goodVideo,
288 waitTranscoding: true 279 waitTranscoding: true
289 } 280 }
290 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 281 const { video } = await servers[1].imports.importVideo({ attributes })
291 const uuid = res.body.video.uuid
292 282
293 await waitJobs(servers) 283 await waitJobs(servers)
294 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 284 await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
295 }) 285 })
296 286
297 it('Should send a notification when the scheduled update has been proceeded', async function () { 287 it('Should send a notification when the scheduled update has been proceeded', async function () {
@@ -304,7 +294,7 @@ describe('Test user notifications', function () {
304 privacy: VideoPrivacy.PRIVATE, 294 privacy: VideoPrivacy.PRIVATE,
305 scheduleUpdate: { 295 scheduleUpdate: {
306 updateAt: updateAt.toISOString(), 296 updateAt: updateAt.toISOString(),
307 privacy: VideoPrivacy.PUBLIC 297 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
308 } 298 }
309 } 299 }
310 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 300 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@@ -322,7 +312,7 @@ describe('Test user notifications', function () {
322 privacy: VideoPrivacy.PRIVATE, 312 privacy: VideoPrivacy.PRIVATE,
323 scheduleUpdate: { 313 scheduleUpdate: {
324 updateAt: updateAt.toISOString(), 314 updateAt: updateAt.toISOString(),
325 privacy: VideoPrivacy.PUBLIC 315 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
326 } 316 }
327 } 317 }
328 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 318 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
@@ -353,13 +343,12 @@ describe('Test user notifications', function () {
353 name, 343 name,
354 channelId, 344 channelId,
355 privacy: VideoPrivacy.PRIVATE, 345 privacy: VideoPrivacy.PRIVATE,
356 targetUrl: getBadVideoUrl() 346 targetUrl: FIXTURE_URLS.badVideo
357 } 347 }
358 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 348 const { video } = await servers[0].imports.importVideo({ attributes })
359 const uuid = res.body.video.uuid
360 349
361 await waitJobs(servers) 350 await waitJobs(servers)
362 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') 351 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.badVideo, false, 'presence')
363 }) 352 })
364 353
365 it('Should send a notification when the video import succeeded', async function () { 354 it('Should send a notification when the video import succeeded', async function () {
@@ -371,13 +360,12 @@ describe('Test user notifications', function () {
371 name, 360 name,
372 channelId, 361 channelId,
373 privacy: VideoPrivacy.PRIVATE, 362 privacy: VideoPrivacy.PRIVATE,
374 targetUrl: getGoodVideoUrl() 363 targetUrl: FIXTURE_URLS.goodVideo
375 } 364 }
376 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 365 const { video } = await servers[0].imports.importVideo({ attributes })
377 const uuid = res.body.video.uuid
378 366
379 await waitJobs(servers) 367 await waitJobs(servers)
380 await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') 368 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.goodVideo, true, 'presence')
381 }) 369 })
382 }) 370 })
383 371
@@ -394,47 +382,42 @@ describe('Test user notifications', function () {
394 token: userAccessToken 382 token: userAccessToken
395 } 383 }
396 384
397 await updateMyUser({ 385 await servers[0].users.updateMe({ displayName: 'super root name' })
398 url: servers[0].url,
399 accessToken: servers[0].accessToken,
400 displayName: 'super root name'
401 })
402 386
403 await updateMyUser({ 387 await servers[0].users.updateMe({
404 url: servers[0].url, 388 token: userAccessToken,
405 accessToken: userAccessToken,
406 displayName: myUserName 389 displayName: myUserName
407 }) 390 })
408 391
409 await updateMyUser({ 392 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
410 url: servers[1].url,
411 accessToken: servers[1].accessToken,
412 displayName: 'super root 2 name'
413 })
414 393
415 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) 394 await servers[0].channels.update({
395 token: userAccessToken,
396 channelName: 'user_1_channel',
397 attributes: { displayName: myChannelName }
398 })
416 }) 399 })
417 400
418 it('Should notify when a local channel is following one of our channel', async function () { 401 it('Should notify when a local channel is following one of our channel', async function () {
419 this.timeout(50000) 402 this.timeout(50000)
420 403
421 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 404 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
422 await waitJobs(servers) 405 await waitJobs(servers)
423 406
424 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') 407 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
425 408
426 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 409 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
427 }) 410 })
428 411
429 it('Should notify when a remote channel is following one of our channel', async function () { 412 it('Should notify when a remote channel is following one of our channel', async function () {
430 this.timeout(50000) 413 this.timeout(50000)
431 414
432 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 415 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
433 await waitJobs(servers) 416 await waitJobs(servers)
434 417
435 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') 418 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
436 419
437 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 420 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
438 }) 421 })
439 422
440 // PeerTube does not support accout -> account follows 423 // PeerTube does not support accout -> account follows