aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-27 16:26:25 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commit594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (patch)
treebae28fa6215a3a3c6ccd78aea6ea7e75c500a96f /server/tests/api
parent94148c9028829b5576a5dcbfba2c7fb9cf6443d3 (diff)
downloadPeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.gz
PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.zst
PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.zip
Add abuse messages/states notifications
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/user-notifications.ts4
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts128
2 files changed, 128 insertions, 4 deletions
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 883b1d29c..c6384677e 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -173,7 +173,9 @@ describe('Test user notifications API validators', function () {
173 newFollow: UserNotificationSettingValue.WEB, 173 newFollow: UserNotificationSettingValue.WEB,
174 newUserRegistration: UserNotificationSettingValue.WEB, 174 newUserRegistration: UserNotificationSettingValue.WEB,
175 newInstanceFollower: UserNotificationSettingValue.WEB, 175 newInstanceFollower: UserNotificationSettingValue.WEB,
176 autoInstanceFollowing: UserNotificationSettingValue.WEB 176 autoInstanceFollowing: UserNotificationSettingValue.WEB,
177 abuseNewMessage: UserNotificationSettingValue.WEB,
178 abuseStateChange: UserNotificationSettingValue.WEB
177 } 179 }
178 180
179 it('Should fail with missing fields', async function () { 181 it('Should fail with missing fields', async function () {
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
3import 'mocha' 3import 'mocha'
4import { v4 as uuidv4 } from 'uuid' 4import { v4 as uuidv4 } from 'uuid'
5
5import { 6import {
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'
26import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' 29import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
27import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' 30import { 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'
43import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 48import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
44import { CustomConfig } from '../../../../shared/models/server' 49import { CustomConfig } from '../../../../shared/models/server'
45import { UserNotification } from '../../../../shared/models/users' 50import { UserNotification } from '../../../../shared/models/users'
46import { VideoPrivacy } from '../../../../shared/models/videos' 51import { VideoPrivacy } from '../../../../shared/models/videos'
52import { AbuseState } from '@shared/models'
47 53
48describe('Test moderation notifications', function () { 54describe('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