diff options
Diffstat (limited to 'server/tests/api/notifications/moderation-notifications.ts')
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 128 |
1 files changed, 125 insertions, 3 deletions
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 9faaacb91..721a445ab 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { v4 as uuidv4 } from 'uuid' | 4 | import { v4 as uuidv4 } from 'uuid' |
5 | |||
5 | import { | 6 | import { |
6 | addVideoCommentThread, | 7 | addVideoCommentThread, |
7 | addVideoToBlacklist, | 8 | addVideoToBlacklist, |
@@ -21,7 +22,9 @@ import { | |||
21 | unfollow, | 22 | unfollow, |
22 | updateCustomConfig, | 23 | updateCustomConfig, |
23 | updateCustomSubConfig, | 24 | updateCustomSubConfig, |
24 | wait | 25 | wait, |
26 | updateAbuse, | ||
27 | addAbuseMessage | ||
25 | } from '../../../../shared/extra-utils' | 28 | } from '../../../../shared/extra-utils' |
26 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | 29 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' |
27 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | 30 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' |
@@ -38,12 +41,15 @@ import { | |||
38 | checkUserRegistered, | 41 | checkUserRegistered, |
39 | checkVideoAutoBlacklistForModerators, | 42 | checkVideoAutoBlacklistForModerators, |
40 | checkVideoIsPublished, | 43 | checkVideoIsPublished, |
41 | prepareNotificationsTest | 44 | prepareNotificationsTest, |
45 | checkAbuseStateChange, | ||
46 | checkNewAbuseMessage | ||
42 | } from '../../../../shared/extra-utils/users/user-notifications' | 47 | } from '../../../../shared/extra-utils/users/user-notifications' |
43 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | 48 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' |
44 | import { CustomConfig } from '../../../../shared/models/server' | 49 | import { CustomConfig } from '../../../../shared/models/server' |
45 | import { UserNotification } from '../../../../shared/models/users' | 50 | import { UserNotification } from '../../../../shared/models/users' |
46 | import { VideoPrivacy } from '../../../../shared/models/videos' | 51 | import { VideoPrivacy } from '../../../../shared/models/videos' |
52 | import { AbuseState } from '@shared/models' | ||
47 | 53 | ||
48 | describe('Test moderation notifications', function () { | 54 | describe('Test moderation notifications', function () { |
49 | let servers: ServerInfo[] = [] | 55 | let servers: ServerInfo[] = [] |
@@ -65,7 +71,7 @@ describe('Test moderation notifications', function () { | |||
65 | adminNotificationsServer2 = res.adminNotificationsServer2 | 71 | adminNotificationsServer2 = res.adminNotificationsServer2 |
66 | }) | 72 | }) |
67 | 73 | ||
68 | describe('Video abuse for moderators notification', function () { | 74 | describe('Abuse for moderators notification', function () { |
69 | let baseParams: CheckerBaseParams | 75 | let baseParams: CheckerBaseParams |
70 | 76 | ||
71 | before(() => { | 77 | before(() => { |
@@ -169,6 +175,122 @@ describe('Test moderation notifications', function () { | |||
169 | }) | 175 | }) |
170 | }) | 176 | }) |
171 | 177 | ||
178 | describe('Abuse state change notification', function () { | ||
179 | let baseParams: CheckerBaseParams | ||
180 | let abuseId: number | ||
181 | |||
182 | before(async function () { | ||
183 | baseParams = { | ||
184 | server: servers[0], | ||
185 | emails, | ||
186 | socketNotifications: userNotifications, | ||
187 | token: userAccessToken | ||
188 | } | ||
189 | |||
190 | const name = 'abuse ' + uuidv4() | ||
191 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
192 | const video = resVideo.body.video | ||
193 | |||
194 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) | ||
195 | abuseId = res.body.abuse.id | ||
196 | }) | ||
197 | |||
198 | it('Should send a notification to reporter if the abuse has been accepted', async function () { | ||
199 | this.timeout(10000) | ||
200 | |||
201 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.ACCEPTED }) | ||
202 | await waitJobs(servers) | ||
203 | |||
204 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') | ||
205 | }) | ||
206 | |||
207 | it('Should send a notification to reporter if the abuse has been rejected', async function () { | ||
208 | this.timeout(10000) | ||
209 | |||
210 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.REJECTED }) | ||
211 | await waitJobs(servers) | ||
212 | |||
213 | await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') | ||
214 | }) | ||
215 | }) | ||
216 | |||
217 | describe('New abuse message notification', function () { | ||
218 | let baseParamsUser: CheckerBaseParams | ||
219 | let baseParamsAdmin: CheckerBaseParams | ||
220 | let abuseId: number | ||
221 | let abuseId2: number | ||
222 | |||
223 | before(async function () { | ||
224 | baseParamsUser = { | ||
225 | server: servers[0], | ||
226 | emails, | ||
227 | socketNotifications: userNotifications, | ||
228 | token: userAccessToken | ||
229 | } | ||
230 | |||
231 | baseParamsAdmin = { | ||
232 | server: servers[0], | ||
233 | emails, | ||
234 | socketNotifications: adminNotifications, | ||
235 | token: servers[0].accessToken | ||
236 | } | ||
237 | |||
238 | const name = 'abuse ' + uuidv4() | ||
239 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
240 | const video = resVideo.body.video | ||
241 | |||
242 | { | ||
243 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) | ||
244 | abuseId = res.body.abuse.id | ||
245 | } | ||
246 | |||
247 | { | ||
248 | const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) | ||
249 | abuseId2 = res.body.abuse.id | ||
250 | } | ||
251 | }) | ||
252 | |||
253 | it('Should send a notification to reporter on new message', async function () { | ||
254 | this.timeout(10000) | ||
255 | |||
256 | const message = 'my super message to users' | ||
257 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) | ||
258 | await waitJobs(servers) | ||
259 | |||
260 | await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') | ||
261 | }) | ||
262 | |||
263 | it('Should not send a notification to the admin if sent by the admin', async function () { | ||
264 | this.timeout(10000) | ||
265 | |||
266 | const message = 'my super message that should not be sent to the admin' | ||
267 | await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) | ||
268 | await waitJobs(servers) | ||
269 | |||
270 | await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin1@example.com', 'absence') | ||
271 | }) | ||
272 | |||
273 | it('Should send a notification to moderators', async function () { | ||
274 | this.timeout(10000) | ||
275 | |||
276 | const message = 'my super message to moderators' | ||
277 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) | ||
278 | await waitJobs(servers) | ||
279 | |||
280 | await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin1@example.com', 'presence') | ||
281 | }) | ||
282 | |||
283 | it('Should not send a notification to reporter if sent by the reporter', async function () { | ||
284 | this.timeout(10000) | ||
285 | |||
286 | const message = 'my super message that should not be sent to reporter' | ||
287 | await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) | ||
288 | await waitJobs(servers) | ||
289 | |||
290 | await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') | ||
291 | }) | ||
292 | }) | ||
293 | |||
172 | describe('Video blacklist on my video', function () { | 294 | describe('Video blacklist on my video', function () { |
173 | let baseParams: CheckerBaseParams | 295 | let baseParams: CheckerBaseParams |
174 | 296 | ||