diff options
Diffstat (limited to 'server/tests/api/notifications/moderation-notifications.ts')
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 288 |
1 files changed, 134 insertions, 154 deletions
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 3425480ae..eb3c29fe7 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -2,33 +2,6 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { buildUUID } from '@server/helpers/uuid' | 4 | import { buildUUID } from '@server/helpers/uuid' |
5 | import { AbuseState } from '@shared/models' | ||
6 | import { | ||
7 | addAbuseMessage, | ||
8 | addVideoCommentThread, | ||
9 | addVideoToBlacklist, | ||
10 | cleanupTests, | ||
11 | createUser, | ||
12 | follow, | ||
13 | generateUserAccessToken, | ||
14 | getAccount, | ||
15 | getCustomConfig, | ||
16 | getVideoCommentThreads, | ||
17 | getVideoIdFromUUID, | ||
18 | immutableAssign, | ||
19 | MockInstancesIndex, | ||
20 | registerUser, | ||
21 | removeVideoFromBlacklist, | ||
22 | reportAbuse, | ||
23 | unfollow, | ||
24 | updateAbuse, | ||
25 | updateCustomConfig, | ||
26 | updateCustomSubConfig, | ||
27 | wait | ||
28 | } from '../../../../shared/extra-utils' | ||
29 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | ||
30 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
32 | import { | 5 | import { |
33 | checkAbuseStateChange, | 6 | checkAbuseStateChange, |
34 | checkAutoInstanceFollowing, | 7 | checkAutoInstanceFollowing, |
@@ -43,15 +16,18 @@ import { | |||
43 | checkUserRegistered, | 16 | checkUserRegistered, |
44 | checkVideoAutoBlacklistForModerators, | 17 | checkVideoAutoBlacklistForModerators, |
45 | checkVideoIsPublished, | 18 | checkVideoIsPublished, |
46 | prepareNotificationsTest | 19 | cleanupTests, |
47 | } from '../../../../shared/extra-utils/users/user-notifications' | 20 | MockInstancesIndex, |
48 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | 21 | MockSmtpServer, |
49 | import { CustomConfig } from '../../../../shared/models/server' | 22 | PeerTubeServer, |
50 | import { UserNotification } from '../../../../shared/models/users' | 23 | prepareNotificationsTest, |
51 | import { VideoPrivacy } from '../../../../shared/models/videos' | 24 | wait, |
25 | waitJobs | ||
26 | } from '@shared/extra-utils' | ||
27 | import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' | ||
52 | 28 | ||
53 | describe('Test moderation notifications', function () { | 29 | describe('Test moderation notifications', function () { |
54 | let servers: ServerInfo[] = [] | 30 | let servers: PeerTubeServer[] = [] |
55 | let userAccessToken: string | 31 | let userAccessToken: string |
56 | let userNotifications: UserNotification[] = [] | 32 | let userNotifications: UserNotification[] = [] |
57 | let adminNotifications: UserNotification[] = [] | 33 | let adminNotifications: UserNotification[] = [] |
@@ -86,93 +62,97 @@ describe('Test moderation notifications', function () { | |||
86 | this.timeout(20000) | 62 | this.timeout(20000) |
87 | 63 | ||
88 | const name = 'video for abuse ' + buildUUID() | 64 | const name = 'video for abuse ' + buildUUID() |
89 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 65 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
90 | const video = resVideo.body.video | ||
91 | 66 | ||
92 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) | 67 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) |
93 | 68 | ||
94 | await waitJobs(servers) | 69 | await waitJobs(servers) |
95 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 70 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
96 | }) | 71 | }) |
97 | 72 | ||
98 | it('Should send a notification to moderators on remote video abuse', async function () { | 73 | it('Should send a notification to moderators on remote video abuse', async function () { |
99 | this.timeout(20000) | 74 | this.timeout(20000) |
100 | 75 | ||
101 | const name = 'video for abuse ' + buildUUID() | 76 | const name = 'video for abuse ' + buildUUID() |
102 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 77 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
103 | const video = resVideo.body.video | ||
104 | 78 | ||
105 | await waitJobs(servers) | 79 | await waitJobs(servers) |
106 | 80 | ||
107 | const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) | 81 | const videoId = await servers[1].videos.getId({ uuid: video.uuid }) |
108 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'super reason' }) | 82 | await servers[1].abuses.report({ videoId, reason: 'super reason' }) |
109 | 83 | ||
110 | await waitJobs(servers) | 84 | await waitJobs(servers) |
111 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 85 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
112 | }) | 86 | }) |
113 | 87 | ||
114 | it('Should send a notification to moderators on local comment abuse', async function () { | 88 | it('Should send a notification to moderators on local comment abuse', async function () { |
115 | this.timeout(20000) | 89 | this.timeout(20000) |
116 | 90 | ||
117 | const name = 'video for abuse ' + buildUUID() | 91 | const name = 'video for abuse ' + buildUUID() |
118 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 92 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
119 | const video = resVideo.body.video | 93 | const comment = await servers[0].comments.createThread({ |
120 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) | 94 | token: userAccessToken, |
121 | const comment = resComment.body.comment | 95 | videoId: video.id, |
96 | text: 'comment abuse ' + buildUUID() | ||
97 | }) | ||
122 | 98 | ||
123 | await waitJobs(servers) | 99 | await waitJobs(servers) |
124 | 100 | ||
125 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) | 101 | await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) |
126 | 102 | ||
127 | await waitJobs(servers) | 103 | await waitJobs(servers) |
128 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | 104 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
129 | }) | 105 | }) |
130 | 106 | ||
131 | it('Should send a notification to moderators on remote comment abuse', async function () { | 107 | it('Should send a notification to moderators on remote comment abuse', async function () { |
132 | this.timeout(20000) | 108 | this.timeout(20000) |
133 | 109 | ||
134 | const name = 'video for abuse ' + buildUUID() | 110 | const name = 'video for abuse ' + buildUUID() |
135 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 111 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
136 | const video = resVideo.body.video | 112 | |
137 | await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) | 113 | await servers[0].comments.createThread({ |
114 | token: userAccessToken, | ||
115 | videoId: video.id, | ||
116 | text: 'comment abuse ' + buildUUID() | ||
117 | }) | ||
138 | 118 | ||
139 | await waitJobs(servers) | 119 | await waitJobs(servers) |
140 | 120 | ||
141 | const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) | 121 | const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) |
142 | const commentId = resComments.body.data[0].id | 122 | const commentId = data[0].id |
143 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, commentId, reason: 'super reason' }) | 123 | await servers[1].abuses.report({ commentId, reason: 'super reason' }) |
144 | 124 | ||
145 | await waitJobs(servers) | 125 | await waitJobs(servers) |
146 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | 126 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
147 | }) | 127 | }) |
148 | 128 | ||
149 | it('Should send a notification to moderators on local account abuse', async function () { | 129 | it('Should send a notification to moderators on local account abuse', async function () { |
150 | this.timeout(20000) | 130 | this.timeout(20000) |
151 | 131 | ||
152 | const username = 'user' + new Date().getTime() | 132 | const username = 'user' + new Date().getTime() |
153 | const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) | 133 | const { account } = await servers[0].users.create({ username, password: 'donald' }) |
154 | const accountId = resUser.body.user.account.id | 134 | const accountId = account.id |
155 | 135 | ||
156 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId, reason: 'super reason' }) | 136 | await servers[0].abuses.report({ accountId, reason: 'super reason' }) |
157 | 137 | ||
158 | await waitJobs(servers) | 138 | await waitJobs(servers) |
159 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | 139 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
160 | }) | 140 | }) |
161 | 141 | ||
162 | it('Should send a notification to moderators on remote account abuse', async function () { | 142 | it('Should send a notification to moderators on remote account abuse', async function () { |
163 | this.timeout(20000) | 143 | this.timeout(20000) |
164 | 144 | ||
165 | const username = 'user' + new Date().getTime() | 145 | const username = 'user' + new Date().getTime() |
166 | const tmpToken = await generateUserAccessToken(servers[0], username) | 146 | const tmpToken = await servers[0].users.generateUserAndToken(username) |
167 | await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) | 147 | await servers[0].videos.upload({ token: tmpToken, attributes: { name: 'super video' } }) |
168 | 148 | ||
169 | await waitJobs(servers) | 149 | await waitJobs(servers) |
170 | 150 | ||
171 | const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) | 151 | const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) |
172 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, accountId: resAccount.body.id, reason: 'super reason' }) | 152 | await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) |
173 | 153 | ||
174 | await waitJobs(servers) | 154 | await waitJobs(servers) |
175 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | 155 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
176 | }) | 156 | }) |
177 | }) | 157 | }) |
178 | 158 | ||
@@ -189,29 +169,28 @@ describe('Test moderation notifications', function () { | |||
189 | } | 169 | } |
190 | 170 | ||
191 | const name = 'abuse ' + buildUUID() | 171 | const name = 'abuse ' + buildUUID() |
192 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 172 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
193 | const video = resVideo.body.video | ||
194 | 173 | ||
195 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 174 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) |
196 | abuseId = res.body.abuse.id | 175 | abuseId = body.abuse.id |
197 | }) | 176 | }) |
198 | 177 | ||
199 | it('Should send a notification to reporter if the abuse has been accepted', async function () { | 178 | it('Should send a notification to reporter if the abuse has been accepted', async function () { |
200 | this.timeout(10000) | 179 | this.timeout(10000) |
201 | 180 | ||
202 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.ACCEPTED }) | 181 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
203 | await waitJobs(servers) | 182 | await waitJobs(servers) |
204 | 183 | ||
205 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') | 184 | await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' }) |
206 | }) | 185 | }) |
207 | 186 | ||
208 | it('Should send a notification to reporter if the abuse has been rejected', async function () { | 187 | it('Should send a notification to reporter if the abuse has been rejected', async function () { |
209 | this.timeout(10000) | 188 | this.timeout(10000) |
210 | 189 | ||
211 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.REJECTED }) | 190 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } }) |
212 | await waitJobs(servers) | 191 | await waitJobs(servers) |
213 | 192 | ||
214 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') | 193 | await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' }) |
215 | }) | 194 | }) |
216 | }) | 195 | }) |
217 | 196 | ||
@@ -237,17 +216,16 @@ describe('Test moderation notifications', function () { | |||
237 | } | 216 | } |
238 | 217 | ||
239 | const name = 'abuse ' + buildUUID() | 218 | const name = 'abuse ' + buildUUID() |
240 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 219 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
241 | const video = resVideo.body.video | ||
242 | 220 | ||
243 | { | 221 | { |
244 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 222 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) |
245 | abuseId = res.body.abuse.id | 223 | abuseId = body.abuse.id |
246 | } | 224 | } |
247 | 225 | ||
248 | { | 226 | { |
249 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) | 227 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) |
250 | abuseId2 = res.body.abuse.id | 228 | abuseId2 = body.abuse.id |
251 | } | 229 | } |
252 | }) | 230 | }) |
253 | 231 | ||
@@ -255,40 +233,43 @@ describe('Test moderation notifications', function () { | |||
255 | this.timeout(10000) | 233 | this.timeout(10000) |
256 | 234 | ||
257 | const message = 'my super message to users' | 235 | const message = 'my super message to users' |
258 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) | 236 | await servers[0].abuses.addMessage({ abuseId, message }) |
259 | await waitJobs(servers) | 237 | await waitJobs(servers) |
260 | 238 | ||
261 | await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') | 239 | await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' }) |
262 | }) | 240 | }) |
263 | 241 | ||
264 | it('Should not send a notification to the admin if sent by the admin', async function () { | 242 | it('Should not send a notification to the admin if sent by the admin', async function () { |
265 | this.timeout(10000) | 243 | this.timeout(10000) |
266 | 244 | ||
267 | const message = 'my super message that should not be sent to the admin' | 245 | const message = 'my super message that should not be sent to the admin' |
268 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) | 246 | await servers[0].abuses.addMessage({ abuseId, message }) |
269 | await waitJobs(servers) | 247 | await waitJobs(servers) |
270 | 248 | ||
271 | await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') | 249 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
250 | await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' }) | ||
272 | }) | 251 | }) |
273 | 252 | ||
274 | it('Should send a notification to moderators', async function () { | 253 | it('Should send a notification to moderators', async function () { |
275 | this.timeout(10000) | 254 | this.timeout(10000) |
276 | 255 | ||
277 | const message = 'my super message to moderators' | 256 | const message = 'my super message to moderators' |
278 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) | 257 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) |
279 | await waitJobs(servers) | 258 | await waitJobs(servers) |
280 | 259 | ||
281 | await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') | 260 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
261 | await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' }) | ||
282 | }) | 262 | }) |
283 | 263 | ||
284 | it('Should not send a notification to reporter if sent by the reporter', async function () { | 264 | it('Should not send a notification to reporter if sent by the reporter', async function () { |
285 | this.timeout(10000) | 265 | this.timeout(10000) |
286 | 266 | ||
287 | const message = 'my super message that should not be sent to reporter' | 267 | const message = 'my super message that should not be sent to reporter' |
288 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) | 268 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) |
289 | await waitJobs(servers) | 269 | await waitJobs(servers) |
290 | 270 | ||
291 | await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') | 271 | const toEmail = 'user_1@example.com' |
272 | await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' }) | ||
292 | }) | 273 | }) |
293 | }) | 274 | }) |
294 | 275 | ||
@@ -308,30 +289,28 @@ describe('Test moderation notifications', function () { | |||
308 | this.timeout(10000) | 289 | this.timeout(10000) |
309 | 290 | ||
310 | const name = 'video for abuse ' + buildUUID() | 291 | const name = 'video for abuse ' + buildUUID() |
311 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 292 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
312 | const uuid = resVideo.body.video.uuid | ||
313 | 293 | ||
314 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | 294 | await servers[0].blacklist.add({ videoId: uuid }) |
315 | 295 | ||
316 | await waitJobs(servers) | 296 | await waitJobs(servers) |
317 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') | 297 | await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' }) |
318 | }) | 298 | }) |
319 | 299 | ||
320 | it('Should send a notification to video owner on unblacklist', async function () { | 300 | it('Should send a notification to video owner on unblacklist', async function () { |
321 | this.timeout(10000) | 301 | this.timeout(10000) |
322 | 302 | ||
323 | const name = 'video for abuse ' + buildUUID() | 303 | const name = 'video for abuse ' + buildUUID() |
324 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 304 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) |
325 | const uuid = resVideo.body.video.uuid | ||
326 | 305 | ||
327 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | 306 | await servers[0].blacklist.add({ videoId: uuid }) |
328 | 307 | ||
329 | await waitJobs(servers) | 308 | await waitJobs(servers) |
330 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | 309 | await servers[0].blacklist.remove({ videoId: uuid }) |
331 | await waitJobs(servers) | 310 | await waitJobs(servers) |
332 | 311 | ||
333 | await wait(500) | 312 | await wait(500) |
334 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') | 313 | await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) |
335 | }) | 314 | }) |
336 | }) | 315 | }) |
337 | 316 | ||
@@ -350,14 +329,14 @@ describe('Test moderation notifications', function () { | |||
350 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | 329 | it('Should send a notification only to moderators when a user registers on the instance', async function () { |
351 | this.timeout(10000) | 330 | this.timeout(10000) |
352 | 331 | ||
353 | await registerUser(servers[0].url, 'user_45', 'password') | 332 | await servers[0].users.register({ username: 'user_45' }) |
354 | 333 | ||
355 | await waitJobs(servers) | 334 | await waitJobs(servers) |
356 | 335 | ||
357 | await checkUserRegistered(baseParams, 'user_45', 'presence') | 336 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) |
358 | 337 | ||
359 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 338 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
360 | await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') | 339 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) |
361 | }) | 340 | }) |
362 | }) | 341 | }) |
363 | 342 | ||
@@ -392,20 +371,20 @@ describe('Test moderation notifications', function () { | |||
392 | it('Should send a notification only to admin when there is a new instance follower', async function () { | 371 | it('Should send a notification only to admin when there is a new instance follower', async function () { |
393 | this.timeout(20000) | 372 | this.timeout(20000) |
394 | 373 | ||
395 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | 374 | await servers[2].follows.follow({ hosts: [ servers[0].url ] }) |
396 | 375 | ||
397 | await waitJobs(servers) | 376 | await waitJobs(servers) |
398 | 377 | ||
399 | await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') | 378 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) |
400 | 379 | ||
401 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 380 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
402 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') | 381 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) |
403 | }) | 382 | }) |
404 | 383 | ||
405 | it('Should send a notification on auto follow back', async function () { | 384 | it('Should send a notification on auto follow back', async function () { |
406 | this.timeout(40000) | 385 | this.timeout(40000) |
407 | 386 | ||
408 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | 387 | await servers[2].follows.unfollow({ target: servers[0] }) |
409 | await waitJobs(servers) | 388 | await waitJobs(servers) |
410 | 389 | ||
411 | const config = { | 390 | const config = { |
@@ -415,41 +394,41 @@ describe('Test moderation notifications', function () { | |||
415 | } | 394 | } |
416 | } | 395 | } |
417 | } | 396 | } |
418 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | 397 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
419 | 398 | ||
420 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | 399 | await servers[2].follows.follow({ hosts: [ servers[0].url ] }) |
421 | 400 | ||
422 | await waitJobs(servers) | 401 | await waitJobs(servers) |
423 | 402 | ||
424 | const followerHost = servers[0].host | 403 | const followerHost = servers[0].host |
425 | const followingHost = servers[2].host | 404 | const followingHost = servers[2].host |
426 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | 405 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
427 | 406 | ||
428 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 407 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
429 | await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') | 408 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) |
430 | 409 | ||
431 | config.followings.instance.autoFollowBack.enabled = false | 410 | config.followings.instance.autoFollowBack.enabled = false |
432 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | 411 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
433 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | 412 | await servers[0].follows.unfollow({ target: servers[2] }) |
434 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | 413 | await servers[2].follows.unfollow({ target: servers[0] }) |
435 | }) | 414 | }) |
436 | 415 | ||
437 | it('Should send a notification on auto instances index follow', async function () { | 416 | it('Should send a notification on auto instances index follow', async function () { |
438 | this.timeout(30000) | 417 | this.timeout(30000) |
439 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | 418 | await servers[0].follows.unfollow({ target: servers[1] }) |
440 | 419 | ||
441 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | 420 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
442 | 421 | ||
443 | await wait(5000) | 422 | await wait(5000) |
444 | await waitJobs(servers) | 423 | await waitJobs(servers) |
445 | 424 | ||
446 | const followerHost = servers[0].host | 425 | const followerHost = servers[0].host |
447 | const followingHost = servers[1].host | 426 | const followingHost = servers[1].host |
448 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | 427 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
449 | 428 | ||
450 | config.followings.instance.autoFollowIndex.enabled = false | 429 | config.followings.instance.autoFollowIndex.enabled = false |
451 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | 430 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
452 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | 431 | await servers[0].follows.unfollow({ target: servers[1] }) |
453 | }) | 432 | }) |
454 | }) | 433 | }) |
455 | 434 | ||
@@ -457,7 +436,8 @@ describe('Test moderation notifications', function () { | |||
457 | let userBaseParams: CheckerBaseParams | 436 | let userBaseParams: CheckerBaseParams |
458 | let adminBaseParamsServer1: CheckerBaseParams | 437 | let adminBaseParamsServer1: CheckerBaseParams |
459 | let adminBaseParamsServer2: CheckerBaseParams | 438 | let adminBaseParamsServer2: CheckerBaseParams |
460 | let videoUUID: string | 439 | let uuid: string |
440 | let shortUUID: string | ||
461 | let videoName: string | 441 | let videoName: string |
462 | let currentCustomConfig: CustomConfig | 442 | let currentCustomConfig: CustomConfig |
463 | 443 | ||
@@ -484,9 +464,11 @@ describe('Test moderation notifications', function () { | |||
484 | token: userAccessToken | 464 | token: userAccessToken |
485 | } | 465 | } |
486 | 466 | ||
487 | const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) | 467 | currentCustomConfig = await servers[0].config.getCustomConfig() |
488 | currentCustomConfig = resCustomConfig.body | 468 | |
489 | const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { | 469 | const autoBlacklistTestsCustomConfig = { |
470 | ...currentCustomConfig, | ||
471 | |||
490 | autoBlacklist: { | 472 | autoBlacklist: { |
491 | videos: { | 473 | videos: { |
492 | ofUsers: { | 474 | ofUsers: { |
@@ -494,43 +476,44 @@ describe('Test moderation notifications', function () { | |||
494 | } | 476 | } |
495 | } | 477 | } |
496 | } | 478 | } |
497 | }) | 479 | } |
480 | |||
498 | // enable transcoding otherwise own publish notification after transcoding not expected | 481 | // enable transcoding otherwise own publish notification after transcoding not expected |
499 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | 482 | autoBlacklistTestsCustomConfig.transcoding.enabled = true |
500 | await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) | 483 | await servers[0].config.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) |
501 | |||
502 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
503 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
504 | 484 | ||
485 | await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | ||
486 | await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | ||
505 | }) | 487 | }) |
506 | 488 | ||
507 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | 489 | it('Should send notification to moderators on new video with auto-blacklist', async function () { |
508 | this.timeout(40000) | 490 | this.timeout(40000) |
509 | 491 | ||
510 | videoName = 'video with auto-blacklist ' + buildUUID() | 492 | videoName = 'video with auto-blacklist ' + buildUUID() |
511 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) | 493 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) |
512 | videoUUID = resVideo.body.video.uuid | 494 | shortUUID = video.shortUUID |
495 | uuid = video.uuid | ||
513 | 496 | ||
514 | await waitJobs(servers) | 497 | await waitJobs(servers) |
515 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | 498 | await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' }) |
516 | }) | 499 | }) |
517 | 500 | ||
518 | it('Should not send video publish notification if auto-blacklisted', async function () { | 501 | it('Should not send video publish notification if auto-blacklisted', async function () { |
519 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | 502 | await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' }) |
520 | }) | 503 | }) |
521 | 504 | ||
522 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | 505 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { |
523 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | 506 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' }) |
524 | }) | 507 | }) |
525 | 508 | ||
526 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | 509 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { |
527 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | 510 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' }) |
528 | }) | 511 | }) |
529 | 512 | ||
530 | it('Should send video published and unblacklist after video unblacklisted', async function () { | 513 | it('Should send video published and unblacklist after video unblacklisted', async function () { |
531 | this.timeout(40000) | 514 | this.timeout(40000) |
532 | 515 | ||
533 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) | 516 | await servers[0].blacklist.remove({ videoId: uuid }) |
534 | 517 | ||
535 | await waitJobs(servers) | 518 | await waitJobs(servers) |
536 | 519 | ||
@@ -541,11 +524,11 @@ describe('Test moderation notifications', function () { | |||
541 | }) | 524 | }) |
542 | 525 | ||
543 | it('Should send a local user subscription notification after removed from blacklist', async function () { | 526 | it('Should send a local user subscription notification after removed from blacklist', async function () { |
544 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | 527 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' }) |
545 | }) | 528 | }) |
546 | 529 | ||
547 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | 530 | it('Should send a remote user subscription notification after removed from blacklist', async function () { |
548 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | 531 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' }) |
549 | }) | 532 | }) |
550 | 533 | ||
551 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | 534 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { |
@@ -555,29 +538,28 @@ describe('Test moderation notifications', function () { | |||
555 | 538 | ||
556 | const name = 'video with auto-blacklist and future schedule ' + buildUUID() | 539 | const name = 'video with auto-blacklist and future schedule ' + buildUUID() |
557 | 540 | ||
558 | const data = { | 541 | const attributes = { |
559 | name, | 542 | name, |
560 | privacy: VideoPrivacy.PRIVATE, | 543 | privacy: VideoPrivacy.PRIVATE, |
561 | scheduleUpdate: { | 544 | scheduleUpdate: { |
562 | updateAt: updateAt.toISOString(), | 545 | updateAt: updateAt.toISOString(), |
563 | privacy: VideoPrivacy.PUBLIC | 546 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
564 | } | 547 | } |
565 | } | 548 | } |
566 | 549 | ||
567 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | 550 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) |
568 | const uuid = resVideo.body.video.uuid | ||
569 | 551 | ||
570 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | 552 | await servers[0].blacklist.remove({ videoId: uuid }) |
571 | 553 | ||
572 | await waitJobs(servers) | 554 | await waitJobs(servers) |
573 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | 555 | await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) |
574 | 556 | ||
575 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | 557 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one |
576 | // One notification might be better anyways | 558 | // One notification might be better anyways |
577 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | 559 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') |
578 | 560 | ||
579 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | 561 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) |
580 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | 562 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) |
581 | }) | 563 | }) |
582 | 564 | ||
583 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | 565 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { |
@@ -588,22 +570,21 @@ describe('Test moderation notifications', function () { | |||
588 | 570 | ||
589 | const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() | 571 | const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() |
590 | 572 | ||
591 | const data = { | 573 | const attributes = { |
592 | name, | 574 | name, |
593 | privacy: VideoPrivacy.PRIVATE, | 575 | privacy: VideoPrivacy.PRIVATE, |
594 | scheduleUpdate: { | 576 | scheduleUpdate: { |
595 | updateAt: updateAt.toISOString(), | 577 | updateAt: updateAt.toISOString(), |
596 | privacy: VideoPrivacy.PUBLIC | 578 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
597 | } | 579 | } |
598 | } | 580 | } |
599 | 581 | ||
600 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | 582 | const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) |
601 | const uuid = resVideo.body.video.uuid | ||
602 | 583 | ||
603 | await wait(6000) | 584 | await wait(6000) |
604 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | 585 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) |
605 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | 586 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) |
606 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | 587 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) |
607 | }) | 588 | }) |
608 | 589 | ||
609 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | 590 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { |
@@ -612,18 +593,17 @@ describe('Test moderation notifications', function () { | |||
612 | const name = 'video without auto-blacklist ' + buildUUID() | 593 | const name = 'video without auto-blacklist ' + buildUUID() |
613 | 594 | ||
614 | // admin with blacklist right will not be auto-blacklisted | 595 | // admin with blacklist right will not be auto-blacklisted |
615 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) | 596 | const { shortUUID } = await servers[0].videos.upload({ attributes: { name } }) |
616 | const uuid = resVideo.body.video.uuid | ||
617 | 597 | ||
618 | await waitJobs(servers) | 598 | await waitJobs(servers) |
619 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | 599 | await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' }) |
620 | }) | 600 | }) |
621 | 601 | ||
622 | after(async () => { | 602 | after(async () => { |
623 | await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) | 603 | await servers[0].config.updateCustomConfig({ newCustomConfig: currentCustomConfig }) |
624 | 604 | ||
625 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | 605 | await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
626 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | 606 | await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
627 | }) | 607 | }) |
628 | }) | 608 | }) |
629 | 609 | ||