aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-07 14:34:16 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-10 14:02:41 +0200
commit4f32032fed8587ea97d45e235b167e8958efd81f (patch)
tree6ec4ce2d5d05a275fb7eeaf3aee33c2b69ebc043 /server/tests/api
parent57f6896f67cfc570cf3605dd94b0778101b2d9b9 (diff)
downloadPeerTube-4f32032fed8587ea97d45e235b167e8958efd81f.tar.gz
PeerTube-4f32032fed8587ea97d45e235b167e8958efd81f.tar.zst
PeerTube-4f32032fed8587ea97d45e235b167e8958efd81f.zip
Add migrations
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/user-notifications.ts2
-rw-r--r--server/tests/api/ci-4.sh1
-rw-r--r--server/tests/api/index.ts1
-rw-r--r--server/tests/api/moderation/abuses.ts384
-rw-r--r--server/tests/api/moderation/blocklist.ts (renamed from server/tests/api/users/blocklist.ts)0
-rw-r--r--server/tests/api/moderation/index.ts2
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts14
-rw-r--r--server/tests/api/server/email.ts12
-rw-r--r--server/tests/api/users/index.ts3
-rw-r--r--server/tests/api/users/users.ts40
-rw-r--r--server/tests/api/videos/video-abuse.ts12
11 files changed, 432 insertions, 39 deletions
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 2048fa667..883b1d29c 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -164,7 +164,7 @@ describe('Test user notifications API validators', function () {
164 const correctFields: UserNotificationSetting = { 164 const correctFields: UserNotificationSetting = {
165 newVideoFromSubscription: UserNotificationSettingValue.WEB, 165 newVideoFromSubscription: UserNotificationSettingValue.WEB,
166 newCommentOnMyVideo: UserNotificationSettingValue.WEB, 166 newCommentOnMyVideo: UserNotificationSettingValue.WEB,
167 videoAbuseAsModerator: UserNotificationSettingValue.WEB, 167 abuseAsModerator: UserNotificationSettingValue.WEB,
168 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB, 168 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB,
169 blacklistOnMyVideo: UserNotificationSettingValue.WEB, 169 blacklistOnMyVideo: UserNotificationSettingValue.WEB,
170 myVideoImportFinished: UserNotificationSettingValue.WEB, 170 myVideoImportFinished: UserNotificationSettingValue.WEB,
diff --git a/server/tests/api/ci-4.sh b/server/tests/api/ci-4.sh
index 14a014f07..4998de364 100644
--- a/server/tests/api/ci-4.sh
+++ b/server/tests/api/ci-4.sh
@@ -2,6 +2,7 @@
2 2
3set -eu 3set -eu
4 4
5activitypubFiles=$(find server/tests/api/moderation -type f | grep -v index.ts | xargs echo)
5redundancyFiles=$(find server/tests/api/redundancy -type f | grep -v index.ts | xargs echo) 6redundancyFiles=$(find server/tests/api/redundancy -type f | grep -v index.ts | xargs echo)
6activitypubFiles=$(find server/tests/api/activitypub -type f | grep -v index.ts | xargs echo) 7activitypubFiles=$(find server/tests/api/activitypub -type f | grep -v index.ts | xargs echo)
7 8
diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts
index bac77ab2e..b62e2f5f7 100644
--- a/server/tests/api/index.ts
+++ b/server/tests/api/index.ts
@@ -1,6 +1,7 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2import './activitypub' 2import './activitypub'
3import './check-params' 3import './check-params'
4import './moderation'
4import './notifications' 5import './notifications'
5import './redundancy' 6import './redundancy'
6import './search' 7import './search'
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
new file mode 100644
index 000000000..28c5a5531
--- /dev/null
+++ b/server/tests/api/moderation/abuses.ts
@@ -0,0 +1,384 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { Abuse, AbusePredefinedReasonsString, AbuseState } from '@shared/models'
6import {
7 cleanupTests,
8 createUser,
9 deleteVideoAbuse,
10 flushAndRunMultipleServers,
11 getVideoAbusesList,
12 getVideosList,
13 removeVideo,
14 reportVideoAbuse,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateVideoAbuse,
18 uploadVideo,
19 userLogin
20} from '../../../../shared/extra-utils/index'
21import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import {
24 addAccountToServerBlocklist,
25 addServerToServerBlocklist,
26 removeAccountFromServerBlocklist,
27 removeServerFromServerBlocklist
28} from '../../../../shared/extra-utils/users/blocklist'
29
30const expect = chai.expect
31
32describe('Test abuses', function () {
33 let servers: ServerInfo[] = []
34 let abuseServer2: Abuse
35
36 before(async function () {
37 this.timeout(50000)
38
39 // Run servers
40 servers = await flushAndRunMultipleServers(2)
41
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
44
45 // Server 1 and server 2 follow each other
46 await doubleFollow(servers[0], servers[1])
47
48 // Upload some videos on each servers
49 const video1Attributes = {
50 name: 'my super name for server 1',
51 description: 'my super description for server 1'
52 }
53 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
54
55 const video2Attributes = {
56 name: 'my super name for server 2',
57 description: 'my super description for server 2'
58 }
59 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
60
61 // Wait videos propagation, server 2 has transcoding enabled
62 await waitJobs(servers)
63
64 const res = await getVideosList(servers[0].url)
65 const videos = res.body.data
66
67 expect(videos.length).to.equal(2)
68
69 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
70 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
71 })
72
73 it('Should not have video abuses', async function () {
74 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
75
76 expect(res.body.total).to.equal(0)
77 expect(res.body.data).to.be.an('array')
78 expect(res.body.data.length).to.equal(0)
79 })
80
81 it('Should report abuse on a local video', async function () {
82 this.timeout(15000)
83
84 const reason = 'my super bad reason'
85 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
86
87 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
88 await waitJobs(servers)
89 })
90
91 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
92 const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
93
94 expect(res1.body.total).to.equal(1)
95 expect(res1.body.data).to.be.an('array')
96 expect(res1.body.data.length).to.equal(1)
97
98 const abuse: Abuse = res1.body.data[0]
99 expect(abuse.reason).to.equal('my super bad reason')
100 expect(abuse.reporterAccount.name).to.equal('root')
101 expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port)
102 expect(abuse.video.id).to.equal(servers[0].video.id)
103 expect(abuse.video.channel).to.exist
104 expect(abuse.count).to.equal(1)
105 expect(abuse.nth).to.equal(1)
106 expect(abuse.countReportsForReporter).to.equal(1)
107 expect(abuse.countReportsForReportee).to.equal(1)
108
109 const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
110 expect(res2.body.total).to.equal(0)
111 expect(res2.body.data).to.be.an('array')
112 expect(res2.body.data.length).to.equal(0)
113 })
114
115 it('Should report abuse on a remote video', async function () {
116 this.timeout(10000)
117
118 const reason = 'my super bad reason 2'
119 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
120
121 // We wait requests propagation
122 await waitJobs(servers)
123 })
124
125 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
126 const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
127 expect(res1.body.total).to.equal(2)
128 expect(res1.body.data).to.be.an('array')
129 expect(res1.body.data.length).to.equal(2)
130
131 const abuse1: Abuse = res1.body.data[0]
132 expect(abuse1.reason).to.equal('my super bad reason')
133 expect(abuse1.reporterAccount.name).to.equal('root')
134 expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port)
135 expect(abuse1.video.id).to.equal(servers[0].video.id)
136 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
137 expect(abuse1.state.label).to.equal('Pending')
138 expect(abuse1.moderationComment).to.be.null
139 expect(abuse1.count).to.equal(1)
140 expect(abuse1.nth).to.equal(1)
141
142 const abuse2: Abuse = res1.body.data[1]
143 expect(abuse2.reason).to.equal('my super bad reason 2')
144 expect(abuse2.reporterAccount.name).to.equal('root')
145 expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port)
146 expect(abuse2.video.id).to.equal(servers[1].video.id)
147 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
148 expect(abuse2.state.label).to.equal('Pending')
149 expect(abuse2.moderationComment).to.be.null
150
151 const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
152 expect(res2.body.total).to.equal(1)
153 expect(res2.body.data).to.be.an('array')
154 expect(res2.body.data.length).to.equal(1)
155
156 abuseServer2 = res2.body.data[0]
157 expect(abuseServer2.reason).to.equal('my super bad reason 2')
158 expect(abuseServer2.reporterAccount.name).to.equal('root')
159 expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port)
160 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
161 expect(abuseServer2.state.label).to.equal('Pending')
162 expect(abuseServer2.moderationComment).to.be.null
163 })
164
165 it('Should update the state of a video abuse', async function () {
166 const body = { state: AbuseState.REJECTED }
167 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
168
169 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
170 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED)
171 })
172
173 it('Should add a moderation comment', async function () {
174 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' }
175 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
176
177 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
178 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
179 expect(res.body.data[0].moderationComment).to.equal('It is valid')
180 })
181
182 it('Should hide video abuses from blocked accounts', async function () {
183 this.timeout(10000)
184
185 {
186 await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this')
187 await waitJobs(servers)
188
189 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
190 expect(res.body.total).to.equal(3)
191 }
192
193 const accountToBlock = 'root@localhost:' + servers[1].port
194
195 {
196 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
197
198 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
199 expect(res.body.total).to.equal(2)
200
201 const abuse = res.body.data.find(a => a.reason === 'will mute this')
202 expect(abuse).to.be.undefined
203 }
204
205 {
206 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
207
208 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
209 expect(res.body.total).to.equal(3)
210 }
211 })
212
213 it('Should hide video abuses from blocked servers', async function () {
214 const serverToBlock = servers[1].host
215
216 {
217 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
218
219 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
220 expect(res.body.total).to.equal(2)
221
222 const abuse = res.body.data.find(a => a.reason === 'will mute this')
223 expect(abuse).to.be.undefined
224 }
225
226 {
227 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
228
229 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
230 expect(res.body.total).to.equal(3)
231 }
232 })
233
234 it('Should keep the video abuse when deleting the video', async function () {
235 this.timeout(10000)
236
237 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
238
239 await waitJobs(servers)
240
241 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
242 expect(res.body.total).to.equal(2, "wrong number of videos returned")
243 expect(res.body.data.length).to.equal(2, "wrong number of videos returned")
244 expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video")
245
246 const abuse: Abuse = res.body.data[0]
247 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
248 expect(abuse.video.channel).to.exist
249 expect(abuse.video.deleted).to.be.true
250 })
251
252 it('Should include counts of reports from reporter and reportee', async function () {
253 this.timeout(10000)
254
255 // register a second user to have two reporters/reportees
256 const user = { username: 'user2', password: 'password' }
257 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
258 const userAccessToken = await userLogin(servers[0], user)
259
260 // upload a third video via this user
261 const video3Attributes = {
262 name: 'my second super name for server 1',
263 description: 'my second super description for server 1'
264 }
265 await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
266
267 const res1 = await getVideosList(servers[0].url)
268 const videos = res1.body.data
269 const video3 = videos.find(video => video.name === 'my second super name for server 1')
270
271 // resume with the test
272 const reason3 = 'my super bad reason 3'
273 await reportVideoAbuse(servers[0].url, servers[0].accessToken, video3.id, reason3)
274 const reason4 = 'my super bad reason 4'
275 await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4)
276
277 const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
278
279 {
280 for (const abuse of res2.body.data as Abuse[]) {
281 if (abuse.video.id === video3.id) {
282 expect(abuse.count).to.equal(1, "wrong reports count for video 3")
283 expect(abuse.nth).to.equal(1, "wrong report position in report list for video 3")
284 expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
285 expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
286 }
287 if (abuse.video.id === servers[0].video.id) {
288 expect(abuse.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
289 }
290 }
291 }
292 })
293
294 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
295 this.timeout(10000)
296
297 const reason5 = 'my super bad reason 5'
298 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
299 const createdAbuse = (await reportVideoAbuse(
300 servers[0].url,
301 servers[0].accessToken,
302 servers[0].video.id,
303 reason5,
304 predefinedReasons5,
305 1,
306 5
307 )).body.abuse
308
309 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
310
311 {
312 const abuse = (res.body.data as Abuse[]).find(a => a.id === createdAbuse.id)
313 expect(abuse.reason).to.equals(reason5)
314 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
315 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
316 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
317 }
318 })
319
320 it('Should delete the video abuse', async function () {
321 this.timeout(10000)
322
323 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
324
325 await waitJobs(servers)
326
327 {
328 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
329 expect(res.body.total).to.equal(1)
330 expect(res.body.data.length).to.equal(1)
331 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
332 }
333
334 {
335 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
336 expect(res.body.total).to.equal(6)
337 }
338 })
339
340 it('Should list and filter video abuses', async function () {
341 async function list (query: Omit<Parameters<typeof getVideoAbusesList>[0], 'url' | 'token'>) {
342 const options = {
343 url: servers[0].url,
344 token: servers[0].accessToken
345 }
346
347 Object.assign(options, query)
348
349 const res = await getVideoAbusesList(options)
350
351 return res.body.data as Abuse[]
352 }
353
354 expect(await list({ id: 56 })).to.have.lengthOf(0)
355 expect(await list({ id: 1 })).to.have.lengthOf(1)
356
357 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
358 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
359
360 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
361
362 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
363 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
364
365 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
366 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
367
368 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
369 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
370
371 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
372 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
373
374 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
375 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
376
377 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
378 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
379 })
380
381 after(async function () {
382 await cleanupTests(servers)
383 })
384})
diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index 8c9107a50..8c9107a50 100644
--- a/server/tests/api/users/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
diff --git a/server/tests/api/moderation/index.ts b/server/tests/api/moderation/index.ts
new file mode 100644
index 000000000..cb018d88e
--- /dev/null
+++ b/server/tests/api/moderation/index.ts
@@ -0,0 +1,2 @@
1export * from './abuses'
2export * from './blocklist'
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index b90732a7a..a27681603 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -11,7 +11,7 @@ import {
11 MockInstancesIndex, 11 MockInstancesIndex,
12 registerUser, 12 registerUser,
13 removeVideoFromBlacklist, 13 removeVideoFromBlacklist,
14 reportVideoAbuse, 14 reportAbuse,
15 unfollow, 15 unfollow,
16 updateCustomConfig, 16 updateCustomConfig,
17 updateCustomSubConfig, 17 updateCustomSubConfig,
@@ -74,12 +74,12 @@ describe('Test moderation notifications', function () {
74 74
75 const name = 'video for abuse ' + uuidv4() 75 const name = 'video for abuse ' + uuidv4()
76 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 76 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
77 const uuid = resVideo.body.video.uuid 77 const video = resVideo.body.video
78 78
79 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') 79 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' })
80 80
81 await waitJobs(servers) 81 await waitJobs(servers)
82 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') 82 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence')
83 }) 83 })
84 84
85 it('Should send a notification to moderators on remote video abuse', async function () { 85 it('Should send a notification to moderators on remote video abuse', async function () {
@@ -87,14 +87,14 @@ describe('Test moderation notifications', function () {
87 87
88 const name = 'video for abuse ' + uuidv4() 88 const name = 'video for abuse ' + uuidv4()
89 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 89 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
90 const uuid = resVideo.body.video.uuid 90 const video = resVideo.body.video
91 91
92 await waitJobs(servers) 92 await waitJobs(servers)
93 93
94 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') 94 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId: video.id, reason: 'super reason' })
95 95
96 await waitJobs(servers) 96 await waitJobs(servers)
97 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') 97 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence')
98 }) 98 })
99 }) 99 })
100 100
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index 95b64a459..9c3299618 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 addVideoToBlacklist, 6 addVideoToBlacklist,
7 askResetPassword, 7 askResetPassword,
@@ -11,7 +11,7 @@ import {
11 createUser, 11 createUser,
12 flushAndRunServer, 12 flushAndRunServer,
13 removeVideoFromBlacklist, 13 removeVideoFromBlacklist,
14 reportVideoAbuse, 14 reportAbuse,
15 resetPassword, 15 resetPassword,
16 ServerInfo, 16 ServerInfo,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
@@ -30,10 +30,15 @@ describe('Test emails', function () {
30 let userId: number 30 let userId: number
31 let userId2: number 31 let userId2: number
32 let userAccessToken: string 32 let userAccessToken: string
33
33 let videoUUID: string 34 let videoUUID: string
35 let videoId: number
36
34 let videoUserUUID: string 37 let videoUserUUID: string
38
35 let verificationString: string 39 let verificationString: string
36 let verificationString2: string 40 let verificationString2: string
41
37 const emails: object[] = [] 42 const emails: object[] = []
38 const user = { 43 const user = {
39 username: 'user_1', 44 username: 'user_1',
@@ -76,6 +81,7 @@ describe('Test emails', function () {
76 } 81 }
77 const res = await uploadVideo(server.url, server.accessToken, attributes) 82 const res = await uploadVideo(server.url, server.accessToken, attributes)
78 videoUUID = res.body.video.uuid 83 videoUUID = res.body.video.uuid
84 videoId = res.body.video.id
79 } 85 }
80 }) 86 })
81 87
@@ -179,7 +185,7 @@ describe('Test emails', function () {
179 this.timeout(10000) 185 this.timeout(10000)
180 186
181 const reason = 'my super bad reason' 187 const reason = 'my super bad reason'
182 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason) 188 await reportAbuse({ url: server.url, token: server.accessToken, videoId, reason })
183 189
184 await waitJobs(server) 190 await waitJobs(server)
185 expect(emails).to.have.lengthOf(3) 191 expect(emails).to.have.lengthOf(3)
diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts
index fcd022429..a244a6edb 100644
--- a/server/tests/api/users/index.ts
+++ b/server/tests/api/users/index.ts
@@ -1,5 +1,4 @@
1import './users-verification'
2import './blocklist'
3import './user-subscriptions' 1import './user-subscriptions'
4import './users' 2import './users'
5import './users-multiple-servers' 3import './users-multiple-servers'
4import './users-verification'
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 88b68d977..ea74bde6a 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -1,8 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { MyUser, User, UserRole, Video, AbuseState, AbuseUpdate, VideoPlaylistType } from '@shared/models' 4import * as chai from 'chai'
5import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models'
6import { CustomConfig } from '@shared/models/server'
6import { 7import {
7 addVideoCommentThread, 8 addVideoCommentThread,
8 blockUser, 9 blockUser,
@@ -10,6 +11,7 @@ import {
10 createUser, 11 createUser,
11 deleteMe, 12 deleteMe,
12 flushAndRunServer, 13 flushAndRunServer,
14 getAbusesList,
13 getAccountRatings, 15 getAccountRatings,
14 getBlacklistedVideosList, 16 getBlacklistedVideosList,
15 getCustomConfig, 17 getCustomConfig,
@@ -19,7 +21,6 @@ import {
19 getUserInformation, 21 getUserInformation,
20 getUsersList, 22 getUsersList,
21 getUsersListPaginationAndSort, 23 getUsersListPaginationAndSort,
22 getVideoAbusesList,
23 getVideoChannel, 24 getVideoChannel,
24 getVideosList, 25 getVideosList,
25 installPlugin, 26 installPlugin,
@@ -29,15 +30,15 @@ import {
29 registerUserWithChannel, 30 registerUserWithChannel,
30 removeUser, 31 removeUser,
31 removeVideo, 32 removeVideo,
32 reportVideoAbuse, 33 reportAbuse,
33 ServerInfo, 34 ServerInfo,
34 testImage, 35 testImage,
35 unblockUser, 36 unblockUser,
37 updateAbuse,
36 updateCustomSubConfig, 38 updateCustomSubConfig,
37 updateMyAvatar, 39 updateMyAvatar,
38 updateMyUser, 40 updateMyUser,
39 updateUser, 41 updateUser,
40 updateVideoAbuse,
41 uploadVideo, 42 uploadVideo,
42 userLogin, 43 userLogin,
43 waitJobs 44 waitJobs
@@ -46,7 +47,6 @@ import { follow } from '../../../../shared/extra-utils/server/follows'
46import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 47import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
47import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' 48import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
48import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
49import { CustomConfig } from '@shared/models/server'
50 50
51const expect = chai.expect 51const expect = chai.expect
52 52
@@ -302,10 +302,10 @@ describe('Test users', function () {
302 expect(userGet.videosCount).to.equal(0) 302 expect(userGet.videosCount).to.equal(0)
303 expect(userGet.videoCommentsCount).to.be.a('number') 303 expect(userGet.videoCommentsCount).to.be.a('number')
304 expect(userGet.videoCommentsCount).to.equal(0) 304 expect(userGet.videoCommentsCount).to.equal(0)
305 expect(userGet.videoAbusesCount).to.be.a('number') 305 expect(userGet.abusesCount).to.be.a('number')
306 expect(userGet.videoAbusesCount).to.equal(0) 306 expect(userGet.abusesCount).to.equal(0)
307 expect(userGet.videoAbusesAcceptedCount).to.be.a('number') 307 expect(userGet.abusesAcceptedCount).to.be.a('number')
308 expect(userGet.videoAbusesAcceptedCount).to.equal(0) 308 expect(userGet.abusesAcceptedCount).to.equal(0)
309 }) 309 })
310 }) 310 })
311 311
@@ -895,9 +895,9 @@ describe('Test users', function () {
895 895
896 expect(user.videosCount).to.equal(0) 896 expect(user.videosCount).to.equal(0)
897 expect(user.videoCommentsCount).to.equal(0) 897 expect(user.videoCommentsCount).to.equal(0)
898 expect(user.videoAbusesCount).to.equal(0) 898 expect(user.abusesCount).to.equal(0)
899 expect(user.videoAbusesCreatedCount).to.equal(0) 899 expect(user.abusesCreatedCount).to.equal(0)
900 expect(user.videoAbusesAcceptedCount).to.equal(0) 900 expect(user.abusesAcceptedCount).to.equal(0)
901 }) 901 })
902 902
903 it('Should report correct videos count', async function () { 903 it('Should report correct videos count', async function () {
@@ -924,26 +924,26 @@ describe('Test users', function () {
924 expect(user.videoCommentsCount).to.equal(1) 924 expect(user.videoCommentsCount).to.equal(1)
925 }) 925 })
926 926
927 it('Should report correct video abuses counts', async function () { 927 it('Should report correct abuses counts', async function () {
928 const reason = 'my super bad reason' 928 const reason = 'my super bad reason'
929 await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) 929 await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason })
930 930
931 const res1 = await getVideoAbusesList({ url: server.url, token: server.accessToken }) 931 const res1 = await getAbusesList({ url: server.url, token: server.accessToken })
932 const abuseId = res1.body.data[0].id 932 const abuseId = res1.body.data[0].id
933 933
934 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) 934 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
935 const user2: User = res2.body 935 const user2: User = res2.body
936 936
937 expect(user2.videoAbusesCount).to.equal(1) // number of incriminations 937 expect(user2.abusesCount).to.equal(1) // number of incriminations
938 expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created 938 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
939 939
940 const body: AbuseUpdate = { state: AbuseState.ACCEPTED } 940 const body: AbuseUpdate = { state: AbuseState.ACCEPTED }
941 await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body) 941 await updateAbuse(server.url, server.accessToken, abuseId, body)
942 942
943 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) 943 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
944 const user3: User = res3.body 944 const user3: User = res3.body
945 945
946 expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted 946 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
947 }) 947 })
948 }) 948 })
949 949
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index 20975aa4a..baeb543e0 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -103,8 +103,8 @@ describe('Test video abuses', function () {
103 expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) 103 expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port)
104 expect(abuse.video.id).to.equal(servers[0].video.id) 104 expect(abuse.video.id).to.equal(servers[0].video.id)
105 expect(abuse.video.channel).to.exist 105 expect(abuse.video.channel).to.exist
106 expect(abuse.count).to.equal(1) 106 expect(abuse.video.countReports).to.equal(1)
107 expect(abuse.nth).to.equal(1) 107 expect(abuse.video.nthReport).to.equal(1)
108 expect(abuse.countReportsForReporter).to.equal(1) 108 expect(abuse.countReportsForReporter).to.equal(1)
109 expect(abuse.countReportsForReportee).to.equal(1) 109 expect(abuse.countReportsForReportee).to.equal(1)
110 110
@@ -138,8 +138,8 @@ describe('Test video abuses', function () {
138 expect(abuse1.state.id).to.equal(AbuseState.PENDING) 138 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
139 expect(abuse1.state.label).to.equal('Pending') 139 expect(abuse1.state.label).to.equal('Pending')
140 expect(abuse1.moderationComment).to.be.null 140 expect(abuse1.moderationComment).to.be.null
141 expect(abuse1.count).to.equal(1) 141 expect(abuse1.video.countReports).to.equal(1)
142 expect(abuse1.nth).to.equal(1) 142 expect(abuse1.video.nthReport).to.equal(1)
143 143
144 const abuse2: Abuse = res1.body.data[1] 144 const abuse2: Abuse = res1.body.data[1]
145 expect(abuse2.reason).to.equal('my super bad reason 2') 145 expect(abuse2.reason).to.equal('my super bad reason 2')
@@ -281,8 +281,8 @@ describe('Test video abuses', function () {
281 { 281 {
282 for (const abuse of res2.body.data as Abuse[]) { 282 for (const abuse of res2.body.data as Abuse[]) {
283 if (abuse.video.id === video3.id) { 283 if (abuse.video.id === video3.id) {
284 expect(abuse.count).to.equal(1, "wrong reports count for video 3") 284 expect(abuse.video.countReports).to.equal(1, "wrong reports count for video 3")
285 expect(abuse.nth).to.equal(1, "wrong report position in report list for video 3") 285 expect(abuse.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
286 expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") 286 expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
287 expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") 287 expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
288 } 288 }