aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/user-notifications.ts16
-rw-r--r--server/tests/api/users/user-notifications.ts401
2 files changed, 291 insertions, 126 deletions
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 3ae36ddb3..4f21f7b95 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -52,6 +52,18 @@ describe('Test user notifications API validators', function () {
52 await checkBadSortPagination(server.url, path, server.accessToken) 52 await checkBadSortPagination(server.url, path, server.accessToken)
53 }) 53 })
54 54
55 it('Should fail with an incorrect unread parameter', async function () {
56 await makeGetRequest({
57 url: server.url,
58 path,
59 query: {
60 unread: 'toto'
61 },
62 token: server.accessToken,
63 statusCodeExpected: 200
64 })
65 })
66
55 it('Should fail with a non authenticated user', async function () { 67 it('Should fail with a non authenticated user', async function () {
56 await makeGetRequest({ 68 await makeGetRequest({
57 url: server.url, 69 url: server.url,
@@ -125,7 +137,9 @@ describe('Test user notifications API validators', function () {
125 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION, 137 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION,
126 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, 138 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION,
127 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION, 139 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION,
128 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION 140 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION,
141 myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION,
142 myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION
129 } 143 }
130 144
131 it('Should fail with missing fields', async function () { 145 it('Should fail with missing fields', async function () {
diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts
index 09c0479fd..e4966dbf5 100644
--- a/server/tests/api/users/user-notifications.ts
+++ b/server/tests/api/users/user-notifications.ts
@@ -29,33 +29,46 @@ import {
29 getLastNotification, 29 getLastNotification,
30 getUserNotifications, 30 getUserNotifications,
31 markAsReadNotifications, 31 markAsReadNotifications,
32 updateMyNotificationSettings 32 updateMyNotificationSettings,
33 checkVideoIsPublished, checkMyVideoImportIsFinished
33} from '../../../../shared/utils/users/user-notifications' 34} from '../../../../shared/utils/users/user-notifications'
34import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' 35import {
36 User,
37 UserNotification,
38 UserNotificationSetting,
39 UserNotificationSettingValue,
40 UserNotificationType
41} from '../../../../shared/models/users'
35import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 42import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
36import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions' 43import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
37import { VideoPrivacy } from '../../../../shared/models/videos' 44import { VideoPrivacy } from '../../../../shared/models/videos'
38import { getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' 45import { getYoutubeVideoUrl, importVideo, getBadVideoUrl } from '../../../../shared/utils/videos/video-imports'
39import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' 46import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
47import * as uuidv4 from 'uuid/v4'
48import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
40 49
41const expect = chai.expect 50const expect = chai.expect
42 51
43async function uploadVideoByRemoteAccount (servers: ServerInfo[], videoNameId: number, additionalParams: any = {}) { 52async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
44 const data = Object.assign({ name: 'remote video ' + videoNameId }, additionalParams) 53 const name = 'remote video ' + uuidv4()
54
55 const data = Object.assign({ name }, additionalParams)
45 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data) 56 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
46 57
47 await waitJobs(servers) 58 await waitJobs(servers)
48 59
49 return res.body.video.uuid 60 return { uuid: res.body.video.uuid, name }
50} 61}
51 62
52async function uploadVideoByLocalAccount (servers: ServerInfo[], videoNameId: number, additionalParams: any = {}) { 63async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
53 const data = Object.assign({ name: 'local video ' + videoNameId }, additionalParams) 64 const name = 'local video ' + uuidv4()
65
66 const data = Object.assign({ name }, additionalParams)
54 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data) 67 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
55 68
56 await waitJobs(servers) 69 await waitJobs(servers)
57 70
58 return res.body.video.uuid 71 return { uuid: res.body.video.uuid, name }
59} 72}
60 73
61describe('Test users notifications', function () { 74describe('Test users notifications', function () {
@@ -63,7 +76,18 @@ describe('Test users notifications', function () {
63 let userAccessToken: string 76 let userAccessToken: string
64 let userNotifications: UserNotification[] = [] 77 let userNotifications: UserNotification[] = []
65 let adminNotifications: UserNotification[] = [] 78 let adminNotifications: UserNotification[] = []
79 let adminNotificationsServer2: UserNotification[] = []
66 const emails: object[] = [] 80 const emails: object[] = []
81 let channelId: number
82
83 const allNotificationSettings: UserNotificationSetting = {
84 myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
85 myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
86 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
87 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
88 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
89 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
90 }
67 91
68 before(async function () { 92 before(async function () {
69 this.timeout(120000) 93 this.timeout(120000)
@@ -94,12 +118,9 @@ describe('Test users notifications', function () {
94 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000) 118 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
95 userAccessToken = await userLogin(servers[0], user) 119 userAccessToken = await userLogin(servers[0], user)
96 120
97 await updateMyNotificationSettings(servers[0].url, userAccessToken, { 121 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
98 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, 122 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
99 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, 123 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
100 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
101 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
102 })
103 124
104 { 125 {
105 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken) 126 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
@@ -109,6 +130,15 @@ describe('Test users notifications', function () {
109 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken) 130 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
110 socket.on('new-notification', n => adminNotifications.push(n)) 131 socket.on('new-notification', n => adminNotifications.push(n))
111 } 132 }
133 {
134 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
135 socket.on('new-notification', n => adminNotificationsServer2.push(n))
136 }
137
138 {
139 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
140 channelId = resChannel.body.videoChannels[0].id
141 }
112 }) 142 })
113 143
114 describe('New video from my subscription notification', function () { 144 describe('New video from my subscription notification', function () {
@@ -124,7 +154,7 @@ describe('Test users notifications', function () {
124 }) 154 })
125 155
126 it('Should not send notifications if the user does not follow the video publisher', async function () { 156 it('Should not send notifications if the user does not follow the video publisher', async function () {
127 await uploadVideoByLocalAccount(servers, 1) 157 await uploadVideoByLocalAccount(servers)
128 158
129 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) 159 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
130 expect(notification).to.be.undefined 160 expect(notification).to.be.undefined
@@ -136,11 +166,8 @@ describe('Test users notifications', function () {
136 it('Should send a new video notification if the user follows the local video publisher', async function () { 166 it('Should send a new video notification if the user follows the local video publisher', async function () {
137 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') 167 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
138 168
139 const videoNameId = 10 169 const { name, uuid } = await uploadVideoByLocalAccount(servers)
140 const videoName = 'local video ' + videoNameId 170 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
141
142 const uuid = await uploadVideoByLocalAccount(servers, videoNameId)
143 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence')
144 }) 171 })
145 172
146 it('Should send a new video notification from a remote account', async function () { 173 it('Should send a new video notification from a remote account', async function () {
@@ -148,21 +175,13 @@ describe('Test users notifications', function () {
148 175
149 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002') 176 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
150 177
151 const videoNameId = 20 178 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
152 const videoName = 'remote video ' + videoNameId 179 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
153
154 const uuid = await uploadVideoByRemoteAccount(servers, videoNameId)
155 await waitJobs(servers)
156
157 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence')
158 }) 180 })
159 181
160 it('Should send a new video notification on a scheduled publication', async function () { 182 it('Should send a new video notification on a scheduled publication', async function () {
161 this.timeout(20000) 183 this.timeout(20000)
162 184
163 const videoNameId = 30
164 const videoName = 'local video ' + videoNameId
165
166 // In 2 seconds 185 // In 2 seconds
167 let updateAt = new Date(new Date().getTime() + 2000) 186 let updateAt = new Date(new Date().getTime() + 2000)
168 187
@@ -173,18 +192,15 @@ describe('Test users notifications', function () {
173 privacy: VideoPrivacy.PUBLIC 192 privacy: VideoPrivacy.PUBLIC
174 } 193 }
175 } 194 }
176 const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) 195 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
177 196
178 await wait(6000) 197 await wait(6000)
179 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') 198 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
180 }) 199 })
181 200
182 it('Should send a new video notification on a remote scheduled publication', async function () { 201 it('Should send a new video notification on a remote scheduled publication', async function () {
183 this.timeout(20000) 202 this.timeout(20000)
184 203
185 const videoNameId = 40
186 const videoName = 'remote video ' + videoNameId
187
188 // In 2 seconds 204 // In 2 seconds
189 let updateAt = new Date(new Date().getTime() + 2000) 205 let updateAt = new Date(new Date().getTime() + 2000)
190 206
@@ -195,19 +211,16 @@ describe('Test users notifications', function () {
195 privacy: VideoPrivacy.PUBLIC 211 privacy: VideoPrivacy.PUBLIC
196 } 212 }
197 } 213 }
198 const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) 214 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
199 await waitJobs(servers) 215 await waitJobs(servers)
200 216
201 await wait(6000) 217 await wait(6000)
202 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') 218 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
203 }) 219 })
204 220
205 it('Should not send a notification before the video is published', async function () { 221 it('Should not send a notification before the video is published', async function () {
206 this.timeout(20000) 222 this.timeout(20000)
207 223
208 const videoNameId = 50
209 const videoName = 'local video ' + videoNameId
210
211 let updateAt = new Date(new Date().getTime() + 100000) 224 let updateAt = new Date(new Date().getTime() + 100000)
212 225
213 const data = { 226 const data = {
@@ -217,86 +230,70 @@ describe('Test users notifications', function () {
217 privacy: VideoPrivacy.PUBLIC 230 privacy: VideoPrivacy.PUBLIC
218 } 231 }
219 } 232 }
220 const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) 233 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
221 234
222 await wait(6000) 235 await wait(6000)
223 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') 236 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
224 }) 237 })
225 238
226 it('Should send a new video notification when a video becomes public', async function () { 239 it('Should send a new video notification when a video becomes public', async function () {
227 this.timeout(10000) 240 this.timeout(10000)
228 241
229 const videoNameId = 60
230 const videoName = 'local video ' + videoNameId
231
232 const data = { privacy: VideoPrivacy.PRIVATE } 242 const data = { privacy: VideoPrivacy.PRIVATE }
233 const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) 243 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
234 244
235 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') 245 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
236 246
237 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 247 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
238 248
239 await wait(500) 249 await wait(500)
240 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') 250 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
241 }) 251 })
242 252
243 it('Should send a new video notification when a remote video becomes public', async function () { 253 it('Should send a new video notification when a remote video becomes public', async function () {
244 this.timeout(20000) 254 this.timeout(20000)
245 255
246 const videoNameId = 70
247 const videoName = 'remote video ' + videoNameId
248
249 const data = { privacy: VideoPrivacy.PRIVATE } 256 const data = { privacy: VideoPrivacy.PRIVATE }
250 const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) 257 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
251 await waitJobs(servers)
252 258
253 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') 259 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
254 260
255 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 261 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
256 262
257 await waitJobs(servers) 263 await waitJobs(servers)
258 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') 264 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
259 }) 265 })
260 266
261 it('Should not send a new video notification when a video becomes unlisted', async function () { 267 it('Should not send a new video notification when a video becomes unlisted', async function () {
262 this.timeout(20000) 268 this.timeout(20000)
263 269
264 const videoNameId = 80
265 const videoName = 'local video ' + videoNameId
266
267 const data = { privacy: VideoPrivacy.PRIVATE } 270 const data = { privacy: VideoPrivacy.PRIVATE }
268 const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) 271 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
269 272
270 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 273 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
271 274
272 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') 275 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
273 }) 276 })
274 277
275 it('Should not send a new video notification when a remote video becomes unlisted', async function () { 278 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
276 this.timeout(20000) 279 this.timeout(20000)
277 280
278 const videoNameId = 90
279 const videoName = 'remote video ' + videoNameId
280
281 const data = { privacy: VideoPrivacy.PRIVATE } 281 const data = { privacy: VideoPrivacy.PRIVATE }
282 const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) 282 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
283 await waitJobs(servers)
284 283
285 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 284 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
286 285
287 await waitJobs(servers) 286 await waitJobs(servers)
288 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') 287 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
289 }) 288 })
290 289
291 it('Should send a new video notification after a video import', async function () { 290 it('Should send a new video notification after a video import', async function () {
292 this.timeout(30000) 291 this.timeout(30000)
293 292
294 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) 293 const name = 'video import ' + uuidv4()
295 const channelId = resChannel.body.videoChannels[0].id
296 const videoName = 'local video 100'
297 294
298 const attributes = { 295 const attributes = {
299 name: videoName, 296 name,
300 channelId, 297 channelId,
301 privacy: VideoPrivacy.PUBLIC, 298 privacy: VideoPrivacy.PUBLIC,
302 targetUrl: getYoutubeVideoUrl() 299 targetUrl: getYoutubeVideoUrl()
@@ -306,7 +303,7 @@ describe('Test users notifications', function () {
306 303
307 await waitJobs(servers) 304 await waitJobs(servers)
308 305
309 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') 306 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
310 }) 307 })
311 }) 308 })
312 309
@@ -348,6 +345,23 @@ describe('Test users notifications', function () {
348 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') 345 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
349 }) 346 })
350 347
348 it('Should not send a new comment notification if the account is muted', async function () {
349 this.timeout(10000)
350
351 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
352
353 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
354 const uuid = resVideo.body.video.uuid
355
356 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
357 const commentId = resComment.body.comment.id
358
359 await wait(500)
360 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
361
362 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
363 })
364
351 it('Should send a new comment notification after a local comment on my video', async function () { 365 it('Should send a new comment notification after a local comment on my video', async function () {
352 this.timeout(10000) 366 this.timeout(10000)
353 367
@@ -425,23 +439,21 @@ describe('Test users notifications', function () {
425 it('Should send a notification to moderators on local video abuse', async function () { 439 it('Should send a notification to moderators on local video abuse', async function () {
426 this.timeout(10000) 440 this.timeout(10000)
427 441
428 const videoName = 'local video 110' 442 const name = 'video for abuse ' + uuidv4()
429 443 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
430 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
431 const uuid = resVideo.body.video.uuid 444 const uuid = resVideo.body.video.uuid
432 445
433 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') 446 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
434 447
435 await waitJobs(servers) 448 await waitJobs(servers)
436 await checkNewVideoAbuseForModerators(baseParams, uuid, videoName, 'presence') 449 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
437 }) 450 })
438 451
439 it('Should send a notification to moderators on remote video abuse', async function () { 452 it('Should send a notification to moderators on remote video abuse', async function () {
440 this.timeout(10000) 453 this.timeout(10000)
441 454
442 const videoName = 'remote video 120' 455 const name = 'video for abuse ' + uuidv4()
443 456 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
444 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
445 const uuid = resVideo.body.video.uuid 457 const uuid = resVideo.body.video.uuid
446 458
447 await waitJobs(servers) 459 await waitJobs(servers)
@@ -449,7 +461,7 @@ describe('Test users notifications', function () {
449 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') 461 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
450 462
451 await waitJobs(servers) 463 await waitJobs(servers)
452 await checkNewVideoAbuseForModerators(baseParams, uuid, videoName, 'presence') 464 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
453 }) 465 })
454 }) 466 })
455 467
@@ -468,23 +480,21 @@ describe('Test users notifications', function () {
468 it('Should send a notification to video owner on blacklist', async function () { 480 it('Should send a notification to video owner on blacklist', async function () {
469 this.timeout(10000) 481 this.timeout(10000)
470 482
471 const videoName = 'local video 130' 483 const name = 'video for abuse ' + uuidv4()
472 484 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
473 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
474 const uuid = resVideo.body.video.uuid 485 const uuid = resVideo.body.video.uuid
475 486
476 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) 487 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
477 488
478 await waitJobs(servers) 489 await waitJobs(servers)
479 await checkNewBlacklistOnMyVideo(baseParams, uuid, videoName, 'blacklist') 490 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
480 }) 491 })
481 492
482 it('Should send a notification to video owner on unblacklist', async function () { 493 it('Should send a notification to video owner on unblacklist', async function () {
483 this.timeout(10000) 494 this.timeout(10000)
484 495
485 const videoName = 'local video 130' 496 const name = 'video for abuse ' + uuidv4()
486 497 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
487 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
488 const uuid = resVideo.body.video.uuid 498 const uuid = resVideo.body.video.uuid
489 499
490 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) 500 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
@@ -494,38 +504,187 @@ describe('Test users notifications', function () {
494 await waitJobs(servers) 504 await waitJobs(servers)
495 505
496 await wait(500) 506 await wait(500)
497 await checkNewBlacklistOnMyVideo(baseParams, uuid, videoName, 'unblacklist') 507 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
508 })
509 })
510
511 describe('My video is published', function () {
512 let baseParams: CheckerBaseParams
513
514 before(() => {
515 baseParams = {
516 server: servers[1],
517 emails,
518 socketNotifications: adminNotificationsServer2,
519 token: servers[1].accessToken
520 }
521 })
522
523 it('Should not send a notification if transcoding is not enabled', async function () {
524 const { name, uuid } = await uploadVideoByLocalAccount(servers)
525 await waitJobs(servers)
526
527 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
528 })
529
530 it('Should not send a notification if the wait transcoding is false', async function () {
531 this.timeout(50000)
532
533 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
534 await waitJobs(servers)
535
536 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
537 if (notification) {
538 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
539 }
540 })
541
542 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
543 this.timeout(50000)
544
545 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
546 await waitJobs(servers)
547
548 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
549 })
550
551 it('Should send a notification with a transcoded video', async function () {
552 this.timeout(50000)
553
554 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
555 await waitJobs(servers)
556
557 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
558 })
559
560 it('Should send a notification when an imported video is transcoded', async function () {
561 this.timeout(50000)
562
563 const name = 'video import ' + uuidv4()
564
565 const attributes = {
566 name,
567 channelId,
568 privacy: VideoPrivacy.PUBLIC,
569 targetUrl: getYoutubeVideoUrl(),
570 waitTranscoding: true
571 }
572 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
573 const uuid = res.body.video.uuid
574
575 await waitJobs(servers)
576 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
577 })
578
579 it('Should send a notification when the scheduled update has been proceeded', async function () {
580 this.timeout(70000)
581
582 // In 2 seconds
583 let updateAt = new Date(new Date().getTime() + 2000)
584
585 const data = {
586 privacy: VideoPrivacy.PRIVATE,
587 scheduleUpdate: {
588 updateAt: updateAt.toISOString(),
589 privacy: VideoPrivacy.PUBLIC
590 }
591 }
592 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
593
594 await wait(6000)
595 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
596 })
597 })
598
599 describe('My video is imported', function () {
600 let baseParams: CheckerBaseParams
601
602 before(() => {
603 baseParams = {
604 server: servers[0],
605 emails,
606 socketNotifications: adminNotifications,
607 token: servers[0].accessToken
608 }
609 })
610
611 it('Should send a notification when the video import failed', async function () {
612 this.timeout(70000)
613
614 const name = 'video import ' + uuidv4()
615
616 const attributes = {
617 name,
618 channelId,
619 privacy: VideoPrivacy.PRIVATE,
620 targetUrl: getBadVideoUrl()
621 }
622 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
623 const uuid = res.body.video.uuid
624
625 await waitJobs(servers)
626 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
627 })
628
629 it('Should send a notification when the video import succeeded', async function () {
630 this.timeout(70000)
631
632 const name = 'video import ' + uuidv4()
633
634 const attributes = {
635 name,
636 channelId,
637 privacy: VideoPrivacy.PRIVATE,
638 targetUrl: getYoutubeVideoUrl()
639 }
640 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
641 const uuid = res.body.video.uuid
642
643 await waitJobs(servers)
644 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
498 }) 645 })
499 }) 646 })
500 647
501 describe('Mark as read', function () { 648 describe('Mark as read', function () {
502 it('Should mark as read some notifications', async function () { 649 it('Should mark as read some notifications', async function () {
503 const res = await getUserNotifications(servers[0].url, userAccessToken, 2, 3) 650 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
504 const ids = res.body.data.map(n => n.id) 651 const ids = res.body.data.map(n => n.id)
505 652
506 await markAsReadNotifications(servers[0].url, userAccessToken, ids) 653 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
507 }) 654 })
508 655
509 it('Should have the notifications marked as read', async function () { 656 it('Should have the notifications marked as read', async function () {
510 const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10) 657 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
658
659 const notifications = res.body.data as UserNotification[]
660 expect(notifications[ 0 ].read).to.be.false
661 expect(notifications[ 1 ].read).to.be.false
662 expect(notifications[ 2 ].read).to.be.true
663 expect(notifications[ 3 ].read).to.be.true
664 expect(notifications[ 4 ].read).to.be.true
665 expect(notifications[ 5 ].read).to.be.false
666 })
667
668 it('Should only list read notifications', async function () {
669 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
511 670
512 const notifications = res.body.data as UserNotification[] 671 const notifications = res.body.data as UserNotification[]
513 expect(notifications[0].read).to.be.false 672 for (const notification of notifications) {
514 expect(notifications[1].read).to.be.false 673 expect(notification.read).to.be.true
515 expect(notifications[2].read).to.be.true 674 }
516 expect(notifications[3].read).to.be.true 675 })
517 expect(notifications[4].read).to.be.true 676
518 expect(notifications[5].read).to.be.false 677 it('Should only list unread notifications', async function () {
678 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
679
680 const notifications = res.body.data as UserNotification[]
681 for (const notification of notifications) {
682 expect(notification.read).to.be.false
683 }
519 }) 684 })
520 }) 685 })
521 686
522 describe('Notification settings', function () { 687 describe('Notification settings', function () {
523 const baseUpdateNotificationParams = {
524 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
525 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
526 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
527 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
528 }
529 let baseParams: CheckerBaseParams 688 let baseParams: CheckerBaseParams
530 689
531 before(() => { 690 before(() => {
@@ -538,7 +697,7 @@ describe('Test users notifications', function () {
538 }) 697 })
539 698
540 it('Should not have notifications', async function () { 699 it('Should not have notifications', async function () {
541 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { 700 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
542 newVideoFromSubscription: UserNotificationSettingValue.NONE 701 newVideoFromSubscription: UserNotificationSettingValue.NONE
543 })) 702 }))
544 703
@@ -548,16 +707,14 @@ describe('Test users notifications', function () {
548 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 707 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
549 } 708 }
550 709
551 const videoNameId = 42 710 const { name, uuid } = await uploadVideoByLocalAccount(servers)
552 const videoName = 'local video ' + videoNameId
553 const uuid = await uploadVideoByLocalAccount(servers, videoNameId)
554 711
555 const check = { web: true, mail: true } 712 const check = { web: true, mail: true }
556 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') 713 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
557 }) 714 })
558 715
559 it('Should only have web notifications', async function () { 716 it('Should only have web notifications', async function () {
560 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { 717 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
561 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION 718 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION
562 })) 719 }))
563 720
@@ -567,23 +724,21 @@ describe('Test users notifications', function () {
567 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION) 724 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION)
568 } 725 }
569 726
570 const videoNameId = 52 727 const { name, uuid } = await uploadVideoByLocalAccount(servers)
571 const videoName = 'local video ' + videoNameId
572 const uuid = await uploadVideoByLocalAccount(servers, videoNameId)
573 728
574 { 729 {
575 const check = { mail: true, web: false } 730 const check = { mail: true, web: false }
576 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') 731 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
577 } 732 }
578 733
579 { 734 {
580 const check = { mail: false, web: true } 735 const check = { mail: false, web: true }
581 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'presence') 736 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
582 } 737 }
583 }) 738 })
584 739
585 it('Should only have mail notifications', async function () { 740 it('Should only have mail notifications', async function () {
586 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { 741 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
587 newVideoFromSubscription: UserNotificationSettingValue.EMAIL 742 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
588 })) 743 }))
589 744
@@ -593,23 +748,21 @@ describe('Test users notifications', function () {
593 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 748 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
594 } 749 }
595 750
596 const videoNameId = 62 751 const { name, uuid } = await uploadVideoByLocalAccount(servers)
597 const videoName = 'local video ' + videoNameId
598 const uuid = await uploadVideoByLocalAccount(servers, videoNameId)
599 752
600 { 753 {
601 const check = { mail: false, web: true } 754 const check = { mail: false, web: true }
602 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') 755 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
603 } 756 }
604 757
605 { 758 {
606 const check = { mail: true, web: false } 759 const check = { mail: true, web: false }
607 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'presence') 760 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
608 } 761 }
609 }) 762 })
610 763
611 it('Should have email and web notifications', async function () { 764 it('Should have email and web notifications', async function () {
612 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { 765 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
613 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL 766 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
614 })) 767 }))
615 768
@@ -619,11 +772,9 @@ describe('Test users notifications', function () {
619 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL) 772 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL)
620 } 773 }
621 774
622 const videoNameId = 72 775 const { name, uuid } = await uploadVideoByLocalAccount(servers)
623 const videoName = 'local video ' + videoNameId
624 const uuid = await uploadVideoByLocalAccount(servers, videoNameId)
625 776
626 await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') 777 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
627 }) 778 })
628 }) 779 })
629 780