diff options
author | Chocobozzz <me@florianbigard.com> | 2019-12-19 10:35:47 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-12-19 11:34:00 +0100 |
commit | dddc8b1fe0c875f41c88f395b0d55cfea69add2c (patch) | |
tree | 06b84dc99f78d8422fc8eeda8a3372291660aed0 /server/tests | |
parent | 96f6278f3e5b35d6e812176c799088f88729a0b0 (diff) | |
download | PeerTube-dddc8b1fe0c875f41c88f395b0d55cfea69add2c.tar.gz PeerTube-dddc8b1fe0c875f41c88f395b0d55cfea69add2c.tar.zst PeerTube-dddc8b1fe0c875f41c88f395b0d55cfea69add2c.zip |
Don't notify on muted instance
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/users/blocklist.ts | 210 |
1 files changed, 204 insertions, 6 deletions
diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts index c25e85ada..09e72d068 100644 --- a/server/tests/api/users/blocklist.ts +++ b/server/tests/api/users/blocklist.ts | |||
@@ -2,10 +2,10 @@ | |||
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { AccountBlock, ServerBlock, Video } from '../../../../shared/index' | 5 | import { AccountBlock, ServerBlock, UserNotificationType, Video } from '../../../../shared/index' |
6 | import { | 6 | import { |
7 | cleanupTests, | 7 | cleanupTests, |
8 | createUser, | 8 | createUser, deleteVideoComment, |
9 | doubleFollow, | 9 | doubleFollow, |
10 | flushAndRunMultipleServers, | 10 | flushAndRunMultipleServers, |
11 | flushTests, | 11 | flushTests, |
@@ -38,6 +38,7 @@ import { | |||
38 | removeServerFromAccountBlocklist, | 38 | removeServerFromAccountBlocklist, |
39 | removeServerFromServerBlocklist | 39 | removeServerFromServerBlocklist |
40 | } from '../../../../shared/extra-utils/users/blocklist' | 40 | } from '../../../../shared/extra-utils/users/blocklist' |
41 | import { getUserNotifications } from '@shared/extra-utils/users/user-notifications' | ||
41 | 42 | ||
42 | const expect = chai.expect | 43 | const expect = chai.expect |
43 | 44 | ||
@@ -56,9 +57,10 @@ async function checkAllVideos (url: string, token: string) { | |||
56 | } | 57 | } |
57 | 58 | ||
58 | async function checkAllComments (url: string, token: string, videoUUID: string) { | 59 | async function checkAllComments (url: string, token: string, videoUUID: string) { |
59 | const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 5, '-createdAt', token) | 60 | const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) |
60 | 61 | ||
61 | const threads: VideoComment[] = resThreads.body.data | 62 | const allThreads: VideoComment[] = resThreads.body.data |
63 | const threads = allThreads.filter(t => t.isDeleted === false) | ||
62 | expect(threads).to.have.lengthOf(2) | 64 | expect(threads).to.have.lengthOf(2) |
63 | 65 | ||
64 | for (const thread of threads) { | 66 | for (const thread of threads) { |
@@ -69,6 +71,28 @@ async function checkAllComments (url: string, token: string, videoUUID: string) | |||
69 | } | 71 | } |
70 | } | 72 | } |
71 | 73 | ||
74 | async function checkCommentNotification ( | ||
75 | mainServer: ServerInfo, | ||
76 | comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, | ||
77 | check: 'presence' | 'absence' | ||
78 | ) { | ||
79 | const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) | ||
80 | const threadId = resComment.body.comment.id | ||
81 | |||
82 | await waitJobs([ mainServer, comment.server]) | ||
83 | |||
84 | const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) | ||
85 | const commentNotifications = res.body.data | ||
86 | .filter(n => n.comment && n.comment.id === threadId) | ||
87 | |||
88 | if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) | ||
89 | else expect(commentNotifications).to.have.lengthOf(0) | ||
90 | |||
91 | await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) | ||
92 | |||
93 | await waitJobs([ mainServer, comment.server]) | ||
94 | } | ||
95 | |||
72 | describe('Test blocklist', function () { | 96 | describe('Test blocklist', function () { |
73 | let servers: ServerInfo[] | 97 | let servers: ServerInfo[] |
74 | let videoUUID1: string | 98 | let videoUUID1: string |
@@ -189,6 +213,25 @@ describe('Test blocklist', function () { | |||
189 | } | 213 | } |
190 | }) | 214 | }) |
191 | 215 | ||
216 | it('Should not have notifications from blocked accounts', async function () { | ||
217 | this.timeout(20000) | ||
218 | |||
219 | { | ||
220 | const comment = { server: servers[ 0 ], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } | ||
221 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
222 | } | ||
223 | |||
224 | { | ||
225 | const comment = { | ||
226 | server: servers[ 0 ], | ||
227 | token: userToken1, | ||
228 | videoUUID: videoUUID2, | ||
229 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
230 | } | ||
231 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
232 | } | ||
233 | }) | ||
234 | |||
192 | it('Should list all the videos with another user', async function () { | 235 | it('Should list all the videos with another user', async function () { |
193 | return checkAllVideos(servers[ 0 ].url, userToken1) | 236 | return checkAllVideos(servers[ 0 ].url, userToken1) |
194 | }) | 237 | }) |
@@ -248,6 +291,25 @@ describe('Test blocklist', function () { | |||
248 | it('Should display its comments', function () { | 291 | it('Should display its comments', function () { |
249 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | 292 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) |
250 | }) | 293 | }) |
294 | |||
295 | it('Should have a notification from a non blocked account', async function () { | ||
296 | this.timeout(20000) | ||
297 | |||
298 | { | ||
299 | const comment = { server: servers[ 1 ], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } | ||
300 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
301 | } | ||
302 | |||
303 | { | ||
304 | const comment = { | ||
305 | server: servers[ 0 ], | ||
306 | token: userToken1, | ||
307 | videoUUID: videoUUID2, | ||
308 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
309 | } | ||
310 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
311 | } | ||
312 | }) | ||
251 | }) | 313 | }) |
252 | 314 | ||
253 | describe('When managing server blocklist', function () { | 315 | describe('When managing server blocklist', function () { |
@@ -280,7 +342,37 @@ describe('Test blocklist', function () { | |||
280 | return checkAllVideos(servers[ 0 ].url, userToken1) | 342 | return checkAllVideos(servers[ 0 ].url, userToken1) |
281 | }) | 343 | }) |
282 | 344 | ||
283 | it('Should hide its comments') | 345 | it('Should hide its comments', async function () { |
346 | this.timeout(10000) | ||
347 | |||
348 | const resThreads = await addVideoCommentThread(servers[ 1 ].url, userToken2, videoUUID1, 'hidden comment 2') | ||
349 | const threadId = resThreads.body.comment.id | ||
350 | |||
351 | await waitJobs(servers) | ||
352 | |||
353 | await checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | ||
354 | |||
355 | await deleteVideoComment(servers[ 1 ].url, userToken2, videoUUID1, threadId) | ||
356 | }) | ||
357 | |||
358 | it('Should not have notifications from blocked server', async function () { | ||
359 | this.timeout(20000) | ||
360 | |||
361 | { | ||
362 | const comment = { server: servers[ 1 ], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } | ||
363 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
364 | } | ||
365 | |||
366 | { | ||
367 | const comment = { | ||
368 | server: servers[ 1 ], | ||
369 | token: userToken2, | ||
370 | videoUUID: videoUUID1, | ||
371 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
372 | } | ||
373 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
374 | } | ||
375 | }) | ||
284 | 376 | ||
285 | it('Should list blocked servers', async function () { | 377 | it('Should list blocked servers', async function () { |
286 | const res = await getServerBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | 378 | const res = await getServerBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') |
@@ -305,6 +397,25 @@ describe('Test blocklist', function () { | |||
305 | it('Should display its comments', function () { | 397 | it('Should display its comments', function () { |
306 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | 398 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) |
307 | }) | 399 | }) |
400 | |||
401 | it('Should have notification from unblocked server', async function () { | ||
402 | this.timeout(20000) | ||
403 | |||
404 | { | ||
405 | const comment = { server: servers[ 1 ], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } | ||
406 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
407 | } | ||
408 | |||
409 | { | ||
410 | const comment = { | ||
411 | server: servers[ 1 ], | ||
412 | token: userToken2, | ||
413 | videoUUID: videoUUID1, | ||
414 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
415 | } | ||
416 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
417 | } | ||
418 | }) | ||
308 | }) | 419 | }) |
309 | }) | 420 | }) |
310 | 421 | ||
@@ -375,6 +486,25 @@ describe('Test blocklist', function () { | |||
375 | } | 486 | } |
376 | }) | 487 | }) |
377 | 488 | ||
489 | it('Should not have notification from blocked accounts by instance', async function () { | ||
490 | this.timeout(20000) | ||
491 | |||
492 | { | ||
493 | const comment = { server: servers[ 0 ], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } | ||
494 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
495 | } | ||
496 | |||
497 | { | ||
498 | const comment = { | ||
499 | server: servers[ 1 ], | ||
500 | token: userToken2, | ||
501 | videoUUID: videoUUID1, | ||
502 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
503 | } | ||
504 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
505 | } | ||
506 | }) | ||
507 | |||
378 | it('Should list blocked accounts', async function () { | 508 | it('Should list blocked accounts', async function () { |
379 | { | 509 | { |
380 | const res = await getAccountBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | 510 | const res = await getAccountBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') |
@@ -430,6 +560,25 @@ describe('Test blocklist', function () { | |||
430 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) | 560 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) |
431 | } | 561 | } |
432 | }) | 562 | }) |
563 | |||
564 | it('Should have notifications from unblocked accounts', async function () { | ||
565 | this.timeout(20000) | ||
566 | |||
567 | { | ||
568 | const comment = { server: servers[ 0 ], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' } | ||
569 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
570 | } | ||
571 | |||
572 | { | ||
573 | const comment = { | ||
574 | server: servers[ 1 ], | ||
575 | token: userToken2, | ||
576 | videoUUID: videoUUID1, | ||
577 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
578 | } | ||
579 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
580 | } | ||
581 | }) | ||
433 | }) | 582 | }) |
434 | 583 | ||
435 | describe('When managing server blocklist', function () { | 584 | describe('When managing server blocklist', function () { |
@@ -467,7 +616,37 @@ describe('Test blocklist', function () { | |||
467 | } | 616 | } |
468 | }) | 617 | }) |
469 | 618 | ||
470 | it('Should hide its comments') | 619 | it('Should hide its comments', async function () { |
620 | this.timeout(10000) | ||
621 | |||
622 | const resThreads = await addVideoCommentThread(servers[ 1 ].url, userToken2, videoUUID1, 'hidden comment 2') | ||
623 | const threadId = resThreads.body.comment.id | ||
624 | |||
625 | await waitJobs(servers) | ||
626 | |||
627 | await checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | ||
628 | |||
629 | await deleteVideoComment(servers[ 1 ].url, userToken2, videoUUID1, threadId) | ||
630 | }) | ||
631 | |||
632 | it('Should not have notification from blocked instances by instance', async function () { | ||
633 | this.timeout(20000) | ||
634 | |||
635 | { | ||
636 | const comment = { server: servers[ 1 ], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } | ||
637 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
638 | } | ||
639 | |||
640 | { | ||
641 | const comment = { | ||
642 | server: servers[ 1 ], | ||
643 | token: userToken2, | ||
644 | videoUUID: videoUUID1, | ||
645 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
646 | } | ||
647 | await checkCommentNotification(servers[ 0 ], comment, 'absence') | ||
648 | } | ||
649 | }) | ||
471 | 650 | ||
472 | it('Should list blocked servers', async function () { | 651 | it('Should list blocked servers', async function () { |
473 | const res = await getServerBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | 652 | const res = await getServerBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') |
@@ -496,6 +675,25 @@ describe('Test blocklist', function () { | |||
496 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) | 675 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) |
497 | } | 676 | } |
498 | }) | 677 | }) |
678 | |||
679 | it('Should have notification from unblocked instances', async function () { | ||
680 | this.timeout(20000) | ||
681 | |||
682 | { | ||
683 | const comment = { server: servers[ 1 ], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } | ||
684 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
685 | } | ||
686 | |||
687 | { | ||
688 | const comment = { | ||
689 | server: servers[ 1 ], | ||
690 | token: userToken2, | ||
691 | videoUUID: videoUUID1, | ||
692 | text: 'hello @root@localhost:' + servers[ 0 ].port | ||
693 | } | ||
694 | await checkCommentNotification(servers[ 0 ], comment, 'presence') | ||
695 | } | ||
696 | }) | ||
499 | }) | 697 | }) |
500 | }) | 698 | }) |
501 | 699 | ||