diff options
Diffstat (limited to 'server/tests/api/notifications/moderation-notifications.ts')
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 88 |
1 files changed, 41 insertions, 47 deletions
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') |