From 310b5219b38427f0c2c7ba57225afdd8f3064380 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Jul 2020 15:51:46 +0200 Subject: Add new abuses tests --- shared/extra-utils/moderation/abuses.ts | 14 ++++- shared/extra-utils/server/servers.ts | 4 +- shared/extra-utils/users/user-notifications.ts | 75 +++++++++++++++++++++++--- shared/models/users/user-notification.model.ts | 2 +- 4 files changed, 82 insertions(+), 13 deletions(-) (limited to 'shared') 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: { function getAbusesList (options: { url: string token: string + + start?: number + count?: number + sort?: string + id?: number predefinedReason?: AbusePredefinedReasonsString search?: string - filter?: AbuseFilter, + filter?: AbuseFilter state?: AbuseState videoIs?: AbuseVideoIs searchReporter?: string @@ -71,6 +76,9 @@ function getAbusesList (options: { const { url, token, + start, + count, + sort, id, predefinedReason, search, @@ -85,13 +93,15 @@ function getAbusesList (options: { const path = '/api/v1/abuses' const query = { - sort: 'createdAt', id, predefinedReason, search, state, filter, videoIs, + start, + count, + sort: sort || 'createdAt', searchReporter, searchReportee, 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 { video?: { id: number uuid: string - name: string - account: { + name?: string + account?: { name: string } } 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 ( } function checkVideo (video: any, videoName?: string, videoUUID?: string) { - expect(video.name).to.be.a('string') - expect(video.name).to.not.be.empty - if (videoName) expect(video.name).to.equal(videoName) + if (videoName) { + expect(video.name).to.be.a('string') + expect(video.name).to.not.be.empty + expect(video.name).to.equal(videoName) + } - expect(video.uuid).to.be.a('string') - expect(video.uuid).to.not.be.empty - if (videoUUID) expect(video.uuid).to.equal(videoUUID) + if (videoUUID) { + expect(video.uuid).to.be.a('string') + expect(video.uuid).to.not.be.empty + expect(video.uuid).to.equal(videoUUID) + } expect(video.id).to.be.a('number') } @@ -436,7 +440,7 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, } async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { - const notificationType = UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS + const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS function notificationChecker (notification: UserNotification, type: CheckerType) { if (type === 'presence') { @@ -460,6 +464,56 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU await checkNotification(base, notificationChecker, emailNotificationFinder, type) } +async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { + const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, type: CheckerType) { + if (type === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.be.a('number') + checkVideo(notification.abuse.comment.video, videoName, videoUUID) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1 + } + + await checkNotification(base, notificationChecker, emailNotificationFinder, type) +} + +async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) { + const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, type: CheckerType) { + if (type === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.be.a('number') + expect(notification.abuse.account.displayName).to.equal(displayName) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1 + } + + await checkNotification(base, notificationChecker, emailNotificationFinder, type) +} + async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS @@ -541,6 +595,9 @@ async function prepareNotificationsTest (serversCount = 3) { smtp: { hostname: 'localhost', port + }, + signup: { + limit: 20 } } const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) @@ -623,5 +680,7 @@ export { markAsReadNotifications, getLastNotification, checkNewInstanceFollower, - prepareNotificationsTest + prepareNotificationsTest, + checkNewCommentAbuseForModerators, + checkNewAccountAbuseForModerators } diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index 39090f5a1..11d96fd50 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts @@ -3,7 +3,7 @@ import { FollowState } from '../actors' export enum UserNotificationType { NEW_VIDEO_FROM_SUBSCRIPTION = 1, NEW_COMMENT_ON_MY_VIDEO = 2, - NEW_VIDEO_ABUSE_FOR_MODERATORS = 3, + NEW_ABUSE_FOR_MODERATORS = 3, BLACKLIST_ON_MY_VIDEO = 4, UNBLACKLIST_ON_MY_VIDEO = 5, -- cgit v1.2.3