aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-08 15:51:46 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-10 14:02:41 +0200
commit310b5219b38427f0c2c7ba57225afdd8f3064380 (patch)
tree853ff7e4e66425ca47b0999384eeb08ed14b28ff /shared/extra-utils
parent811cef146c841ef8530bc812c05dfee77e0f2998 (diff)
downloadPeerTube-310b5219b38427f0c2c7ba57225afdd8f3064380.tar.gz
PeerTube-310b5219b38427f0c2c7ba57225afdd8f3064380.tar.zst
PeerTube-310b5219b38427f0c2c7ba57225afdd8f3064380.zip
Add new abuses tests
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/moderation/abuses.ts14
-rw-r--r--shared/extra-utils/server/servers.ts4
-rw-r--r--shared/extra-utils/users/user-notifications.ts75
3 files changed, 81 insertions, 12 deletions
diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts
index 1af703f92..62af9556e 100644
--- a/shared/extra-utils/moderation/abuses.ts
+++ b/shared/extra-utils/moderation/abuses.ts
@@ -57,10 +57,15 @@ function reportAbuse (options: {
57function getAbusesList (options: { 57function getAbusesList (options: {
58 url: string 58 url: string
59 token: string 59 token: string
60
61 start?: number
62 count?: number
63 sort?: string
64
60 id?: number 65 id?: number
61 predefinedReason?: AbusePredefinedReasonsString 66 predefinedReason?: AbusePredefinedReasonsString
62 search?: string 67 search?: string
63 filter?: AbuseFilter, 68 filter?: AbuseFilter
64 state?: AbuseState 69 state?: AbuseState
65 videoIs?: AbuseVideoIs 70 videoIs?: AbuseVideoIs
66 searchReporter?: string 71 searchReporter?: string
@@ -71,6 +76,9 @@ function getAbusesList (options: {
71 const { 76 const {
72 url, 77 url,
73 token, 78 token,
79 start,
80 count,
81 sort,
74 id, 82 id,
75 predefinedReason, 83 predefinedReason,
76 search, 84 search,
@@ -85,13 +93,15 @@ function getAbusesList (options: {
85 const path = '/api/v1/abuses' 93 const path = '/api/v1/abuses'
86 94
87 const query = { 95 const query = {
88 sort: 'createdAt',
89 id, 96 id,
90 predefinedReason, 97 predefinedReason,
91 search, 98 search,
92 state, 99 state,
93 filter, 100 filter,
94 videoIs, 101 videoIs,
102 start,
103 count,
104 sort: sort || 'createdAt',
95 searchReporter, 105 searchReporter,
96 searchReportee, 106 searchReportee,
97 searchVideo, 107 searchVideo,
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 0f883d839..994aac628 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -37,8 +37,8 @@ interface ServerInfo {
37 video?: { 37 video?: {
38 id: number 38 id: number
39 uuid: string 39 uuid: string
40 name: string 40 name?: string
41 account: { 41 account?: {
42 name: string 42 name: string
43 } 43 }
44 } 44 }
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index 4a5bc30fe..2061e3353 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -139,13 +139,17 @@ async function checkNotification (
139} 139}
140 140
141function checkVideo (video: any, videoName?: string, videoUUID?: string) { 141function checkVideo (video: any, videoName?: string, videoUUID?: string) {
142 expect(video.name).to.be.a('string') 142 if (videoName) {
143 expect(video.name).to.not.be.empty 143 expect(video.name).to.be.a('string')
144 if (videoName) expect(video.name).to.equal(videoName) 144 expect(video.name).to.not.be.empty
145 expect(video.name).to.equal(videoName)
146 }
145 147
146 expect(video.uuid).to.be.a('string') 148 if (videoUUID) {
147 expect(video.uuid).to.not.be.empty 149 expect(video.uuid).to.be.a('string')
148 if (videoUUID) expect(video.uuid).to.equal(videoUUID) 150 expect(video.uuid).to.not.be.empty
151 expect(video.uuid).to.equal(videoUUID)
152 }
149 153
150 expect(video.id).to.be.a('number') 154 expect(video.id).to.be.a('number')
151} 155}
@@ -436,7 +440,7 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string,
436} 440}
437 441
438async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { 442async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
439 const notificationType = UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS 443 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
440 444
441 function notificationChecker (notification: UserNotification, type: CheckerType) { 445 function notificationChecker (notification: UserNotification, type: CheckerType) {
442 if (type === 'presence') { 446 if (type === 'presence') {
@@ -460,6 +464,56 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU
460 await checkNotification(base, notificationChecker, emailNotificationFinder, type) 464 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
461} 465}
462 466
467async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
468 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
469
470 function notificationChecker (notification: UserNotification, type: CheckerType) {
471 if (type === 'presence') {
472 expect(notification).to.not.be.undefined
473 expect(notification.type).to.equal(notificationType)
474
475 expect(notification.abuse.id).to.be.a('number')
476 checkVideo(notification.abuse.comment.video, videoName, videoUUID)
477 } else {
478 expect(notification).to.satisfy((n: UserNotification) => {
479 return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID
480 })
481 }
482 }
483
484 function emailNotificationFinder (email: object) {
485 const text = email['text']
486 return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
487 }
488
489 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
490}
491
492async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) {
493 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
494
495 function notificationChecker (notification: UserNotification, type: CheckerType) {
496 if (type === 'presence') {
497 expect(notification).to.not.be.undefined
498 expect(notification.type).to.equal(notificationType)
499
500 expect(notification.abuse.id).to.be.a('number')
501 expect(notification.abuse.account.displayName).to.equal(displayName)
502 } else {
503 expect(notification).to.satisfy((n: UserNotification) => {
504 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
505 })
506 }
507 }
508
509 function emailNotificationFinder (email: object) {
510 const text = email['text']
511 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
512 }
513
514 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
515}
516
463async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { 517async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
464 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS 518 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
465 519
@@ -541,6 +595,9 @@ async function prepareNotificationsTest (serversCount = 3) {
541 smtp: { 595 smtp: {
542 hostname: 'localhost', 596 hostname: 'localhost',
543 port 597 port
598 },
599 signup: {
600 limit: 20
544 } 601 }
545 } 602 }
546 const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) 603 const servers = await flushAndRunMultipleServers(serversCount, overrideConfig)
@@ -623,5 +680,7 @@ export {
623 markAsReadNotifications, 680 markAsReadNotifications,
624 getLastNotification, 681 getLastNotification,
625 checkNewInstanceFollower, 682 checkNewInstanceFollower,
626 prepareNotificationsTest 683 prepareNotificationsTest,
684 checkNewCommentAbuseForModerators,
685 checkNewAccountAbuseForModerators
627} 686}