diff options
Diffstat (limited to 'server/tests/api/moderation/blocklist.ts')
-rw-r--r-- | server/tests/api/moderation/blocklist.ts | 100 |
1 files changed, 37 insertions, 63 deletions
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 9ca6324c2..1b8860571 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts | |||
@@ -3,46 +3,27 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | addAccountToAccountBlocklist, | ||
7 | addAccountToServerBlocklist, | ||
8 | addServerToAccountBlocklist, | ||
9 | addServerToServerBlocklist, | ||
10 | addVideoCommentReply, | 6 | addVideoCommentReply, |
11 | addVideoCommentThread, | 7 | addVideoCommentThread, |
8 | BlocklistCommand, | ||
12 | cleanupTests, | 9 | cleanupTests, |
13 | createUser, | 10 | createUser, |
14 | deleteVideoComment, | 11 | deleteVideoComment, |
15 | doubleFollow, | 12 | doubleFollow, |
16 | findCommentId, | 13 | findCommentId, |
17 | flushAndRunMultipleServers, | 14 | flushAndRunMultipleServers, |
18 | getAccountBlocklistByAccount, | ||
19 | getAccountBlocklistByServer, | ||
20 | getServerBlocklistByAccount, | ||
21 | getServerBlocklistByServer, | ||
22 | getUserNotifications, | 15 | getUserNotifications, |
23 | getVideoCommentThreads, | 16 | getVideoCommentThreads, |
24 | getVideosList, | 17 | getVideosList, |
25 | getVideosListWithToken, | 18 | getVideosListWithToken, |
26 | getVideoThreadComments, | 19 | getVideoThreadComments, |
27 | removeAccountFromAccountBlocklist, | ||
28 | removeAccountFromServerBlocklist, | ||
29 | removeServerFromAccountBlocklist, | ||
30 | removeServerFromServerBlocklist, | ||
31 | ServerInfo, | 20 | ServerInfo, |
32 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
33 | uploadVideo, | 22 | uploadVideo, |
34 | userLogin, | 23 | userLogin, |
35 | waitJobs | 24 | waitJobs |
36 | } from '@shared/extra-utils' | 25 | } from '@shared/extra-utils' |
37 | import { | 26 | import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' |
38 | AccountBlock, | ||
39 | ServerBlock, | ||
40 | UserNotification, | ||
41 | UserNotificationType, | ||
42 | Video, | ||
43 | VideoComment, | ||
44 | VideoCommentThreadTree | ||
45 | } from '@shared/models' | ||
46 | 27 | ||
47 | const expect = chai.expect | 28 | const expect = chai.expect |
48 | 29 | ||
@@ -108,6 +89,8 @@ describe('Test blocklist', function () { | |||
108 | let userModeratorToken: string | 89 | let userModeratorToken: string |
109 | let userToken2: string | 90 | let userToken2: string |
110 | 91 | ||
92 | let command: BlocklistCommand | ||
93 | |||
111 | before(async function () { | 94 | before(async function () { |
112 | this.timeout(120000) | 95 | this.timeout(120000) |
113 | 96 | ||
@@ -167,6 +150,8 @@ describe('Test blocklist', function () { | |||
167 | } | 150 | } |
168 | 151 | ||
169 | await waitJobs(servers) | 152 | await waitJobs(servers) |
153 | |||
154 | command = servers[0].blocklistCommand | ||
170 | }) | 155 | }) |
171 | 156 | ||
172 | describe('User blocklist', function () { | 157 | describe('User blocklist', function () { |
@@ -181,7 +166,7 @@ describe('Test blocklist', function () { | |||
181 | }) | 166 | }) |
182 | 167 | ||
183 | it('Should block a remote account', async function () { | 168 | it('Should block a remote account', async function () { |
184 | await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) | 169 | await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) |
185 | }) | 170 | }) |
186 | 171 | ||
187 | it('Should hide its videos', async function () { | 172 | it('Should hide its videos', async function () { |
@@ -195,7 +180,7 @@ describe('Test blocklist', function () { | |||
195 | }) | 180 | }) |
196 | 181 | ||
197 | it('Should block a local account', async function () { | 182 | it('Should block a local account', async function () { |
198 | await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') | 183 | await command.addToMyBlocklist({ account: 'user1' }) |
199 | }) | 184 | }) |
200 | 185 | ||
201 | it('Should hide its videos', async function () { | 186 | it('Should hide its videos', async function () { |
@@ -251,12 +236,10 @@ describe('Test blocklist', function () { | |||
251 | 236 | ||
252 | it('Should list blocked accounts', async function () { | 237 | it('Should list blocked accounts', async function () { |
253 | { | 238 | { |
254 | const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') | 239 | const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) |
255 | const blocks: AccountBlock[] = res.body.data | 240 | expect(body.total).to.equal(2) |
256 | 241 | ||
257 | expect(res.body.total).to.equal(2) | 242 | const block = body.data[0] |
258 | |||
259 | const block = blocks[0] | ||
260 | expect(block.byAccount.displayName).to.equal('root') | 243 | expect(block.byAccount.displayName).to.equal('root') |
261 | expect(block.byAccount.name).to.equal('root') | 244 | expect(block.byAccount.name).to.equal('root') |
262 | expect(block.blockedAccount.displayName).to.equal('user2') | 245 | expect(block.blockedAccount.displayName).to.equal('user2') |
@@ -265,12 +248,10 @@ describe('Test blocklist', function () { | |||
265 | } | 248 | } |
266 | 249 | ||
267 | { | 250 | { |
268 | const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') | 251 | const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) |
269 | const blocks: AccountBlock[] = res.body.data | 252 | expect(body.total).to.equal(2) |
270 | |||
271 | expect(res.body.total).to.equal(2) | ||
272 | 253 | ||
273 | const block = blocks[0] | 254 | const block = body.data[0] |
274 | expect(block.byAccount.displayName).to.equal('root') | 255 | expect(block.byAccount.displayName).to.equal('root') |
275 | expect(block.byAccount.name).to.equal('root') | 256 | expect(block.byAccount.name).to.equal('root') |
276 | expect(block.blockedAccount.displayName).to.equal('user1') | 257 | expect(block.blockedAccount.displayName).to.equal('user1') |
@@ -335,7 +316,7 @@ describe('Test blocklist', function () { | |||
335 | }) | 316 | }) |
336 | 317 | ||
337 | it('Should unblock the remote account', async function () { | 318 | it('Should unblock the remote account', async function () { |
338 | await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) | 319 | await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) |
339 | }) | 320 | }) |
340 | 321 | ||
341 | it('Should display its videos', async function () { | 322 | it('Should display its videos', async function () { |
@@ -374,7 +355,7 @@ describe('Test blocklist', function () { | |||
374 | }) | 355 | }) |
375 | 356 | ||
376 | it('Should unblock the local account', async function () { | 357 | it('Should unblock the local account', async function () { |
377 | await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') | 358 | await command.removeFromMyBlocklist({ account: 'user1' }) |
378 | }) | 359 | }) |
379 | 360 | ||
380 | it('Should display its comments', function () { | 361 | it('Should display its comments', function () { |
@@ -402,6 +383,7 @@ describe('Test blocklist', function () { | |||
402 | }) | 383 | }) |
403 | 384 | ||
404 | describe('When managing server blocklist', function () { | 385 | describe('When managing server blocklist', function () { |
386 | |||
405 | it('Should list all videos', function () { | 387 | it('Should list all videos', function () { |
406 | return checkAllVideos(servers[0].url, servers[0].accessToken) | 388 | return checkAllVideos(servers[0].url, servers[0].accessToken) |
407 | }) | 389 | }) |
@@ -411,7 +393,7 @@ describe('Test blocklist', function () { | |||
411 | }) | 393 | }) |
412 | 394 | ||
413 | it('Should block a remote server', async function () { | 395 | it('Should block a remote server', async function () { |
414 | await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) | 396 | await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port }) |
415 | }) | 397 | }) |
416 | 398 | ||
417 | it('Should hide its videos', async function () { | 399 | it('Should hide its videos', async function () { |
@@ -464,19 +446,17 @@ describe('Test blocklist', function () { | |||
464 | }) | 446 | }) |
465 | 447 | ||
466 | it('Should list blocked servers', async function () { | 448 | it('Should list blocked servers', async function () { |
467 | const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') | 449 | const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) |
468 | const blocks: ServerBlock[] = res.body.data | 450 | expect(body.total).to.equal(1) |
469 | |||
470 | expect(res.body.total).to.equal(1) | ||
471 | 451 | ||
472 | const block = blocks[0] | 452 | const block = body.data[0] |
473 | expect(block.byAccount.displayName).to.equal('root') | 453 | expect(block.byAccount.displayName).to.equal('root') |
474 | expect(block.byAccount.name).to.equal('root') | 454 | expect(block.byAccount.name).to.equal('root') |
475 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) | 455 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) |
476 | }) | 456 | }) |
477 | 457 | ||
478 | it('Should unblock the remote server', async function () { | 458 | it('Should unblock the remote server', async function () { |
479 | await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) | 459 | await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) |
480 | }) | 460 | }) |
481 | 461 | ||
482 | it('Should display its videos', function () { | 462 | it('Should display its videos', function () { |
@@ -524,7 +504,7 @@ describe('Test blocklist', function () { | |||
524 | }) | 504 | }) |
525 | 505 | ||
526 | it('Should block a remote account', async function () { | 506 | it('Should block a remote account', async function () { |
527 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) | 507 | await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) |
528 | }) | 508 | }) |
529 | 509 | ||
530 | it('Should hide its videos', async function () { | 510 | it('Should hide its videos', async function () { |
@@ -540,7 +520,7 @@ describe('Test blocklist', function () { | |||
540 | }) | 520 | }) |
541 | 521 | ||
542 | it('Should block a local account', async function () { | 522 | it('Should block a local account', async function () { |
543 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') | 523 | await command.addToServerBlocklist({ account: 'user1' }) |
544 | }) | 524 | }) |
545 | 525 | ||
546 | it('Should hide its videos', async function () { | 526 | it('Should hide its videos', async function () { |
@@ -598,12 +578,10 @@ describe('Test blocklist', function () { | |||
598 | 578 | ||
599 | it('Should list blocked accounts', async function () { | 579 | it('Should list blocked accounts', async function () { |
600 | { | 580 | { |
601 | const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') | 581 | const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) |
602 | const blocks: AccountBlock[] = res.body.data | 582 | expect(body.total).to.equal(2) |
603 | |||
604 | expect(res.body.total).to.equal(2) | ||
605 | 583 | ||
606 | const block = blocks[0] | 584 | const block = body.data[0] |
607 | expect(block.byAccount.displayName).to.equal('peertube') | 585 | expect(block.byAccount.displayName).to.equal('peertube') |
608 | expect(block.byAccount.name).to.equal('peertube') | 586 | expect(block.byAccount.name).to.equal('peertube') |
609 | expect(block.blockedAccount.displayName).to.equal('user2') | 587 | expect(block.blockedAccount.displayName).to.equal('user2') |
@@ -612,12 +590,10 @@ describe('Test blocklist', function () { | |||
612 | } | 590 | } |
613 | 591 | ||
614 | { | 592 | { |
615 | const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') | 593 | const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) |
616 | const blocks: AccountBlock[] = res.body.data | 594 | expect(body.total).to.equal(2) |
617 | 595 | ||
618 | expect(res.body.total).to.equal(2) | 596 | const block = body.data[0] |
619 | |||
620 | const block = blocks[0] | ||
621 | expect(block.byAccount.displayName).to.equal('peertube') | 597 | expect(block.byAccount.displayName).to.equal('peertube') |
622 | expect(block.byAccount.name).to.equal('peertube') | 598 | expect(block.byAccount.name).to.equal('peertube') |
623 | expect(block.blockedAccount.displayName).to.equal('user1') | 599 | expect(block.blockedAccount.displayName).to.equal('user1') |
@@ -627,7 +603,7 @@ describe('Test blocklist', function () { | |||
627 | }) | 603 | }) |
628 | 604 | ||
629 | it('Should unblock the remote account', async function () { | 605 | it('Should unblock the remote account', async function () { |
630 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) | 606 | await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) |
631 | }) | 607 | }) |
632 | 608 | ||
633 | it('Should display its videos', async function () { | 609 | it('Should display its videos', async function () { |
@@ -643,7 +619,7 @@ describe('Test blocklist', function () { | |||
643 | }) | 619 | }) |
644 | 620 | ||
645 | it('Should unblock the local account', async function () { | 621 | it('Should unblock the local account', async function () { |
646 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') | 622 | await command.removeFromServerBlocklist({ account: 'user1' }) |
647 | }) | 623 | }) |
648 | 624 | ||
649 | it('Should display its comments', async function () { | 625 | it('Should display its comments', async function () { |
@@ -686,7 +662,7 @@ describe('Test blocklist', function () { | |||
686 | }) | 662 | }) |
687 | 663 | ||
688 | it('Should block a remote server', async function () { | 664 | it('Should block a remote server', async function () { |
689 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) | 665 | await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) |
690 | }) | 666 | }) |
691 | 667 | ||
692 | it('Should hide its videos', async function () { | 668 | it('Should hide its videos', async function () { |
@@ -758,19 +734,17 @@ describe('Test blocklist', function () { | |||
758 | }) | 734 | }) |
759 | 735 | ||
760 | it('Should list blocked servers', async function () { | 736 | it('Should list blocked servers', async function () { |
761 | const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') | 737 | const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) |
762 | const blocks: ServerBlock[] = res.body.data | 738 | expect(body.total).to.equal(1) |
763 | |||
764 | expect(res.body.total).to.equal(1) | ||
765 | 739 | ||
766 | const block = blocks[0] | 740 | const block = body.data[0] |
767 | expect(block.byAccount.displayName).to.equal('peertube') | 741 | expect(block.byAccount.displayName).to.equal('peertube') |
768 | expect(block.byAccount.name).to.equal('peertube') | 742 | expect(block.byAccount.name).to.equal('peertube') |
769 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) | 743 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) |
770 | }) | 744 | }) |
771 | 745 | ||
772 | it('Should unblock the remote server', async function () { | 746 | it('Should unblock the remote server', async function () { |
773 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) | 747 | await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) |
774 | }) | 748 | }) |
775 | 749 | ||
776 | it('Should list all videos', async function () { | 750 | it('Should list all videos', async function () { |