diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/abuses.ts | 146 | ||||
-rw-r--r-- | server/tests/api/moderation/abuses.ts | 631 | ||||
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 88 | ||||
-rw-r--r-- | server/tests/api/server/email.ts | 3 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 28 |
5 files changed, 415 insertions, 481 deletions
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 2054776cc..e158e50dc 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts | |||
@@ -1,46 +1,40 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { AbuseCreate, AbuseState } from '@shared/models' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
5 | import { | 5 | import { |
6 | addAbuseMessage, | 6 | AbusesCommand, |
7 | checkBadCountPagination, | ||
8 | checkBadSortPagination, | ||
9 | checkBadStartPagination, | ||
7 | cleanupTests, | 10 | cleanupTests, |
8 | createUser, | 11 | createUser, |
9 | deleteAbuse, | ||
10 | deleteAbuseMessage, | ||
11 | doubleFollow, | 12 | doubleFollow, |
12 | flushAndRunServer, | 13 | flushAndRunServer, |
13 | generateUserAccessToken, | 14 | generateUserAccessToken, |
14 | getAdminAbusesList, | ||
15 | getVideoIdFromUUID, | 15 | getVideoIdFromUUID, |
16 | listAbuseMessages, | ||
17 | makeGetRequest, | 16 | makeGetRequest, |
18 | makePostBodyRequest, | 17 | makePostBodyRequest, |
19 | reportAbuse, | ||
20 | ServerInfo, | 18 | ServerInfo, |
21 | setAccessTokensToServers, | 19 | setAccessTokensToServers, |
22 | updateAbuse, | ||
23 | uploadVideo, | 20 | uploadVideo, |
24 | userLogin, | 21 | userLogin, |
25 | waitJobs | 22 | waitJobs |
26 | } from '../../../../shared/extra-utils' | 23 | } from '@shared/extra-utils' |
27 | import { | 24 | import { AbuseCreate, AbuseState } from '@shared/models' |
28 | checkBadCountPagination, | ||
29 | checkBadSortPagination, | ||
30 | checkBadStartPagination | ||
31 | } from '../../../../shared/extra-utils/requests/check-api-params' | ||
32 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
33 | 25 | ||
34 | describe('Test abuses API validators', function () { | 26 | describe('Test abuses API validators', function () { |
35 | const basePath = '/api/v1/abuses/' | 27 | const basePath = '/api/v1/abuses/' |
36 | 28 | ||
37 | let server: ServerInfo | 29 | let server: ServerInfo |
38 | 30 | ||
39 | let userAccessToken = '' | 31 | let userToken = '' |
40 | let userAccessToken2 = '' | 32 | let userToken2 = '' |
41 | let abuseId: number | 33 | let abuseId: number |
42 | let messageId: number | 34 | let messageId: number |
43 | 35 | ||
36 | let command: AbusesCommand | ||
37 | |||
44 | // --------------------------------------------------------------- | 38 | // --------------------------------------------------------------- |
45 | 39 | ||
46 | before(async function () { | 40 | before(async function () { |
@@ -53,14 +47,14 @@ describe('Test abuses API validators', function () { | |||
53 | const username = 'user1' | 47 | const username = 'user1' |
54 | const password = 'my super password' | 48 | const password = 'my super password' |
55 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | 49 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
56 | userAccessToken = await userLogin(server, { username, password }) | 50 | userToken = await userLogin(server, { username, password }) |
57 | 51 | ||
58 | { | 52 | userToken2 = await generateUserAccessToken(server, 'user_2') |
59 | userAccessToken2 = await generateUserAccessToken(server, 'user_2') | ||
60 | } | ||
61 | 53 | ||
62 | const res = await uploadVideo(server.url, server.accessToken, {}) | 54 | const res = await uploadVideo(server.url, server.accessToken, {}) |
63 | server.video = res.body.video | 55 | server.video = res.body.video |
56 | |||
57 | command = server.abusesCommand | ||
64 | }) | 58 | }) |
65 | 59 | ||
66 | describe('When listing abuses for admins', function () { | 60 | describe('When listing abuses for admins', function () { |
@@ -90,7 +84,7 @@ describe('Test abuses API validators', function () { | |||
90 | await makeGetRequest({ | 84 | await makeGetRequest({ |
91 | url: server.url, | 85 | url: server.url, |
92 | path, | 86 | path, |
93 | token: userAccessToken, | 87 | token: userToken, |
94 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 88 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
95 | }) | 89 | }) |
96 | }) | 90 | }) |
@@ -134,15 +128,15 @@ describe('Test abuses API validators', function () { | |||
134 | const path = '/api/v1/users/me/abuses' | 128 | const path = '/api/v1/users/me/abuses' |
135 | 129 | ||
136 | it('Should fail with a bad start pagination', async function () { | 130 | it('Should fail with a bad start pagination', async function () { |
137 | await checkBadStartPagination(server.url, path, userAccessToken) | 131 | await checkBadStartPagination(server.url, path, userToken) |
138 | }) | 132 | }) |
139 | 133 | ||
140 | it('Should fail with a bad count pagination', async function () { | 134 | it('Should fail with a bad count pagination', async function () { |
141 | await checkBadCountPagination(server.url, path, userAccessToken) | 135 | await checkBadCountPagination(server.url, path, userToken) |
142 | }) | 136 | }) |
143 | 137 | ||
144 | it('Should fail with an incorrect sort', async function () { | 138 | it('Should fail with an incorrect sort', async function () { |
145 | await checkBadSortPagination(server.url, path, userAccessToken) | 139 | await checkBadSortPagination(server.url, path, userToken) |
146 | }) | 140 | }) |
147 | 141 | ||
148 | it('Should fail with a non authenticated user', async function () { | 142 | it('Should fail with a non authenticated user', async function () { |
@@ -154,12 +148,12 @@ describe('Test abuses API validators', function () { | |||
154 | }) | 148 | }) |
155 | 149 | ||
156 | it('Should fail with a bad id filter', async function () { | 150 | it('Should fail with a bad id filter', async function () { |
157 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { id: 'toto' } }) | 151 | await makeGetRequest({ url: server.url, path, token: userToken, query: { id: 'toto' } }) |
158 | }) | 152 | }) |
159 | 153 | ||
160 | it('Should fail with a bad state filter', async function () { | 154 | it('Should fail with a bad state filter', async function () { |
161 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 'toto' } }) | 155 | await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 'toto' } }) |
162 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 0 } }) | 156 | await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 0 } }) |
163 | }) | 157 | }) |
164 | 158 | ||
165 | it('Should succeed with the correct params', async function () { | 159 | it('Should succeed with the correct params', async function () { |
@@ -168,7 +162,7 @@ describe('Test abuses API validators', function () { | |||
168 | state: 2 | 162 | state: 2 |
169 | } | 163 | } |
170 | 164 | ||
171 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) | 165 | await makeGetRequest({ url: server.url, path, token: userToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) |
172 | }) | 166 | }) |
173 | }) | 167 | }) |
174 | 168 | ||
@@ -177,12 +171,12 @@ describe('Test abuses API validators', function () { | |||
177 | 171 | ||
178 | it('Should fail with nothing', async function () { | 172 | it('Should fail with nothing', async function () { |
179 | const fields = {} | 173 | const fields = {} |
180 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 174 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) |
181 | }) | 175 | }) |
182 | 176 | ||
183 | it('Should fail with a wrong video', async function () { | 177 | it('Should fail with a wrong video', async function () { |
184 | const fields = { video: { id: 'blabla' }, reason: 'my super reason' } | 178 | const fields = { video: { id: 'blabla' }, reason: 'my super reason' } |
185 | await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) | 179 | await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) |
186 | }) | 180 | }) |
187 | 181 | ||
188 | it('Should fail with an unknown video', async function () { | 182 | it('Should fail with an unknown video', async function () { |
@@ -190,7 +184,7 @@ describe('Test abuses API validators', function () { | |||
190 | await makePostBodyRequest({ | 184 | await makePostBodyRequest({ |
191 | url: server.url, | 185 | url: server.url, |
192 | path, | 186 | path, |
193 | token: userAccessToken, | 187 | token: userToken, |
194 | fields, | 188 | fields, |
195 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | 189 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
196 | }) | 190 | }) |
@@ -198,7 +192,7 @@ describe('Test abuses API validators', function () { | |||
198 | 192 | ||
199 | it('Should fail with a wrong comment', async function () { | 193 | it('Should fail with a wrong comment', async function () { |
200 | const fields = { comment: { id: 'blabla' }, reason: 'my super reason' } | 194 | const fields = { comment: { id: 'blabla' }, reason: 'my super reason' } |
201 | await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) | 195 | await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) |
202 | }) | 196 | }) |
203 | 197 | ||
204 | it('Should fail with an unknown comment', async function () { | 198 | it('Should fail with an unknown comment', async function () { |
@@ -206,7 +200,7 @@ describe('Test abuses API validators', function () { | |||
206 | await makePostBodyRequest({ | 200 | await makePostBodyRequest({ |
207 | url: server.url, | 201 | url: server.url, |
208 | path, | 202 | path, |
209 | token: userAccessToken, | 203 | token: userToken, |
210 | fields, | 204 | fields, |
211 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | 205 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
212 | }) | 206 | }) |
@@ -214,7 +208,7 @@ describe('Test abuses API validators', function () { | |||
214 | 208 | ||
215 | it('Should fail with a wrong account', async function () { | 209 | it('Should fail with a wrong account', async function () { |
216 | const fields = { account: { id: 'blabla' }, reason: 'my super reason' } | 210 | const fields = { account: { id: 'blabla' }, reason: 'my super reason' } |
217 | await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) | 211 | await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) |
218 | }) | 212 | }) |
219 | 213 | ||
220 | it('Should fail with an unknown account', async function () { | 214 | it('Should fail with an unknown account', async function () { |
@@ -222,7 +216,7 @@ describe('Test abuses API validators', function () { | |||
222 | await makePostBodyRequest({ | 216 | await makePostBodyRequest({ |
223 | url: server.url, | 217 | url: server.url, |
224 | path, | 218 | path, |
225 | token: userAccessToken, | 219 | token: userToken, |
226 | fields, | 220 | fields, |
227 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | 221 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
228 | }) | 222 | }) |
@@ -233,7 +227,7 @@ describe('Test abuses API validators', function () { | |||
233 | await makePostBodyRequest({ | 227 | await makePostBodyRequest({ |
234 | url: server.url, | 228 | url: server.url, |
235 | path, | 229 | path, |
236 | token: userAccessToken, | 230 | token: userToken, |
237 | fields, | 231 | fields, |
238 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | 232 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
239 | }) | 233 | }) |
@@ -248,13 +242,13 @@ describe('Test abuses API validators', function () { | |||
248 | it('Should fail with a reason too short', async function () { | 242 | it('Should fail with a reason too short', async function () { |
249 | const fields = { video: { id: server.video.id }, reason: 'h' } | 243 | const fields = { video: { id: server.video.id }, reason: 'h' } |
250 | 244 | ||
251 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 245 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) |
252 | }) | 246 | }) |
253 | 247 | ||
254 | it('Should fail with a too big reason', async function () { | 248 | it('Should fail with a too big reason', async function () { |
255 | const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } | 249 | const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } |
256 | 250 | ||
257 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 251 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) |
258 | }) | 252 | }) |
259 | 253 | ||
260 | it('Should succeed with the correct parameters (basic)', async function () { | 254 | it('Should succeed with the correct parameters (basic)', async function () { |
@@ -263,7 +257,7 @@ describe('Test abuses API validators', function () { | |||
263 | const res = await makePostBodyRequest({ | 257 | const res = await makePostBodyRequest({ |
264 | url: server.url, | 258 | url: server.url, |
265 | path, | 259 | path, |
266 | token: userAccessToken, | 260 | token: userToken, |
267 | fields, | 261 | fields, |
268 | statusCodeExpected: HttpStatusCode.OK_200 | 262 | statusCodeExpected: HttpStatusCode.OK_200 |
269 | }) | 263 | }) |
@@ -273,19 +267,19 @@ describe('Test abuses API validators', function () { | |||
273 | it('Should fail with a wrong predefined reason', async function () { | 267 | it('Should fail with a wrong predefined reason', async function () { |
274 | const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } | 268 | const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } |
275 | 269 | ||
276 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 270 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) |
277 | }) | 271 | }) |
278 | 272 | ||
279 | it('Should fail with negative timestamps', async function () { | 273 | it('Should fail with negative timestamps', async function () { |
280 | const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } | 274 | const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } |
281 | 275 | ||
282 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 276 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) |
283 | }) | 277 | }) |
284 | 278 | ||
285 | it('Should fail mith misordered startAt/endAt', async function () { | 279 | it('Should fail mith misordered startAt/endAt', async function () { |
286 | const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } | 280 | const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } |
287 | 281 | ||
288 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 282 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) |
289 | }) | 283 | }) |
290 | 284 | ||
291 | it('Should succeed with the corret parameters (advanced)', async function () { | 285 | it('Should succeed with the corret parameters (advanced)', async function () { |
@@ -299,37 +293,37 @@ describe('Test abuses API validators', function () { | |||
299 | predefinedReasons: [ 'serverRules' ] | 293 | predefinedReasons: [ 'serverRules' ] |
300 | } | 294 | } |
301 | 295 | ||
302 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) | 296 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) |
303 | }) | 297 | }) |
304 | }) | 298 | }) |
305 | 299 | ||
306 | describe('When updating an abuse', function () { | 300 | describe('When updating an abuse', function () { |
307 | 301 | ||
308 | it('Should fail with a non authenticated user', async function () { | 302 | it('Should fail with a non authenticated user', async function () { |
309 | await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401) | 303 | await command.update({ token: 'blabla', abuseId, body: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
310 | }) | 304 | }) |
311 | 305 | ||
312 | it('Should fail with a non admin user', async function () { | 306 | it('Should fail with a non admin user', async function () { |
313 | await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403) | 307 | await command.update({ token: userToken, abuseId, body: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
314 | }) | 308 | }) |
315 | 309 | ||
316 | it('Should fail with a bad abuse id', async function () { | 310 | it('Should fail with a bad abuse id', async function () { |
317 | await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404) | 311 | await command.update({ abuseId: 45, body: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
318 | }) | 312 | }) |
319 | 313 | ||
320 | it('Should fail with a bad state', async function () { | 314 | it('Should fail with a bad state', async function () { |
321 | const body = { state: 5 } | 315 | const body = { state: 5 } |
322 | await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) | 316 | await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
323 | }) | 317 | }) |
324 | 318 | ||
325 | it('Should fail with a bad moderation comment', async function () { | 319 | it('Should fail with a bad moderation comment', async function () { |
326 | const body = { moderationComment: 'b'.repeat(3001) } | 320 | const body = { moderationComment: 'b'.repeat(3001) } |
327 | await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) | 321 | await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
328 | }) | 322 | }) |
329 | 323 | ||
330 | it('Should succeed with the correct params', async function () { | 324 | it('Should succeed with the correct params', async function () { |
331 | const body = { state: AbuseState.ACCEPTED } | 325 | const body = { state: AbuseState.ACCEPTED } |
332 | await updateAbuse(server.url, server.accessToken, abuseId, body) | 326 | await command.update({ abuseId, body }) |
333 | }) | 327 | }) |
334 | }) | 328 | }) |
335 | 329 | ||
@@ -337,23 +331,23 @@ describe('Test abuses API validators', function () { | |||
337 | const message = 'my super message' | 331 | const message = 'my super message' |
338 | 332 | ||
339 | it('Should fail with an invalid abuse id', async function () { | 333 | it('Should fail with an invalid abuse id', async function () { |
340 | await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404) | 334 | await command.addMessage({ token: userToken2, abuseId: 888, message, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
341 | }) | 335 | }) |
342 | 336 | ||
343 | it('Should fail with a non authenticated user', async function () { | 337 | it('Should fail with a non authenticated user', async function () { |
344 | await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401) | 338 | await command.addMessage({ token: 'fake_token', abuseId, message, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
345 | }) | 339 | }) |
346 | 340 | ||
347 | it('Should fail with an invalid logged in user', async function () { | 341 | it('Should fail with an invalid logged in user', async function () { |
348 | await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403) | 342 | await command.addMessage({ token: userToken2, abuseId, message, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
349 | }) | 343 | }) |
350 | 344 | ||
351 | it('Should fail with an invalid message', async function () { | 345 | it('Should fail with an invalid message', async function () { |
352 | await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400) | 346 | await command.addMessage({ token: userToken, abuseId, message: 'a'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
353 | }) | 347 | }) |
354 | 348 | ||
355 | it('Should suceed with the correct params', async function () { | 349 | it('Should suceed with the correct params', async function () { |
356 | const res = await addAbuseMessage(server.url, userAccessToken, abuseId, message) | 350 | const res = await command.addMessage({ token: userToken, abuseId, message }) |
357 | messageId = res.body.abuseMessage.id | 351 | messageId = res.body.abuseMessage.id |
358 | }) | 352 | }) |
359 | }) | 353 | }) |
@@ -361,61 +355,60 @@ describe('Test abuses API validators', function () { | |||
361 | describe('When listing abuse messages', function () { | 355 | describe('When listing abuse messages', function () { |
362 | 356 | ||
363 | it('Should fail with an invalid abuse id', async function () { | 357 | it('Should fail with an invalid abuse id', async function () { |
364 | await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404) | 358 | await command.listMessages({ token: userToken, abuseId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
365 | }) | 359 | }) |
366 | 360 | ||
367 | it('Should fail with a non authenticated user', async function () { | 361 | it('Should fail with a non authenticated user', async function () { |
368 | await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401) | 362 | await command.listMessages({ token: 'fake_token', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
369 | }) | 363 | }) |
370 | 364 | ||
371 | it('Should fail with an invalid logged in user', async function () { | 365 | it('Should fail with an invalid logged in user', async function () { |
372 | await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403) | 366 | await command.listMessages({ token: userToken2, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
373 | }) | 367 | }) |
374 | 368 | ||
375 | it('Should succeed with the correct params', async function () { | 369 | it('Should succeed with the correct params', async function () { |
376 | await listAbuseMessages(server.url, userAccessToken, abuseId) | 370 | await command.listMessages({ token: userToken, abuseId }) |
377 | }) | 371 | }) |
378 | }) | 372 | }) |
379 | 373 | ||
380 | describe('When deleting an abuse message', function () { | 374 | describe('When deleting an abuse message', function () { |
381 | |||
382 | it('Should fail with an invalid abuse id', async function () { | 375 | it('Should fail with an invalid abuse id', async function () { |
383 | await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404) | 376 | await command.deleteMessage({ token: userToken, abuseId: 888, messageId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
384 | }) | 377 | }) |
385 | 378 | ||
386 | it('Should fail with an invalid message id', async function () { | 379 | it('Should fail with an invalid message id', async function () { |
387 | await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404) | 380 | await command.deleteMessage({ token: userToken, abuseId, messageId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
388 | }) | 381 | }) |
389 | 382 | ||
390 | it('Should fail with a non authenticated user', async function () { | 383 | it('Should fail with a non authenticated user', async function () { |
391 | await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401) | 384 | await command.deleteMessage({ token: 'fake_token', abuseId, messageId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
392 | }) | 385 | }) |
393 | 386 | ||
394 | it('Should fail with an invalid logged in user', async function () { | 387 | it('Should fail with an invalid logged in user', async function () { |
395 | await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403) | 388 | await command.deleteMessage({ token: userToken2, abuseId, messageId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
396 | }) | 389 | }) |
397 | 390 | ||
398 | it('Should succeed with the correct params', async function () { | 391 | it('Should succeed with the correct params', async function () { |
399 | await deleteAbuseMessage(server.url, userAccessToken, abuseId, messageId) | 392 | await command.deleteMessage({ token: userToken, abuseId, messageId }) |
400 | }) | 393 | }) |
401 | }) | 394 | }) |
402 | 395 | ||
403 | describe('When deleting a video abuse', function () { | 396 | describe('When deleting a video abuse', function () { |
404 | 397 | ||
405 | it('Should fail with a non authenticated user', async function () { | 398 | it('Should fail with a non authenticated user', async function () { |
406 | await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401) | 399 | await command.delete({ token: 'blabla', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
407 | }) | 400 | }) |
408 | 401 | ||
409 | it('Should fail with a non admin user', async function () { | 402 | it('Should fail with a non admin user', async function () { |
410 | await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403) | 403 | await command.delete({ token: userToken, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
411 | }) | 404 | }) |
412 | 405 | ||
413 | it('Should fail with a bad abuse id', async function () { | 406 | it('Should fail with a bad abuse id', async function () { |
414 | await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404) | 407 | await command.delete({ abuseId: 45, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
415 | }) | 408 | }) |
416 | 409 | ||
417 | it('Should succeed with the correct params', async function () { | 410 | it('Should succeed with the correct params', async function () { |
418 | await deleteAbuse(server.url, server.accessToken, abuseId) | 411 | await command.delete({ abuseId }) |
419 | }) | 412 | }) |
420 | }) | 413 | }) |
421 | 414 | ||
@@ -432,25 +425,20 @@ describe('Test abuses API validators', function () { | |||
432 | await doubleFollow(anotherServer, server) | 425 | await doubleFollow(anotherServer, server) |
433 | 426 | ||
434 | const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) | 427 | const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) |
435 | await reportAbuse({ | 428 | await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) |
436 | url: anotherServer.url, | ||
437 | token: anotherServer.accessToken, | ||
438 | reason: 'remote server', | ||
439 | videoId: server2VideoId | ||
440 | }) | ||
441 | 429 | ||
442 | await waitJobs([ server, anotherServer ]) | 430 | await waitJobs([ server, anotherServer ]) |
443 | 431 | ||
444 | const res = await getAdminAbusesList({ url: server.url, token: server.accessToken, sort: '-createdAt' }) | 432 | const body = await command.getAdminList({ sort: '-createdAt' }) |
445 | remoteAbuseId = res.body.data[0].id | 433 | remoteAbuseId = body.data[0].id |
446 | }) | 434 | }) |
447 | 435 | ||
448 | it('Should fail when listing abuse messages of a remote abuse', async function () { | 436 | it('Should fail when listing abuse messages of a remote abuse', async function () { |
449 | await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400) | 437 | await command.listMessages({ abuseId: remoteAbuseId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
450 | }) | 438 | }) |
451 | 439 | ||
452 | it('Should fail when creating abuse message of a remote abuse', async function () { | 440 | it('Should fail when creating abuse message of a remote abuse', async function () { |
453 | await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400) | 441 | await command.addMessage({ abuseId: remoteAbuseId, message: 'message', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
454 | }) | 442 | }) |
455 | 443 | ||
456 | after(async function () { | 444 | after(async function () { |
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index fb765e7e3..a9f5332ce 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts | |||
@@ -3,51 +3,32 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | AbuseFilter, | 6 | AbusesCommand, |
7 | AbuseMessage, | 7 | addAccountToServerBlocklist, |
8 | AbusePredefinedReasonsString, | 8 | addServerToServerBlocklist, |
9 | AbuseState, | ||
10 | Account, | ||
11 | AdminAbuse, | ||
12 | UserAbuse, | ||
13 | VideoComment | ||
14 | } from '@shared/models' | ||
15 | import { | ||
16 | addAbuseMessage, | ||
17 | addVideoCommentThread, | 9 | addVideoCommentThread, |
18 | cleanupTests, | 10 | cleanupTests, |
19 | createUser, | 11 | createUser, |
20 | deleteAbuse, | ||
21 | deleteAbuseMessage, | ||
22 | deleteVideoComment, | 12 | deleteVideoComment, |
13 | doubleFollow, | ||
23 | flushAndRunMultipleServers, | 14 | flushAndRunMultipleServers, |
24 | generateUserAccessToken, | 15 | generateUserAccessToken, |
25 | getAccount, | 16 | getAccount, |
26 | getAdminAbusesList, | ||
27 | getUserAbusesList, | ||
28 | getVideoCommentThreads, | 17 | getVideoCommentThreads, |
29 | getVideoIdFromUUID, | 18 | getVideoIdFromUUID, |
30 | getVideosList, | 19 | getVideosList, |
31 | immutableAssign, | 20 | removeAccountFromServerBlocklist, |
32 | listAbuseMessages, | 21 | removeServerFromServerBlocklist, |
33 | removeUser, | 22 | removeUser, |
34 | removeVideo, | 23 | removeVideo, |
35 | reportAbuse, | ||
36 | ServerInfo, | 24 | ServerInfo, |
37 | setAccessTokensToServers, | 25 | setAccessTokensToServers, |
38 | updateAbuse, | ||
39 | uploadVideo, | 26 | uploadVideo, |
40 | uploadVideoAndGetId, | 27 | uploadVideoAndGetId, |
41 | userLogin | 28 | userLogin, |
42 | } from '../../../../shared/extra-utils/index' | 29 | waitJobs |
43 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | 30 | } from '@shared/extra-utils' |
44 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 31 | import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' |
45 | import { | ||
46 | addAccountToServerBlocklist, | ||
47 | addServerToServerBlocklist, | ||
48 | removeAccountFromServerBlocklist, | ||
49 | removeServerFromServerBlocklist | ||
50 | } from '../../../../shared/extra-utils/users/blocklist' | ||
51 | 32 | ||
52 | const expect = chai.expect | 33 | const expect = chai.expect |
53 | 34 | ||
@@ -55,6 +36,7 @@ describe('Test abuses', function () { | |||
55 | let servers: ServerInfo[] = [] | 36 | let servers: ServerInfo[] = [] |
56 | let abuseServer1: AdminAbuse | 37 | let abuseServer1: AdminAbuse |
57 | let abuseServer2: AdminAbuse | 38 | let abuseServer2: AdminAbuse |
39 | let commands: AbusesCommand[] | ||
58 | 40 | ||
59 | before(async function () { | 41 | before(async function () { |
60 | this.timeout(50000) | 42 | this.timeout(50000) |
@@ -67,6 +49,8 @@ describe('Test abuses', function () { | |||
67 | 49 | ||
68 | // Server 1 and server 2 follow each other | 50 | // Server 1 and server 2 follow each other |
69 | await doubleFollow(servers[0], servers[1]) | 51 | await doubleFollow(servers[0], servers[1]) |
52 | |||
53 | commands = servers.map(s => s.abusesCommand) | ||
70 | }) | 54 | }) |
71 | 55 | ||
72 | describe('Video abuses', function () { | 56 | describe('Video abuses', function () { |
@@ -100,54 +84,58 @@ describe('Test abuses', function () { | |||
100 | }) | 84 | }) |
101 | 85 | ||
102 | it('Should not have abuses', async function () { | 86 | it('Should not have abuses', async function () { |
103 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 87 | const body = await commands[0].getAdminList() |
104 | 88 | ||
105 | expect(res.body.total).to.equal(0) | 89 | expect(body.total).to.equal(0) |
106 | expect(res.body.data).to.be.an('array') | 90 | expect(body.data).to.be.an('array') |
107 | expect(res.body.data.length).to.equal(0) | 91 | expect(body.data.length).to.equal(0) |
108 | }) | 92 | }) |
109 | 93 | ||
110 | it('Should report abuse on a local video', async function () { | 94 | it('Should report abuse on a local video', async function () { |
111 | this.timeout(15000) | 95 | this.timeout(15000) |
112 | 96 | ||
113 | const reason = 'my super bad reason' | 97 | const reason = 'my super bad reason' |
114 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) | 98 | await commands[0].report({ videoId: servers[0].video.id, reason }) |
115 | 99 | ||
116 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 | 100 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 |
117 | await waitJobs(servers) | 101 | await waitJobs(servers) |
118 | }) | 102 | }) |
119 | 103 | ||
120 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { | 104 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { |
121 | const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 105 | { |
106 | const body = await commands[0].getAdminList() | ||
122 | 107 | ||
123 | expect(res1.body.total).to.equal(1) | 108 | expect(body.total).to.equal(1) |
124 | expect(res1.body.data).to.be.an('array') | 109 | expect(body.data).to.be.an('array') |
125 | expect(res1.body.data.length).to.equal(1) | 110 | expect(body.data.length).to.equal(1) |
126 | 111 | ||
127 | const abuse: AdminAbuse = res1.body.data[0] | 112 | const abuse = body.data[0] |
128 | expect(abuse.reason).to.equal('my super bad reason') | 113 | expect(abuse.reason).to.equal('my super bad reason') |
129 | 114 | ||
130 | expect(abuse.reporterAccount.name).to.equal('root') | 115 | expect(abuse.reporterAccount.name).to.equal('root') |
131 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | 116 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) |
132 | 117 | ||
133 | expect(abuse.video.id).to.equal(servers[0].video.id) | 118 | expect(abuse.video.id).to.equal(servers[0].video.id) |
134 | expect(abuse.video.channel).to.exist | 119 | expect(abuse.video.channel).to.exist |
135 | 120 | ||
136 | expect(abuse.comment).to.be.null | 121 | expect(abuse.comment).to.be.null |
137 | 122 | ||
138 | expect(abuse.flaggedAccount.name).to.equal('root') | 123 | expect(abuse.flaggedAccount.name).to.equal('root') |
139 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) | 124 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) |
140 | 125 | ||
141 | expect(abuse.video.countReports).to.equal(1) | 126 | expect(abuse.video.countReports).to.equal(1) |
142 | expect(abuse.video.nthReport).to.equal(1) | 127 | expect(abuse.video.nthReport).to.equal(1) |
143 | 128 | ||
144 | expect(abuse.countReportsForReporter).to.equal(1) | 129 | expect(abuse.countReportsForReporter).to.equal(1) |
145 | expect(abuse.countReportsForReportee).to.equal(1) | 130 | expect(abuse.countReportsForReportee).to.equal(1) |
131 | } | ||
146 | 132 | ||
147 | const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 133 | { |
148 | expect(res2.body.total).to.equal(0) | 134 | const body = await commands[1].getAdminList() |
149 | expect(res2.body.data).to.be.an('array') | 135 | expect(body.total).to.equal(0) |
150 | expect(res2.body.data.length).to.equal(0) | 136 | expect(body.data).to.be.an('array') |
137 | expect(body.data.length).to.equal(0) | ||
138 | } | ||
151 | }) | 139 | }) |
152 | 140 | ||
153 | it('Should report abuse on a remote video', async function () { | 141 | it('Should report abuse on a remote video', async function () { |
@@ -155,68 +143,72 @@ describe('Test abuses', function () { | |||
155 | 143 | ||
156 | const reason = 'my super bad reason 2' | 144 | const reason = 'my super bad reason 2' |
157 | const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) | 145 | const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) |
158 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason }) | 146 | await commands[0].report({ videoId, reason }) |
159 | 147 | ||
160 | // We wait requests propagation | 148 | // We wait requests propagation |
161 | await waitJobs(servers) | 149 | await waitJobs(servers) |
162 | }) | 150 | }) |
163 | 151 | ||
164 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { | 152 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { |
165 | const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 153 | { |
154 | const body = await commands[0].getAdminList() | ||
166 | 155 | ||
167 | expect(res1.body.total).to.equal(2) | 156 | expect(body.total).to.equal(2) |
168 | expect(res1.body.data.length).to.equal(2) | 157 | expect(body.data.length).to.equal(2) |
169 | 158 | ||
170 | const abuse1: AdminAbuse = res1.body.data[0] | 159 | const abuse1 = body.data[0] |
171 | expect(abuse1.reason).to.equal('my super bad reason') | 160 | expect(abuse1.reason).to.equal('my super bad reason') |
172 | expect(abuse1.reporterAccount.name).to.equal('root') | 161 | expect(abuse1.reporterAccount.name).to.equal('root') |
173 | expect(abuse1.reporterAccount.host).to.equal(servers[0].host) | 162 | expect(abuse1.reporterAccount.host).to.equal(servers[0].host) |
174 | 163 | ||
175 | expect(abuse1.video.id).to.equal(servers[0].video.id) | 164 | expect(abuse1.video.id).to.equal(servers[0].video.id) |
176 | expect(abuse1.video.countReports).to.equal(1) | 165 | expect(abuse1.video.countReports).to.equal(1) |
177 | expect(abuse1.video.nthReport).to.equal(1) | 166 | expect(abuse1.video.nthReport).to.equal(1) |
178 | 167 | ||
179 | expect(abuse1.comment).to.be.null | 168 | expect(abuse1.comment).to.be.null |
180 | 169 | ||
181 | expect(abuse1.flaggedAccount.name).to.equal('root') | 170 | expect(abuse1.flaggedAccount.name).to.equal('root') |
182 | expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) | 171 | expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) |
183 | 172 | ||
184 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) | 173 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) |
185 | expect(abuse1.state.label).to.equal('Pending') | 174 | expect(abuse1.state.label).to.equal('Pending') |
186 | expect(abuse1.moderationComment).to.be.null | 175 | expect(abuse1.moderationComment).to.be.null |
187 | 176 | ||
188 | const abuse2: AdminAbuse = res1.body.data[1] | 177 | const abuse2 = body.data[1] |
189 | expect(abuse2.reason).to.equal('my super bad reason 2') | 178 | expect(abuse2.reason).to.equal('my super bad reason 2') |
190 | 179 | ||
191 | expect(abuse2.reporterAccount.name).to.equal('root') | 180 | expect(abuse2.reporterAccount.name).to.equal('root') |
192 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | 181 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) |
193 | 182 | ||
194 | expect(abuse2.video.id).to.equal(servers[1].video.id) | 183 | expect(abuse2.video.id).to.equal(servers[1].video.id) |
195 | 184 | ||
196 | expect(abuse2.comment).to.be.null | 185 | expect(abuse2.comment).to.be.null |
197 | 186 | ||
198 | expect(abuse2.flaggedAccount.name).to.equal('root') | 187 | expect(abuse2.flaggedAccount.name).to.equal('root') |
199 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) | 188 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) |
200 | 189 | ||
201 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | 190 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
202 | expect(abuse2.state.label).to.equal('Pending') | 191 | expect(abuse2.state.label).to.equal('Pending') |
203 | expect(abuse2.moderationComment).to.be.null | 192 | expect(abuse2.moderationComment).to.be.null |
193 | } | ||
204 | 194 | ||
205 | const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 195 | { |
206 | expect(res2.body.total).to.equal(1) | 196 | const body = await commands[1].getAdminList() |
207 | expect(res2.body.data.length).to.equal(1) | 197 | expect(body.total).to.equal(1) |
198 | expect(body.data.length).to.equal(1) | ||
208 | 199 | ||
209 | abuseServer2 = res2.body.data[0] | 200 | abuseServer2 = body.data[0] |
210 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | 201 | expect(abuseServer2.reason).to.equal('my super bad reason 2') |
211 | expect(abuseServer2.reporterAccount.name).to.equal('root') | 202 | expect(abuseServer2.reporterAccount.name).to.equal('root') |
212 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | 203 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) |
213 | 204 | ||
214 | expect(abuse2.flaggedAccount.name).to.equal('root') | 205 | expect(abuseServer2.flaggedAccount.name).to.equal('root') |
215 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) | 206 | expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host) |
216 | 207 | ||
217 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | 208 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
218 | expect(abuseServer2.state.label).to.equal('Pending') | 209 | expect(abuseServer2.state.label).to.equal('Pending') |
219 | expect(abuseServer2.moderationComment).to.be.null | 210 | expect(abuseServer2.moderationComment).to.be.null |
211 | } | ||
220 | }) | 212 | }) |
221 | 213 | ||
222 | it('Should hide video abuses from blocked accounts', async function () { | 214 | it('Should hide video abuses from blocked accounts', async function () { |
@@ -224,11 +216,11 @@ describe('Test abuses', function () { | |||
224 | 216 | ||
225 | { | 217 | { |
226 | const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) | 218 | const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) |
227 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) | 219 | await commands[1].report({ videoId, reason: 'will mute this' }) |
228 | await waitJobs(servers) | 220 | await waitJobs(servers) |
229 | 221 | ||
230 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 222 | const body = await commands[0].getAdminList() |
231 | expect(res.body.total).to.equal(3) | 223 | expect(body.total).to.equal(3) |
232 | } | 224 | } |
233 | 225 | ||
234 | const accountToBlock = 'root@' + servers[1].host | 226 | const accountToBlock = 'root@' + servers[1].host |
@@ -236,18 +228,18 @@ describe('Test abuses', function () { | |||
236 | { | 228 | { |
237 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) | 229 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) |
238 | 230 | ||
239 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 231 | const body = await commands[0].getAdminList() |
240 | expect(res.body.total).to.equal(2) | 232 | expect(body.total).to.equal(2) |
241 | 233 | ||
242 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | 234 | const abuse = body.data.find(a => a.reason === 'will mute this') |
243 | expect(abuse).to.be.undefined | 235 | expect(abuse).to.be.undefined |
244 | } | 236 | } |
245 | 237 | ||
246 | { | 238 | { |
247 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) | 239 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) |
248 | 240 | ||
249 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 241 | const body = await commands[0].getAdminList() |
250 | expect(res.body.total).to.equal(3) | 242 | expect(body.total).to.equal(3) |
251 | } | 243 | } |
252 | }) | 244 | }) |
253 | 245 | ||
@@ -257,18 +249,18 @@ describe('Test abuses', function () { | |||
257 | { | 249 | { |
258 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) | 250 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) |
259 | 251 | ||
260 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 252 | const body = await commands[0].getAdminList() |
261 | expect(res.body.total).to.equal(2) | 253 | expect(body.total).to.equal(2) |
262 | 254 | ||
263 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | 255 | const abuse = body.data.find(a => a.reason === 'will mute this') |
264 | expect(abuse).to.be.undefined | 256 | expect(abuse).to.be.undefined |
265 | } | 257 | } |
266 | 258 | ||
267 | { | 259 | { |
268 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) | 260 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) |
269 | 261 | ||
270 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 262 | const body = await commands[0].getAdminList() |
271 | expect(res.body.total).to.equal(3) | 263 | expect(body.total).to.equal(3) |
272 | } | 264 | } |
273 | }) | 265 | }) |
274 | 266 | ||
@@ -279,11 +271,11 @@ describe('Test abuses', function () { | |||
279 | 271 | ||
280 | await waitJobs(servers) | 272 | await waitJobs(servers) |
281 | 273 | ||
282 | const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 274 | const body = await commands[1].getAdminList() |
283 | expect(res.body.total).to.equal(2, "wrong number of videos returned") | 275 | expect(body.total).to.equal(2, "wrong number of videos returned") |
284 | expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") | 276 | expect(body.data).to.have.lengthOf(2, "wrong number of videos returned") |
285 | 277 | ||
286 | const abuse: AdminAbuse = res.body.data[0] | 278 | const abuse = body.data[0] |
287 | expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") | 279 | expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") |
288 | expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") | 280 | expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") |
289 | expect(abuse.video.channel).to.exist | 281 | expect(abuse.video.channel).to.exist |
@@ -303,24 +295,21 @@ describe('Test abuses', function () { | |||
303 | name: 'my second super name for server 1', | 295 | name: 'my second super name for server 1', |
304 | description: 'my second super description for server 1' | 296 | description: 'my second super description for server 1' |
305 | } | 297 | } |
306 | await uploadVideo(servers[0].url, userAccessToken, video3Attributes) | 298 | const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) |
307 | 299 | const video3Id = resUpload.body.video.id | |
308 | const res1 = await getVideosList(servers[0].url) | ||
309 | const videos = res1.body.data | ||
310 | const video3 = videos.find(video => video.name === 'my second super name for server 1') | ||
311 | 300 | ||
312 | // resume with the test | 301 | // resume with the test |
313 | const reason3 = 'my super bad reason 3' | 302 | const reason3 = 'my super bad reason 3' |
314 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) | 303 | await commands[0].report({ videoId: video3Id, reason: reason3 }) |
315 | 304 | ||
316 | const reason4 = 'my super bad reason 4' | 305 | const reason4 = 'my super bad reason 4' |
317 | await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) | 306 | await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) |
318 | 307 | ||
319 | { | 308 | { |
320 | const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 309 | const body = await commands[0].getAdminList() |
321 | const abuses = res2.body.data as AdminAbuse[] | 310 | const abuses = body.data |
322 | 311 | ||
323 | const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) | 312 | const abuseVideo3 = body.data.find(a => a.video.id === video3Id) |
324 | expect(abuseVideo3).to.not.be.undefined | 313 | expect(abuseVideo3).to.not.be.undefined |
325 | expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") | 314 | expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") |
326 | expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") | 315 | expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") |
@@ -337,20 +326,18 @@ describe('Test abuses', function () { | |||
337 | 326 | ||
338 | const reason5 = 'my super bad reason 5' | 327 | const reason5 = 'my super bad reason 5' |
339 | const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] | 328 | const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] |
340 | const createdAbuse = (await reportAbuse({ | 329 | const createRes = await commands[0].report({ |
341 | url: servers[0].url, | ||
342 | token: servers[0].accessToken, | ||
343 | videoId: servers[0].video.id, | 330 | videoId: servers[0].video.id, |
344 | reason: reason5, | 331 | reason: reason5, |
345 | predefinedReasons: predefinedReasons5, | 332 | predefinedReasons: predefinedReasons5, |
346 | startAt: 1, | 333 | startAt: 1, |
347 | endAt: 5 | 334 | endAt: 5 |
348 | })).body.abuse | 335 | }) |
349 | 336 | ||
350 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 337 | const body = await commands[0].getAdminList() |
351 | 338 | ||
352 | { | 339 | { |
353 | const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) | 340 | const abuse = body.data.find(a => a.id === createRes.abuse.id) |
354 | expect(abuse.reason).to.equals(reason5) | 341 | expect(abuse.reason).to.equals(reason5) |
355 | expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") | 342 | expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") |
356 | expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") | 343 | expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") |
@@ -361,37 +348,30 @@ describe('Test abuses', function () { | |||
361 | it('Should delete the video abuse', async function () { | 348 | it('Should delete the video abuse', async function () { |
362 | this.timeout(10000) | 349 | this.timeout(10000) |
363 | 350 | ||
364 | await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) | 351 | await commands[1].delete({ abuseId: abuseServer2.id }) |
365 | 352 | ||
366 | await waitJobs(servers) | 353 | await waitJobs(servers) |
367 | 354 | ||
368 | { | 355 | { |
369 | const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 356 | const body = await commands[1].getAdminList() |
370 | expect(res.body.total).to.equal(1) | 357 | expect(body.total).to.equal(1) |
371 | expect(res.body.data.length).to.equal(1) | 358 | expect(body.data.length).to.equal(1) |
372 | expect(res.body.data[0].id).to.not.equal(abuseServer2.id) | 359 | expect(body.data[0].id).to.not.equal(abuseServer2.id) |
373 | } | 360 | } |
374 | 361 | ||
375 | { | 362 | { |
376 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 363 | const body = await commands[0].getAdminList() |
377 | expect(res.body.total).to.equal(6) | 364 | expect(body.total).to.equal(6) |
378 | } | 365 | } |
379 | }) | 366 | }) |
380 | 367 | ||
381 | it('Should list and filter video abuses', async function () { | 368 | it('Should list and filter video abuses', async function () { |
382 | this.timeout(10000) | 369 | this.timeout(10000) |
383 | 370 | ||
384 | async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) { | 371 | async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) { |
385 | const options = { | 372 | const body = await commands[0].getAdminList(query) |
386 | url: servers[0].url, | ||
387 | token: servers[0].accessToken | ||
388 | } | ||
389 | |||
390 | Object.assign(options, query) | ||
391 | 373 | ||
392 | const res = await getAdminAbusesList(options) | 374 | return body.data |
393 | |||
394 | return res.body.data as AdminAbuse[] | ||
395 | } | 375 | } |
396 | 376 | ||
397 | expect(await list({ id: 56 })).to.have.lengthOf(0) | 377 | expect(await list({ id: 56 })).to.have.lengthOf(0) |
@@ -452,7 +432,7 @@ describe('Test abuses', function () { | |||
452 | const comment = await getComment(servers[0].url, servers[0].video.id) | 432 | const comment = await getComment(servers[0].url, servers[0].video.id) |
453 | 433 | ||
454 | const reason = 'it is a bad comment' | 434 | const reason = 'it is a bad comment' |
455 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) | 435 | await commands[0].report({ commentId: comment.id, reason }) |
456 | 436 | ||
457 | await waitJobs(servers) | 437 | await waitJobs(servers) |
458 | }) | 438 | }) |
@@ -460,12 +440,12 @@ describe('Test abuses', function () { | |||
460 | it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { | 440 | it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { |
461 | { | 441 | { |
462 | const comment = await getComment(servers[0].url, servers[0].video.id) | 442 | const comment = await getComment(servers[0].url, servers[0].video.id) |
463 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | 443 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
464 | 444 | ||
465 | expect(res.body.total).to.equal(1) | 445 | expect(body.total).to.equal(1) |
466 | expect(res.body.data).to.have.lengthOf(1) | 446 | expect(body.data).to.have.lengthOf(1) |
467 | 447 | ||
468 | const abuse: AdminAbuse = res.body.data[0] | 448 | const abuse = body.data[0] |
469 | expect(abuse.reason).to.equal('it is a bad comment') | 449 | expect(abuse.reason).to.equal('it is a bad comment') |
470 | 450 | ||
471 | expect(abuse.reporterAccount.name).to.equal('root') | 451 | expect(abuse.reporterAccount.name).to.equal('root') |
@@ -485,9 +465,9 @@ describe('Test abuses', function () { | |||
485 | } | 465 | } |
486 | 466 | ||
487 | { | 467 | { |
488 | const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | 468 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
489 | expect(res.body.total).to.equal(0) | 469 | expect(body.total).to.equal(0) |
490 | expect(res.body.data.length).to.equal(0) | 470 | expect(body.data.length).to.equal(0) |
491 | } | 471 | } |
492 | }) | 472 | }) |
493 | 473 | ||
@@ -497,7 +477,7 @@ describe('Test abuses', function () { | |||
497 | const comment = await getComment(servers[0].url, servers[1].video.uuid) | 477 | const comment = await getComment(servers[0].url, servers[1].video.uuid) |
498 | 478 | ||
499 | const reason = 'it is a really bad comment' | 479 | const reason = 'it is a really bad comment' |
500 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) | 480 | await commands[0].report({ commentId: comment.id, reason }) |
501 | 481 | ||
502 | await waitJobs(servers) | 482 | await waitJobs(servers) |
503 | }) | 483 | }) |
@@ -505,54 +485,58 @@ describe('Test abuses', function () { | |||
505 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | 485 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { |
506 | const commentServer2 = await getComment(servers[0].url, servers[1].video.id) | 486 | const commentServer2 = await getComment(servers[0].url, servers[1].video.id) |
507 | 487 | ||
508 | const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | 488 | { |
509 | expect(res1.body.total).to.equal(2) | 489 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
510 | expect(res1.body.data.length).to.equal(2) | 490 | expect(body.total).to.equal(2) |
491 | expect(body.data.length).to.equal(2) | ||
511 | 492 | ||
512 | const abuse: AdminAbuse = res1.body.data[0] | 493 | const abuse = body.data[0] |
513 | expect(abuse.reason).to.equal('it is a bad comment') | 494 | expect(abuse.reason).to.equal('it is a bad comment') |
514 | expect(abuse.countReportsForReporter).to.equal(6) | 495 | expect(abuse.countReportsForReporter).to.equal(6) |
515 | expect(abuse.countReportsForReportee).to.equal(5) | 496 | expect(abuse.countReportsForReportee).to.equal(5) |
516 | 497 | ||
517 | const abuse2: AdminAbuse = res1.body.data[1] | 498 | const abuse2 = body.data[1] |
518 | 499 | ||
519 | expect(abuse2.reason).to.equal('it is a really bad comment') | 500 | expect(abuse2.reason).to.equal('it is a really bad comment') |
520 | 501 | ||
521 | expect(abuse2.reporterAccount.name).to.equal('root') | 502 | expect(abuse2.reporterAccount.name).to.equal('root') |
522 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | 503 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) |
523 | 504 | ||
524 | expect(abuse2.video).to.be.null | 505 | expect(abuse2.video).to.be.null |
525 | 506 | ||
526 | expect(abuse2.comment.deleted).to.be.false | 507 | expect(abuse2.comment.deleted).to.be.false |
527 | expect(abuse2.comment.id).to.equal(commentServer2.id) | 508 | expect(abuse2.comment.id).to.equal(commentServer2.id) |
528 | expect(abuse2.comment.text).to.equal(commentServer2.text) | 509 | expect(abuse2.comment.text).to.equal(commentServer2.text) |
529 | expect(abuse2.comment.video.name).to.equal('server 2') | 510 | expect(abuse2.comment.video.name).to.equal('server 2') |
530 | expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) | 511 | expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) |
531 | 512 | ||
532 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | 513 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
533 | expect(abuse2.state.label).to.equal('Pending') | 514 | expect(abuse2.state.label).to.equal('Pending') |
534 | 515 | ||
535 | expect(abuse2.moderationComment).to.be.null | 516 | expect(abuse2.moderationComment).to.be.null |
536 | 517 | ||
537 | expect(abuse2.countReportsForReporter).to.equal(6) | 518 | expect(abuse2.countReportsForReporter).to.equal(6) |
538 | expect(abuse2.countReportsForReportee).to.equal(2) | 519 | expect(abuse2.countReportsForReportee).to.equal(2) |
520 | } | ||
539 | 521 | ||
540 | const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | 522 | { |
541 | expect(res2.body.total).to.equal(1) | 523 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
542 | expect(res2.body.data.length).to.equal(1) | 524 | expect(body.total).to.equal(1) |
525 | expect(body.data.length).to.equal(1) | ||
543 | 526 | ||
544 | abuseServer2 = res2.body.data[0] | 527 | abuseServer2 = body.data[0] |
545 | expect(abuseServer2.reason).to.equal('it is a really bad comment') | 528 | expect(abuseServer2.reason).to.equal('it is a really bad comment') |
546 | expect(abuseServer2.reporterAccount.name).to.equal('root') | 529 | expect(abuseServer2.reporterAccount.name).to.equal('root') |
547 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | 530 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) |
548 | 531 | ||
549 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | 532 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
550 | expect(abuseServer2.state.label).to.equal('Pending') | 533 | expect(abuseServer2.state.label).to.equal('Pending') |
551 | 534 | ||
552 | expect(abuseServer2.moderationComment).to.be.null | 535 | expect(abuseServer2.moderationComment).to.be.null |
553 | 536 | ||
554 | expect(abuseServer2.countReportsForReporter).to.equal(1) | 537 | expect(abuseServer2.countReportsForReporter).to.equal(1) |
555 | expect(abuseServer2.countReportsForReportee).to.equal(1) | 538 | expect(abuseServer2.countReportsForReportee).to.equal(1) |
539 | } | ||
556 | }) | 540 | }) |
557 | 541 | ||
558 | it('Should keep the comment abuse when deleting the comment', async function () { | 542 | it('Should keep the comment abuse when deleting the comment', async function () { |
@@ -564,11 +548,11 @@ describe('Test abuses', function () { | |||
564 | 548 | ||
565 | await waitJobs(servers) | 549 | await waitJobs(servers) |
566 | 550 | ||
567 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | 551 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
568 | expect(res.body.total).to.equal(2) | 552 | expect(body.total).to.equal(2) |
569 | expect(res.body.data).to.have.lengthOf(2) | 553 | expect(body.data).to.have.lengthOf(2) |
570 | 554 | ||
571 | const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id) | 555 | const abuse = body.data.find(a => a.comment?.id === commentServer2.id) |
572 | expect(abuse).to.not.be.undefined | 556 | expect(abuse).to.not.be.undefined |
573 | 557 | ||
574 | expect(abuse.comment.text).to.be.empty | 558 | expect(abuse.comment.text).to.be.empty |
@@ -579,53 +563,43 @@ describe('Test abuses', function () { | |||
579 | it('Should delete the comment abuse', async function () { | 563 | it('Should delete the comment abuse', async function () { |
580 | this.timeout(10000) | 564 | this.timeout(10000) |
581 | 565 | ||
582 | await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) | 566 | await commands[1].delete({ abuseId: abuseServer2.id }) |
583 | 567 | ||
584 | await waitJobs(servers) | 568 | await waitJobs(servers) |
585 | 569 | ||
586 | { | 570 | { |
587 | const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | 571 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
588 | expect(res.body.total).to.equal(0) | 572 | expect(body.total).to.equal(0) |
589 | expect(res.body.data.length).to.equal(0) | 573 | expect(body.data.length).to.equal(0) |
590 | } | 574 | } |
591 | 575 | ||
592 | { | 576 | { |
593 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | 577 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
594 | expect(res.body.total).to.equal(2) | 578 | expect(body.total).to.equal(2) |
595 | } | 579 | } |
596 | }) | 580 | }) |
597 | 581 | ||
598 | it('Should list and filter video abuses', async function () { | 582 | it('Should list and filter video abuses', async function () { |
599 | { | 583 | { |
600 | const res = await getAdminAbusesList({ | 584 | const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' }) |
601 | url: servers[0].url, | 585 | expect(body.total).to.equal(0) |
602 | token: servers[0].accessToken, | ||
603 | filter: 'comment', | ||
604 | searchReportee: 'foo' | ||
605 | }) | ||
606 | expect(res.body.total).to.equal(0) | ||
607 | } | 586 | } |
608 | 587 | ||
609 | { | 588 | { |
610 | const res = await getAdminAbusesList({ | 589 | const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' }) |
611 | url: servers[0].url, | 590 | expect(body.total).to.equal(2) |
612 | token: servers[0].accessToken, | ||
613 | filter: 'comment', | ||
614 | searchReportee: 'ot' | ||
615 | }) | ||
616 | expect(res.body.total).to.equal(2) | ||
617 | } | 591 | } |
618 | 592 | ||
619 | { | 593 | { |
620 | const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } | 594 | const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' }) |
621 | 595 | expect(body.data).to.have.lengthOf(1) | |
622 | const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) | 596 | expect(body.data[0].comment.text).to.be.empty |
623 | expect(res1.body.data).to.have.lengthOf(1) | 597 | } |
624 | expect(res1.body.data[0].comment.text).to.be.empty | ||
625 | 598 | ||
626 | const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) | 599 | { |
627 | expect(res2.body.data).to.have.lengthOf(1) | 600 | const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' }) |
628 | expect(res2.body.data[0].comment.text).to.equal('comment server 1') | 601 | expect(body.data).to.have.lengthOf(1) |
602 | expect(body.data[0].comment.text).to.equal('comment server 1') | ||
629 | } | 603 | } |
630 | }) | 604 | }) |
631 | }) | 605 | }) |
@@ -655,19 +629,19 @@ describe('Test abuses', function () { | |||
655 | const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) | 629 | const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) |
656 | 630 | ||
657 | const reason = 'it is a bad account' | 631 | const reason = 'it is a bad account' |
658 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) | 632 | await commands[0].report({ accountId: account.id, reason }) |
659 | 633 | ||
660 | await waitJobs(servers) | 634 | await waitJobs(servers) |
661 | }) | 635 | }) |
662 | 636 | ||
663 | it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { | 637 | it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { |
664 | { | 638 | { |
665 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | 639 | const body = await commands[0].getAdminList({ filter: 'account' }) |
666 | 640 | ||
667 | expect(res.body.total).to.equal(1) | 641 | expect(body.total).to.equal(1) |
668 | expect(res.body.data).to.have.lengthOf(1) | 642 | expect(body.data).to.have.lengthOf(1) |
669 | 643 | ||
670 | const abuse: AdminAbuse = res.body.data[0] | 644 | const abuse = body.data[0] |
671 | expect(abuse.reason).to.equal('it is a bad account') | 645 | expect(abuse.reason).to.equal('it is a bad account') |
672 | 646 | ||
673 | expect(abuse.reporterAccount.name).to.equal('root') | 647 | expect(abuse.reporterAccount.name).to.equal('root') |
@@ -681,9 +655,9 @@ describe('Test abuses', function () { | |||
681 | } | 655 | } |
682 | 656 | ||
683 | { | 657 | { |
684 | const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | 658 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
685 | expect(res.body.total).to.equal(0) | 659 | expect(body.total).to.equal(0) |
686 | expect(res.body.data.length).to.equal(0) | 660 | expect(body.data.length).to.equal(0) |
687 | } | 661 | } |
688 | }) | 662 | }) |
689 | 663 | ||
@@ -693,48 +667,52 @@ describe('Test abuses', function () { | |||
693 | const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) | 667 | const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) |
694 | 668 | ||
695 | const reason = 'it is a really bad account' | 669 | const reason = 'it is a really bad account' |
696 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) | 670 | await commands[0].report({ accountId: account.id, reason }) |
697 | 671 | ||
698 | await waitJobs(servers) | 672 | await waitJobs(servers) |
699 | }) | 673 | }) |
700 | 674 | ||
701 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | 675 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { |
702 | const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | 676 | { |
703 | expect(res1.body.total).to.equal(2) | 677 | const body = await commands[0].getAdminList({ filter: 'account' }) |
704 | expect(res1.body.data.length).to.equal(2) | 678 | expect(body.total).to.equal(2) |
679 | expect(body.data.length).to.equal(2) | ||
705 | 680 | ||
706 | const abuse: AdminAbuse = res1.body.data[0] | 681 | const abuse: AdminAbuse = body.data[0] |
707 | expect(abuse.reason).to.equal('it is a bad account') | 682 | expect(abuse.reason).to.equal('it is a bad account') |
708 | 683 | ||
709 | const abuse2: AdminAbuse = res1.body.data[1] | 684 | const abuse2: AdminAbuse = body.data[1] |
710 | expect(abuse2.reason).to.equal('it is a really bad account') | 685 | expect(abuse2.reason).to.equal('it is a really bad account') |
711 | 686 | ||
712 | expect(abuse2.reporterAccount.name).to.equal('root') | 687 | expect(abuse2.reporterAccount.name).to.equal('root') |
713 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | 688 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) |
714 | 689 | ||
715 | expect(abuse2.video).to.be.null | 690 | expect(abuse2.video).to.be.null |
716 | expect(abuse2.comment).to.be.null | 691 | expect(abuse2.comment).to.be.null |
717 | 692 | ||
718 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | 693 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
719 | expect(abuse2.state.label).to.equal('Pending') | 694 | expect(abuse2.state.label).to.equal('Pending') |
720 | 695 | ||
721 | expect(abuse2.moderationComment).to.be.null | 696 | expect(abuse2.moderationComment).to.be.null |
697 | } | ||
722 | 698 | ||
723 | const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) | 699 | { |
724 | expect(res2.body.total).to.equal(1) | 700 | const body = await commands[1].getAdminList({ filter: 'account' }) |
725 | expect(res2.body.data.length).to.equal(1) | 701 | expect(body.total).to.equal(1) |
702 | expect(body.data.length).to.equal(1) | ||
726 | 703 | ||
727 | abuseServer2 = res2.body.data[0] | 704 | abuseServer2 = body.data[0] |
728 | 705 | ||
729 | expect(abuseServer2.reason).to.equal('it is a really bad account') | 706 | expect(abuseServer2.reason).to.equal('it is a really bad account') |
730 | 707 | ||
731 | expect(abuseServer2.reporterAccount.name).to.equal('root') | 708 | expect(abuseServer2.reporterAccount.name).to.equal('root') |
732 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | 709 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) |
733 | 710 | ||
734 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | 711 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
735 | expect(abuseServer2.state.label).to.equal('Pending') | 712 | expect(abuseServer2.state.label).to.equal('Pending') |
736 | 713 | ||
737 | expect(abuseServer2.moderationComment).to.be.null | 714 | expect(abuseServer2.moderationComment).to.be.null |
715 | } | ||
738 | }) | 716 | }) |
739 | 717 | ||
740 | it('Should keep the account abuse when deleting the account', async function () { | 718 | it('Should keep the account abuse when deleting the account', async function () { |
@@ -745,32 +723,32 @@ describe('Test abuses', function () { | |||
745 | 723 | ||
746 | await waitJobs(servers) | 724 | await waitJobs(servers) |
747 | 725 | ||
748 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | 726 | const body = await commands[0].getAdminList({ filter: 'account' }) |
749 | expect(res.body.total).to.equal(2) | 727 | expect(body.total).to.equal(2) |
750 | expect(res.body.data).to.have.lengthOf(2) | 728 | expect(body.data).to.have.lengthOf(2) |
751 | 729 | ||
752 | const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account') | 730 | const abuse = body.data.find(a => a.reason === 'it is a really bad account') |
753 | expect(abuse).to.not.be.undefined | 731 | expect(abuse).to.not.be.undefined |
754 | }) | 732 | }) |
755 | 733 | ||
756 | it('Should delete the account abuse', async function () { | 734 | it('Should delete the account abuse', async function () { |
757 | this.timeout(10000) | 735 | this.timeout(10000) |
758 | 736 | ||
759 | await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) | 737 | await commands[1].delete({ abuseId: abuseServer2.id }) |
760 | 738 | ||
761 | await waitJobs(servers) | 739 | await waitJobs(servers) |
762 | 740 | ||
763 | { | 741 | { |
764 | const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) | 742 | const body = await commands[1].getAdminList({ filter: 'account' }) |
765 | expect(res.body.total).to.equal(0) | 743 | expect(body.total).to.equal(0) |
766 | expect(res.body.data.length).to.equal(0) | 744 | expect(body.data.length).to.equal(0) |
767 | } | 745 | } |
768 | 746 | ||
769 | { | 747 | { |
770 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | 748 | const body = await commands[0].getAdminList({ filter: 'account' }) |
771 | expect(res.body.total).to.equal(2) | 749 | expect(body.total).to.equal(2) |
772 | 750 | ||
773 | abuseServer1 = res.body.data[0] | 751 | abuseServer1 = body.data[0] |
774 | } | 752 | } |
775 | }) | 753 | }) |
776 | }) | 754 | }) |
@@ -778,20 +756,18 @@ describe('Test abuses', function () { | |||
778 | describe('Common actions on abuses', function () { | 756 | describe('Common actions on abuses', function () { |
779 | 757 | ||
780 | it('Should update the state of an abuse', async function () { | 758 | it('Should update the state of an abuse', async function () { |
781 | const body = { state: AbuseState.REJECTED } | 759 | await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } }) |
782 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) | ||
783 | 760 | ||
784 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) | 761 | const body = await commands[0].getAdminList({ id: abuseServer1.id }) |
785 | expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) | 762 | expect(body.data[0].state.id).to.equal(AbuseState.REJECTED) |
786 | }) | 763 | }) |
787 | 764 | ||
788 | it('Should add a moderation comment', async function () { | 765 | it('Should add a moderation comment', async function () { |
789 | const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } | 766 | await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } }) |
790 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) | ||
791 | 767 | ||
792 | const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) | 768 | const body = await commands[0].getAdminList({ id: abuseServer1.id }) |
793 | expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) | 769 | expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED) |
794 | expect(res.body.data[0].moderationComment).to.equal('It is valid') | 770 | expect(body.data[0].moderationComment).to.equal('Valid') |
795 | }) | 771 | }) |
796 | }) | 772 | }) |
797 | 773 | ||
@@ -802,18 +778,18 @@ describe('Test abuses', function () { | |||
802 | before(async function () { | 778 | before(async function () { |
803 | userAccessToken = await generateUserAccessToken(servers[0], 'user_42') | 779 | userAccessToken = await generateUserAccessToken(servers[0], 'user_42') |
804 | 780 | ||
805 | await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) | 781 | await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) |
806 | 782 | ||
807 | const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) | 783 | const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) |
808 | await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' }) | 784 | await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) |
809 | }) | 785 | }) |
810 | 786 | ||
811 | it('Should correctly list my abuses', async function () { | 787 | it('Should correctly list my abuses', async function () { |
812 | { | 788 | { |
813 | const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) | 789 | const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) |
814 | expect(res.body.total).to.equal(2) | 790 | expect(body.total).to.equal(2) |
815 | 791 | ||
816 | const abuses: UserAbuse[] = res.body.data | 792 | const abuses = body.data |
817 | expect(abuses[0].reason).to.equal('user reason 1') | 793 | expect(abuses[0].reason).to.equal('user reason 1') |
818 | expect(abuses[1].reason).to.equal('user reason 2') | 794 | expect(abuses[1].reason).to.equal('user reason 2') |
819 | 795 | ||
@@ -821,95 +797,77 @@ describe('Test abuses', function () { | |||
821 | } | 797 | } |
822 | 798 | ||
823 | { | 799 | { |
824 | const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) | 800 | const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) |
825 | expect(res.body.total).to.equal(2) | 801 | expect(body.total).to.equal(2) |
826 | 802 | ||
827 | const abuses: UserAbuse[] = res.body.data | 803 | const abuses: UserAbuse[] = body.data |
828 | expect(abuses[0].reason).to.equal('user reason 2') | 804 | expect(abuses[0].reason).to.equal('user reason 2') |
829 | } | 805 | } |
830 | 806 | ||
831 | { | 807 | { |
832 | const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) | 808 | const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) |
833 | expect(res.body.total).to.equal(2) | 809 | expect(body.total).to.equal(2) |
834 | 810 | ||
835 | const abuses: UserAbuse[] = res.body.data | 811 | const abuses: UserAbuse[] = body.data |
836 | expect(abuses[0].reason).to.equal('user reason 1') | 812 | expect(abuses[0].reason).to.equal('user reason 1') |
837 | } | 813 | } |
838 | }) | 814 | }) |
839 | 815 | ||
840 | it('Should correctly filter my abuses by id', async function () { | 816 | it('Should correctly filter my abuses by id', async function () { |
841 | const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 }) | 817 | const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 }) |
842 | 818 | expect(body.total).to.equal(1) | |
843 | expect(res.body.total).to.equal(1) | ||
844 | 819 | ||
845 | const abuses: UserAbuse[] = res.body.data | 820 | const abuses: UserAbuse[] = body.data |
846 | expect(abuses[0].reason).to.equal('user reason 1') | 821 | expect(abuses[0].reason).to.equal('user reason 1') |
847 | }) | 822 | }) |
848 | 823 | ||
849 | it('Should correctly filter my abuses by search', async function () { | 824 | it('Should correctly filter my abuses by search', async function () { |
850 | const res = await getUserAbusesList({ | 825 | const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' }) |
851 | url: servers[0].url, | 826 | expect(body.total).to.equal(1) |
852 | token: userAccessToken, | ||
853 | search: 'server 2' | ||
854 | }) | ||
855 | |||
856 | expect(res.body.total).to.equal(1) | ||
857 | 827 | ||
858 | const abuses: UserAbuse[] = res.body.data | 828 | const abuses: UserAbuse[] = body.data |
859 | expect(abuses[0].reason).to.equal('user reason 2') | 829 | expect(abuses[0].reason).to.equal('user reason 2') |
860 | }) | 830 | }) |
861 | 831 | ||
862 | it('Should correctly filter my abuses by state', async function () { | 832 | it('Should correctly filter my abuses by state', async function () { |
863 | const body = { state: AbuseState.REJECTED } | 833 | await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } }) |
864 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body) | ||
865 | |||
866 | const res = await getUserAbusesList({ | ||
867 | url: servers[0].url, | ||
868 | token: userAccessToken, | ||
869 | state: AbuseState.REJECTED | ||
870 | }) | ||
871 | 834 | ||
872 | expect(res.body.total).to.equal(1) | 835 | const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED }) |
836 | expect(body.total).to.equal(1) | ||
873 | 837 | ||
874 | const abuses: UserAbuse[] = res.body.data | 838 | const abuses: UserAbuse[] = body.data |
875 | expect(abuses[0].reason).to.equal('user reason 1') | 839 | expect(abuses[0].reason).to.equal('user reason 1') |
876 | }) | 840 | }) |
877 | }) | 841 | }) |
878 | 842 | ||
879 | describe('Abuse messages', async function () { | 843 | describe('Abuse messages', async function () { |
880 | let abuseId: number | 844 | let abuseId: number |
881 | let userAccessToken: string | 845 | let userToken: string |
882 | let abuseMessageUserId: number | 846 | let abuseMessageUserId: number |
883 | let abuseMessageModerationId: number | 847 | let abuseMessageModerationId: number |
884 | 848 | ||
885 | before(async function () { | 849 | before(async function () { |
886 | userAccessToken = await generateUserAccessToken(servers[0], 'user_43') | 850 | userToken = await generateUserAccessToken(servers[0], 'user_43') |
887 | |||
888 | const res = await reportAbuse({ | ||
889 | url: servers[0].url, | ||
890 | token: userAccessToken, | ||
891 | videoId: servers[0].video.id, | ||
892 | reason: 'user 43 reason 1' | ||
893 | }) | ||
894 | 851 | ||
895 | abuseId = res.body.abuse.id | 852 | const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) |
853 | abuseId = body.abuse.id | ||
896 | }) | 854 | }) |
897 | 855 | ||
898 | it('Should create some messages on the abuse', async function () { | 856 | it('Should create some messages on the abuse', async function () { |
899 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1') | 857 | await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' }) |
900 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2') | 858 | await commands[0].addMessage({ abuseId, message: 'message 2' }) |
901 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3') | 859 | await commands[0].addMessage({ abuseId, message: 'message 3' }) |
902 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4') | 860 | await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' }) |
903 | }) | 861 | }) |
904 | 862 | ||
905 | it('Should have the correct messages count when listing abuses', async function () { | 863 | it('Should have the correct messages count when listing abuses', async function () { |
906 | const results = await Promise.all([ | 864 | const results = await Promise.all([ |
907 | getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }), | 865 | commands[0].getAdminList({ start: 0, count: 50 }), |
908 | getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 }) | 866 | commands[0].getUserList({ token: userToken, start: 0, count: 50 }) |
909 | ]) | 867 | ]) |
910 | 868 | ||
911 | for (const res of results) { | 869 | for (const body of results) { |
912 | const abuses: AdminAbuse[] = res.body.data | 870 | const abuses = body.data |
913 | const abuse = abuses.find(a => a.id === abuseId) | 871 | const abuse = abuses.find(a => a.id === abuseId) |
914 | expect(abuse.countMessages).to.equal(4) | 872 | expect(abuse.countMessages).to.equal(4) |
915 | } | 873 | } |
@@ -917,14 +875,14 @@ describe('Test abuses', function () { | |||
917 | 875 | ||
918 | it('Should correctly list messages of this abuse', async function () { | 876 | it('Should correctly list messages of this abuse', async function () { |
919 | const results = await Promise.all([ | 877 | const results = await Promise.all([ |
920 | listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), | 878 | commands[0].listMessages({ abuseId }), |
921 | listAbuseMessages(servers[0].url, userAccessToken, abuseId) | 879 | commands[0].listMessages({ token: userToken, abuseId }) |
922 | ]) | 880 | ]) |
923 | 881 | ||
924 | for (const res of results) { | 882 | for (const body of results) { |
925 | expect(res.body.total).to.equal(4) | 883 | expect(body.total).to.equal(4) |
926 | 884 | ||
927 | const abuseMessages: AbuseMessage[] = res.body.data | 885 | const abuseMessages: AbuseMessage[] = body.data |
928 | 886 | ||
929 | expect(abuseMessages[0].message).to.equal('message 1') | 887 | expect(abuseMessages[0].message).to.equal('message 1') |
930 | expect(abuseMessages[0].byModerator).to.be.false | 888 | expect(abuseMessages[0].byModerator).to.be.false |
@@ -948,19 +906,18 @@ describe('Test abuses', function () { | |||
948 | }) | 906 | }) |
949 | 907 | ||
950 | it('Should delete messages', async function () { | 908 | it('Should delete messages', async function () { |
951 | await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId) | 909 | await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId }) |
952 | await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId) | 910 | await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId }) |
953 | 911 | ||
954 | const results = await Promise.all([ | 912 | const results = await Promise.all([ |
955 | listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), | 913 | commands[0].listMessages({ abuseId }), |
956 | listAbuseMessages(servers[0].url, userAccessToken, abuseId) | 914 | commands[0].listMessages({ token: userToken, abuseId }) |
957 | ]) | 915 | ]) |
958 | 916 | ||
959 | for (const res of results) { | 917 | for (const body of results) { |
960 | expect(res.body.total).to.equal(2) | 918 | expect(body.total).to.equal(2) |
961 | |||
962 | const abuseMessages: AbuseMessage[] = res.body.data | ||
963 | 919 | ||
920 | const abuseMessages: AbuseMessage[] = body.data | ||
964 | expect(abuseMessages[0].message).to.equal('message 2') | 921 | expect(abuseMessages[0].message).to.equal('message 2') |
965 | expect(abuseMessages[1].message).to.equal('message 4') | 922 | expect(abuseMessages[1].message).to.equal('message 4') |
966 | } | 923 | } |
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index a7671696f..f77719c68 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -2,11 +2,23 @@ | |||
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 { | 5 | import { |
7 | addAbuseMessage, | 6 | addUserSubscription, |
8 | addVideoCommentThread, | 7 | addVideoCommentThread, |
9 | addVideoToBlacklist, | 8 | addVideoToBlacklist, |
9 | checkAbuseStateChange, | ||
10 | checkAutoInstanceFollowing, | ||
11 | CheckerBaseParams, | ||
12 | checkNewAbuseMessage, | ||
13 | checkNewAccountAbuseForModerators, | ||
14 | checkNewBlacklistOnMyVideo, | ||
15 | checkNewCommentAbuseForModerators, | ||
16 | checkNewInstanceFollower, | ||
17 | checkNewVideoAbuseForModerators, | ||
18 | checkNewVideoFromSubscription, | ||
19 | checkUserRegistered, | ||
20 | checkVideoAutoBlacklistForModerators, | ||
21 | checkVideoIsPublished, | ||
10 | cleanupTests, | 22 | cleanupTests, |
11 | createUser, | 23 | createUser, |
12 | follow, | 24 | follow, |
@@ -17,38 +29,20 @@ import { | |||
17 | getVideoIdFromUUID, | 29 | getVideoIdFromUUID, |
18 | immutableAssign, | 30 | immutableAssign, |
19 | MockInstancesIndex, | 31 | MockInstancesIndex, |
32 | MockSmtpServer, | ||
33 | prepareNotificationsTest, | ||
20 | registerUser, | 34 | registerUser, |
35 | removeUserSubscription, | ||
21 | removeVideoFromBlacklist, | 36 | removeVideoFromBlacklist, |
22 | reportAbuse, | 37 | ServerInfo, |
23 | unfollow, | 38 | unfollow, |
24 | updateAbuse, | ||
25 | updateCustomConfig, | 39 | updateCustomConfig, |
26 | updateCustomSubConfig, | 40 | updateCustomSubConfig, |
27 | wait | 41 | uploadVideo, |
28 | } from '../../../../shared/extra-utils' | 42 | wait, |
29 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | 43 | waitJobs |
30 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | 44 | } from '@shared/extra-utils' |
31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 45 | import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' |
32 | import { | ||
33 | checkAbuseStateChange, | ||
34 | checkAutoInstanceFollowing, | ||
35 | CheckerBaseParams, | ||
36 | checkNewAbuseMessage, | ||
37 | checkNewAccountAbuseForModerators, | ||
38 | checkNewBlacklistOnMyVideo, | ||
39 | checkNewCommentAbuseForModerators, | ||
40 | checkNewInstanceFollower, | ||
41 | checkNewVideoAbuseForModerators, | ||
42 | checkNewVideoFromSubscription, | ||
43 | checkUserRegistered, | ||
44 | checkVideoAutoBlacklistForModerators, | ||
45 | checkVideoIsPublished, | ||
46 | prepareNotificationsTest | ||
47 | } from '../../../../shared/extra-utils/users/user-notifications' | ||
48 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | ||
49 | import { CustomConfig } from '../../../../shared/models/server' | ||
50 | import { UserNotification } from '../../../../shared/models/users' | ||
51 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
52 | 46 | ||
53 | describe('Test moderation notifications', function () { | 47 | describe('Test moderation notifications', function () { |
54 | let servers: ServerInfo[] = [] | 48 | let servers: ServerInfo[] = [] |
@@ -89,7 +83,7 @@ describe('Test moderation notifications', function () { | |||
89 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 83 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) |
90 | const video = resVideo.body.video | 84 | const video = resVideo.body.video |
91 | 85 | ||
92 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) | 86 | await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) |
93 | 87 | ||
94 | await waitJobs(servers) | 88 | await waitJobs(servers) |
95 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 89 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
@@ -105,7 +99,7 @@ describe('Test moderation notifications', function () { | |||
105 | await waitJobs(servers) | 99 | await waitJobs(servers) |
106 | 100 | ||
107 | const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) | 101 | const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) |
108 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'super reason' }) | 102 | await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) |
109 | 103 | ||
110 | await waitJobs(servers) | 104 | await waitJobs(servers) |
111 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 105 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
@@ -122,7 +116,7 @@ describe('Test moderation notifications', function () { | |||
122 | 116 | ||
123 | await waitJobs(servers) | 117 | await waitJobs(servers) |
124 | 118 | ||
125 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) | 119 | await servers[0].abusesCommand.report({ commentId: comment.id, reason: 'super reason' }) |
126 | 120 | ||
127 | await waitJobs(servers) | 121 | await waitJobs(servers) |
128 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | 122 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') |
@@ -140,7 +134,7 @@ describe('Test moderation notifications', function () { | |||
140 | 134 | ||
141 | const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) | 135 | const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) |
142 | const commentId = resComments.body.data[0].id | 136 | const commentId = resComments.body.data[0].id |
143 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, commentId, reason: 'super reason' }) | 137 | await servers[1].abusesCommand.report({ commentId, reason: 'super reason' }) |
144 | 138 | ||
145 | await waitJobs(servers) | 139 | await waitJobs(servers) |
146 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | 140 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') |
@@ -153,7 +147,7 @@ describe('Test moderation notifications', function () { | |||
153 | const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) | 147 | const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) |
154 | const accountId = resUser.body.user.account.id | 148 | const accountId = resUser.body.user.account.id |
155 | 149 | ||
156 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId, reason: 'super reason' }) | 150 | await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) |
157 | 151 | ||
158 | await waitJobs(servers) | 152 | await waitJobs(servers) |
159 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | 153 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') |
@@ -169,7 +163,7 @@ describe('Test moderation notifications', function () { | |||
169 | await waitJobs(servers) | 163 | await waitJobs(servers) |
170 | 164 | ||
171 | const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) | 165 | const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) |
172 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, accountId: resAccount.body.id, reason: 'super reason' }) | 166 | await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' }) |
173 | 167 | ||
174 | await waitJobs(servers) | 168 | await waitJobs(servers) |
175 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | 169 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') |
@@ -192,14 +186,14 @@ describe('Test moderation notifications', function () { | |||
192 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | 186 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) |
193 | const video = resVideo.body.video | 187 | const video = resVideo.body.video |
194 | 188 | ||
195 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 189 | const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) |
196 | abuseId = res.body.abuse.id | 190 | abuseId = body.abuse.id |
197 | }) | 191 | }) |
198 | 192 | ||
199 | it('Should send a notification to reporter if the abuse has been accepted', async function () { | 193 | it('Should send a notification to reporter if the abuse has been accepted', async function () { |
200 | this.timeout(10000) | 194 | this.timeout(10000) |
201 | 195 | ||
202 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.ACCEPTED }) | 196 | await servers[0].abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
203 | await waitJobs(servers) | 197 | await waitJobs(servers) |
204 | 198 | ||
205 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') | 199 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') |
@@ -208,7 +202,7 @@ describe('Test moderation notifications', function () { | |||
208 | it('Should send a notification to reporter if the abuse has been rejected', async function () { | 202 | it('Should send a notification to reporter if the abuse has been rejected', async function () { |
209 | this.timeout(10000) | 203 | this.timeout(10000) |
210 | 204 | ||
211 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.REJECTED }) | 205 | await servers[0].abusesCommand.update({ abuseId, body: { state: AbuseState.REJECTED } }) |
212 | await waitJobs(servers) | 206 | await waitJobs(servers) |
213 | 207 | ||
214 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') | 208 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') |
@@ -241,13 +235,13 @@ describe('Test moderation notifications', function () { | |||
241 | const video = resVideo.body.video | 235 | const video = resVideo.body.video |
242 | 236 | ||
243 | { | 237 | { |
244 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 238 | const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) |
245 | abuseId = res.body.abuse.id | 239 | abuseId = body.abuse.id |
246 | } | 240 | } |
247 | 241 | ||
248 | { | 242 | { |
249 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) | 243 | const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) |
250 | abuseId2 = res.body.abuse.id | 244 | abuseId2 = body.abuse.id |
251 | } | 245 | } |
252 | }) | 246 | }) |
253 | 247 | ||
@@ -255,7 +249,7 @@ describe('Test moderation notifications', function () { | |||
255 | this.timeout(10000) | 249 | this.timeout(10000) |
256 | 250 | ||
257 | const message = 'my super message to users' | 251 | const message = 'my super message to users' |
258 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) | 252 | await servers[0].abusesCommand.addMessage({ abuseId, message }) |
259 | await waitJobs(servers) | 253 | await waitJobs(servers) |
260 | 254 | ||
261 | await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') | 255 | await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') |
@@ -265,7 +259,7 @@ describe('Test moderation notifications', function () { | |||
265 | this.timeout(10000) | 259 | this.timeout(10000) |
266 | 260 | ||
267 | const message = 'my super message that should not be sent to the admin' | 261 | const message = 'my super message that should not be sent to the admin' |
268 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) | 262 | await servers[0].abusesCommand.addMessage({ abuseId, message }) |
269 | await waitJobs(servers) | 263 | await waitJobs(servers) |
270 | 264 | ||
271 | await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') | 265 | await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') |
@@ -275,7 +269,7 @@ describe('Test moderation notifications', function () { | |||
275 | this.timeout(10000) | 269 | this.timeout(10000) |
276 | 270 | ||
277 | const message = 'my super message to moderators' | 271 | const message = 'my super message to moderators' |
278 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) | 272 | await servers[0].abusesCommand.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) |
279 | await waitJobs(servers) | 273 | await waitJobs(servers) |
280 | 274 | ||
281 | await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') | 275 | await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') |
@@ -285,7 +279,7 @@ describe('Test moderation notifications', function () { | |||
285 | this.timeout(10000) | 279 | this.timeout(10000) |
286 | 280 | ||
287 | const message = 'my super message that should not be sent to reporter' | 281 | const message = 'my super message that should not be sent to reporter' |
288 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) | 282 | await servers[0].abusesCommand.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) |
289 | await waitJobs(servers) | 283 | await waitJobs(servers) |
290 | 284 | ||
291 | await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') | 285 | await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') |
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 41071692a..85844ae9d 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts | |||
@@ -12,7 +12,6 @@ import { | |||
12 | createUser, | 12 | createUser, |
13 | flushAndRunServer, | 13 | flushAndRunServer, |
14 | removeVideoFromBlacklist, | 14 | removeVideoFromBlacklist, |
15 | reportAbuse, | ||
16 | resetPassword, | 15 | resetPassword, |
17 | ServerInfo, | 16 | ServerInfo, |
18 | setAccessTokensToServers, | 17 | setAccessTokensToServers, |
@@ -190,7 +189,7 @@ describe('Test emails', function () { | |||
190 | this.timeout(10000) | 189 | this.timeout(10000) |
191 | 190 | ||
192 | const reason = 'my super bad reason' | 191 | const reason = 'my super bad reason' |
193 | await reportAbuse({ url: server.url, token: server.accessToken, videoId, reason }) | 192 | await server.abusesCommand.report({ videoId, reason }) |
194 | 193 | ||
195 | await waitJobs(server) | 194 | await waitJobs(server) |
196 | expect(emails).to.have.lengthOf(3) | 195 | expect(emails).to.have.lengthOf(3) |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 87ba775f6..6bfc7cfe5 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -2,9 +2,7 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { CustomConfig, OAuth2ErrorCode } from '@shared/models/server' | ||
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
8 | import { | 6 | import { |
9 | addVideoCommentThread, | 7 | addVideoCommentThread, |
10 | blockUser, | 8 | blockUser, |
@@ -13,13 +11,14 @@ import { | |||
13 | createUser, | 11 | createUser, |
14 | deleteMe, | 12 | deleteMe, |
15 | flushAndRunServer, | 13 | flushAndRunServer, |
14 | follow, | ||
16 | getAccountRatings, | 15 | getAccountRatings, |
17 | getAdminAbusesList, | ||
18 | getBlacklistedVideosList, | 16 | getBlacklistedVideosList, |
19 | getCustomConfig, | 17 | getCustomConfig, |
20 | getMyUserInformation, | 18 | getMyUserInformation, |
21 | getMyUserVideoQuotaUsed, | 19 | getMyUserVideoQuotaUsed, |
22 | getMyUserVideoRating, | 20 | getMyUserVideoRating, |
21 | getMyVideos, | ||
23 | getUserInformation, | 22 | getUserInformation, |
24 | getUsersList, | 23 | getUsersList, |
25 | getUsersListPaginationAndSort, | 24 | getUsersListPaginationAndSort, |
@@ -28,18 +27,19 @@ import { | |||
28 | installPlugin, | 27 | installPlugin, |
29 | killallServers, | 28 | killallServers, |
30 | login, | 29 | login, |
30 | logout, | ||
31 | makePutBodyRequest, | 31 | makePutBodyRequest, |
32 | rateVideo, | 32 | rateVideo, |
33 | refreshToken, | ||
33 | registerUserWithChannel, | 34 | registerUserWithChannel, |
34 | removeUser, | 35 | removeUser, |
35 | removeVideo, | 36 | removeVideo, |
36 | reportAbuse, | ||
37 | reRunServer, | 37 | reRunServer, |
38 | ServerInfo, | 38 | ServerInfo, |
39 | setAccessTokensToServers, | ||
39 | setTokenField, | 40 | setTokenField, |
40 | testImage, | 41 | testImage, |
41 | unblockUser, | 42 | unblockUser, |
42 | updateAbuse, | ||
43 | updateCustomSubConfig, | 43 | updateCustomSubConfig, |
44 | updateMyAvatar, | 44 | updateMyAvatar, |
45 | updateMyUser, | 45 | updateMyUser, |
@@ -47,11 +47,8 @@ import { | |||
47 | uploadVideo, | 47 | uploadVideo, |
48 | userLogin, | 48 | userLogin, |
49 | waitJobs | 49 | waitJobs |
50 | } from '../../../../shared/extra-utils' | 50 | } from '@shared/extra-utils' |
51 | import { follow } from '../../../../shared/extra-utils/server/follows' | 51 | import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' |
52 | import { logout, refreshToken, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
53 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | ||
54 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
55 | 52 | ||
56 | const expect = chai.expect | 53 | const expect = chai.expect |
57 | 54 | ||
@@ -1002,10 +999,10 @@ describe('Test users', function () { | |||
1002 | 999 | ||
1003 | it('Should report correct abuses counts', async function () { | 1000 | it('Should report correct abuses counts', async function () { |
1004 | const reason = 'my super bad reason' | 1001 | const reason = 'my super bad reason' |
1005 | await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) | 1002 | await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) |
1006 | 1003 | ||
1007 | const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) | 1004 | const body1 = await server.abusesCommand.getAdminList() |
1008 | const abuseId = res1.body.data[0].id | 1005 | const abuseId = body1.data[0].id |
1009 | 1006 | ||
1010 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | 1007 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) |
1011 | const user2: User = res2.body | 1008 | const user2: User = res2.body |
@@ -1013,8 +1010,7 @@ describe('Test users', function () { | |||
1013 | expect(user2.abusesCount).to.equal(1) // number of incriminations | 1010 | expect(user2.abusesCount).to.equal(1) // number of incriminations |
1014 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created | 1011 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created |
1015 | 1012 | ||
1016 | const body: AbuseUpdate = { state: AbuseState.ACCEPTED } | 1013 | await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
1017 | await updateAbuse(server.url, server.accessToken, abuseId, body) | ||
1018 | 1014 | ||
1019 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) | 1015 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) |
1020 | const user3: User = res3.body | 1016 | const user3: User = res3.body |