aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/moderation/abuses.ts')
-rw-r--r--server/tests/api/moderation/abuses.ts756
1 files changed, 348 insertions, 408 deletions
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index fb765e7e3..c258414ce 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -3,70 +3,37 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 AbuseFilter, 6 AbusesCommand,
7 AbuseMessage,
8 AbusePredefinedReasonsString,
9 AbuseState,
10 Account,
11 AdminAbuse,
12 UserAbuse,
13 VideoComment
14} from '@shared/models'
15import {
16 addAbuseMessage,
17 addVideoCommentThread,
18 cleanupTests, 7 cleanupTests,
19 createUser, 8 createMultipleServers,
20 deleteAbuse, 9 doubleFollow,
21 deleteAbuseMessage, 10 PeerTubeServer,
22 deleteVideoComment,
23 flushAndRunMultipleServers,
24 generateUserAccessToken,
25 getAccount,
26 getAdminAbusesList,
27 getUserAbusesList,
28 getVideoCommentThreads,
29 getVideoIdFromUUID,
30 getVideosList,
31 immutableAssign,
32 listAbuseMessages,
33 removeUser,
34 removeVideo,
35 reportAbuse,
36 ServerInfo,
37 setAccessTokensToServers, 11 setAccessTokensToServers,
38 updateAbuse, 12 waitJobs
39 uploadVideo, 13} from '@shared/extra-utils'
40 uploadVideoAndGetId, 14import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
41 userLogin
42} from '../../../../shared/extra-utils/index'
43import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
44import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
45import {
46 addAccountToServerBlocklist,
47 addServerToServerBlocklist,
48 removeAccountFromServerBlocklist,
49 removeServerFromServerBlocklist
50} from '../../../../shared/extra-utils/users/blocklist'
51 15
52const expect = chai.expect 16const expect = chai.expect
53 17
54describe('Test abuses', function () { 18describe('Test abuses', function () {
55 let servers: ServerInfo[] = [] 19 let servers: PeerTubeServer[] = []
56 let abuseServer1: AdminAbuse 20 let abuseServer1: AdminAbuse
57 let abuseServer2: AdminAbuse 21 let abuseServer2: AdminAbuse
22 let commands: AbusesCommand[]
58 23
59 before(async function () { 24 before(async function () {
60 this.timeout(50000) 25 this.timeout(50000)
61 26
62 // Run servers 27 // Run servers
63 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
64 29
65 // Get the access tokens 30 // Get the access tokens
66 await setAccessTokensToServers(servers) 31 await setAccessTokensToServers(servers)
67 32
68 // Server 1 and server 2 follow each other 33 // Server 1 and server 2 follow each other
69 await doubleFollow(servers[0], servers[1]) 34 await doubleFollow(servers[0], servers[1])
35
36 commands = servers.map(s => s.abuses)
70 }) 37 })
71 38
72 describe('Video abuses', function () { 39 describe('Video abuses', function () {
@@ -75,179 +42,189 @@ describe('Test abuses', function () {
75 this.timeout(50000) 42 this.timeout(50000)
76 43
77 // Upload some videos on each servers 44 // Upload some videos on each servers
78 const video1Attributes = { 45 {
79 name: 'my super name for server 1', 46 const attributes = {
80 description: 'my super description for server 1' 47 name: 'my super name for server 1',
48 description: 'my super description for server 1'
49 }
50 await servers[0].videos.upload({ attributes })
81 } 51 }
82 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
83 52
84 const video2Attributes = { 53 {
85 name: 'my super name for server 2', 54 const attributes = {
86 description: 'my super description for server 2' 55 name: 'my super name for server 2',
56 description: 'my super description for server 2'
57 }
58 await servers[1].videos.upload({ attributes })
87 } 59 }
88 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
89 60
90 // Wait videos propagation, server 2 has transcoding enabled 61 // Wait videos propagation, server 2 has transcoding enabled
91 await waitJobs(servers) 62 await waitJobs(servers)
92 63
93 const res = await getVideosList(servers[0].url) 64 const { data } = await servers[0].videos.list()
94 const videos = res.body.data 65 expect(data.length).to.equal(2)
95 66
96 expect(videos.length).to.equal(2) 67 servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
97 68 servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
98 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
99 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
100 }) 69 })
101 70
102 it('Should not have abuses', async function () { 71 it('Should not have abuses', async function () {
103 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 72 const body = await commands[0].getAdminList()
104 73
105 expect(res.body.total).to.equal(0) 74 expect(body.total).to.equal(0)
106 expect(res.body.data).to.be.an('array') 75 expect(body.data).to.be.an('array')
107 expect(res.body.data.length).to.equal(0) 76 expect(body.data.length).to.equal(0)
108 }) 77 })
109 78
110 it('Should report abuse on a local video', async function () { 79 it('Should report abuse on a local video', async function () {
111 this.timeout(15000) 80 this.timeout(15000)
112 81
113 const reason = 'my super bad reason' 82 const reason = 'my super bad reason'
114 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) 83 await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason })
115 84
116 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 85 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
117 await waitJobs(servers) 86 await waitJobs(servers)
118 }) 87 })
119 88
120 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { 89 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
121 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 90 {
91 const body = await commands[0].getAdminList()
122 92
123 expect(res1.body.total).to.equal(1) 93 expect(body.total).to.equal(1)
124 expect(res1.body.data).to.be.an('array') 94 expect(body.data).to.be.an('array')
125 expect(res1.body.data.length).to.equal(1) 95 expect(body.data.length).to.equal(1)
126 96
127 const abuse: AdminAbuse = res1.body.data[0] 97 const abuse = body.data[0]
128 expect(abuse.reason).to.equal('my super bad reason') 98 expect(abuse.reason).to.equal('my super bad reason')
129 99
130 expect(abuse.reporterAccount.name).to.equal('root') 100 expect(abuse.reporterAccount.name).to.equal('root')
131 expect(abuse.reporterAccount.host).to.equal(servers[0].host) 101 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
132 102
133 expect(abuse.video.id).to.equal(servers[0].video.id) 103 expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id)
134 expect(abuse.video.channel).to.exist 104 expect(abuse.video.channel).to.exist
135 105
136 expect(abuse.comment).to.be.null 106 expect(abuse.comment).to.be.null
137 107
138 expect(abuse.flaggedAccount.name).to.equal('root') 108 expect(abuse.flaggedAccount.name).to.equal('root')
139 expect(abuse.flaggedAccount.host).to.equal(servers[0].host) 109 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
140 110
141 expect(abuse.video.countReports).to.equal(1) 111 expect(abuse.video.countReports).to.equal(1)
142 expect(abuse.video.nthReport).to.equal(1) 112 expect(abuse.video.nthReport).to.equal(1)
143 113
144 expect(abuse.countReportsForReporter).to.equal(1) 114 expect(abuse.countReportsForReporter).to.equal(1)
145 expect(abuse.countReportsForReportee).to.equal(1) 115 expect(abuse.countReportsForReportee).to.equal(1)
116 }
146 117
147 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 118 {
148 expect(res2.body.total).to.equal(0) 119 const body = await commands[1].getAdminList()
149 expect(res2.body.data).to.be.an('array') 120 expect(body.total).to.equal(0)
150 expect(res2.body.data.length).to.equal(0) 121 expect(body.data).to.be.an('array')
122 expect(body.data.length).to.equal(0)
123 }
151 }) 124 })
152 125
153 it('Should report abuse on a remote video', async function () { 126 it('Should report abuse on a remote video', async function () {
154 this.timeout(10000) 127 this.timeout(10000)
155 128
156 const reason = 'my super bad reason 2' 129 const reason = 'my super bad reason 2'
157 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 130 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
158 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason }) 131 await commands[0].report({ videoId, reason })
159 132
160 // We wait requests propagation 133 // We wait requests propagation
161 await waitJobs(servers) 134 await waitJobs(servers)
162 }) 135 })
163 136
164 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { 137 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
165 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 138 {
139 const body = await commands[0].getAdminList()
166 140
167 expect(res1.body.total).to.equal(2) 141 expect(body.total).to.equal(2)
168 expect(res1.body.data.length).to.equal(2) 142 expect(body.data.length).to.equal(2)
169 143
170 const abuse1: AdminAbuse = res1.body.data[0] 144 const abuse1 = body.data[0]
171 expect(abuse1.reason).to.equal('my super bad reason') 145 expect(abuse1.reason).to.equal('my super bad reason')
172 expect(abuse1.reporterAccount.name).to.equal('root') 146 expect(abuse1.reporterAccount.name).to.equal('root')
173 expect(abuse1.reporterAccount.host).to.equal(servers[0].host) 147 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
174 148
175 expect(abuse1.video.id).to.equal(servers[0].video.id) 149 expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id)
176 expect(abuse1.video.countReports).to.equal(1) 150 expect(abuse1.video.countReports).to.equal(1)
177 expect(abuse1.video.nthReport).to.equal(1) 151 expect(abuse1.video.nthReport).to.equal(1)
178 152
179 expect(abuse1.comment).to.be.null 153 expect(abuse1.comment).to.be.null
180 154
181 expect(abuse1.flaggedAccount.name).to.equal('root') 155 expect(abuse1.flaggedAccount.name).to.equal('root')
182 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) 156 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
183 157
184 expect(abuse1.state.id).to.equal(AbuseState.PENDING) 158 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
185 expect(abuse1.state.label).to.equal('Pending') 159 expect(abuse1.state.label).to.equal('Pending')
186 expect(abuse1.moderationComment).to.be.null 160 expect(abuse1.moderationComment).to.be.null
187 161
188 const abuse2: AdminAbuse = res1.body.data[1] 162 const abuse2 = body.data[1]
189 expect(abuse2.reason).to.equal('my super bad reason 2') 163 expect(abuse2.reason).to.equal('my super bad reason 2')
190 164
191 expect(abuse2.reporterAccount.name).to.equal('root') 165 expect(abuse2.reporterAccount.name).to.equal('root')
192 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 166 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
193 167
194 expect(abuse2.video.id).to.equal(servers[1].video.id) 168 expect(abuse2.video.id).to.equal(servers[1].store.videoCreated.id)
195 169
196 expect(abuse2.comment).to.be.null 170 expect(abuse2.comment).to.be.null
197 171
198 expect(abuse2.flaggedAccount.name).to.equal('root') 172 expect(abuse2.flaggedAccount.name).to.equal('root')
199 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) 173 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
200 174
201 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 175 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
202 expect(abuse2.state.label).to.equal('Pending') 176 expect(abuse2.state.label).to.equal('Pending')
203 expect(abuse2.moderationComment).to.be.null 177 expect(abuse2.moderationComment).to.be.null
178 }
204 179
205 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 180 {
206 expect(res2.body.total).to.equal(1) 181 const body = await commands[1].getAdminList()
207 expect(res2.body.data.length).to.equal(1) 182 expect(body.total).to.equal(1)
183 expect(body.data.length).to.equal(1)
208 184
209 abuseServer2 = res2.body.data[0] 185 abuseServer2 = body.data[0]
210 expect(abuseServer2.reason).to.equal('my super bad reason 2') 186 expect(abuseServer2.reason).to.equal('my super bad reason 2')
211 expect(abuseServer2.reporterAccount.name).to.equal('root') 187 expect(abuseServer2.reporterAccount.name).to.equal('root')
212 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 188 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
213 189
214 expect(abuse2.flaggedAccount.name).to.equal('root') 190 expect(abuseServer2.flaggedAccount.name).to.equal('root')
215 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) 191 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
216 192
217 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 193 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
218 expect(abuseServer2.state.label).to.equal('Pending') 194 expect(abuseServer2.state.label).to.equal('Pending')
219 expect(abuseServer2.moderationComment).to.be.null 195 expect(abuseServer2.moderationComment).to.be.null
196 }
220 }) 197 })
221 198
222 it('Should hide video abuses from blocked accounts', async function () { 199 it('Should hide video abuses from blocked accounts', async function () {
223 this.timeout(10000) 200 this.timeout(10000)
224 201
225 { 202 {
226 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) 203 const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid })
227 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) 204 await commands[1].report({ videoId, reason: 'will mute this' })
228 await waitJobs(servers) 205 await waitJobs(servers)
229 206
230 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 207 const body = await commands[0].getAdminList()
231 expect(res.body.total).to.equal(3) 208 expect(body.total).to.equal(3)
232 } 209 }
233 210
234 const accountToBlock = 'root@' + servers[1].host 211 const accountToBlock = 'root@' + servers[1].host
235 212
236 { 213 {
237 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 214 await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
238 215
239 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 216 const body = await commands[0].getAdminList()
240 expect(res.body.total).to.equal(2) 217 expect(body.total).to.equal(2)
241 218
242 const abuse = res.body.data.find(a => a.reason === 'will mute this') 219 const abuse = body.data.find(a => a.reason === 'will mute this')
243 expect(abuse).to.be.undefined 220 expect(abuse).to.be.undefined
244 } 221 }
245 222
246 { 223 {
247 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 224 await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
248 225
249 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 226 const body = await commands[0].getAdminList()
250 expect(res.body.total).to.equal(3) 227 expect(body.total).to.equal(3)
251 } 228 }
252 }) 229 })
253 230
@@ -255,35 +232,35 @@ describe('Test abuses', function () {
255 const serverToBlock = servers[1].host 232 const serverToBlock = servers[1].host
256 233
257 { 234 {
258 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) 235 await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
259 236
260 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 237 const body = await commands[0].getAdminList()
261 expect(res.body.total).to.equal(2) 238 expect(body.total).to.equal(2)
262 239
263 const abuse = res.body.data.find(a => a.reason === 'will mute this') 240 const abuse = body.data.find(a => a.reason === 'will mute this')
264 expect(abuse).to.be.undefined 241 expect(abuse).to.be.undefined
265 } 242 }
266 243
267 { 244 {
268 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) 245 await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
269 246
270 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 247 const body = await commands[0].getAdminList()
271 expect(res.body.total).to.equal(3) 248 expect(body.total).to.equal(3)
272 } 249 }
273 }) 250 })
274 251
275 it('Should keep the video abuse when deleting the video', async function () { 252 it('Should keep the video abuse when deleting the video', async function () {
276 this.timeout(10000) 253 this.timeout(10000)
277 254
278 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) 255 await servers[1].videos.remove({ id: abuseServer2.video.uuid })
279 256
280 await waitJobs(servers) 257 await waitJobs(servers)
281 258
282 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 259 const body = await commands[1].getAdminList()
283 expect(res.body.total).to.equal(2, "wrong number of videos returned") 260 expect(body.total).to.equal(2, "wrong number of videos returned")
284 expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") 261 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
285 262
286 const abuse: AdminAbuse = res.body.data[0] 263 const abuse = body.data[0]
287 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") 264 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
288 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") 265 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
289 expect(abuse.video.channel).to.exist 266 expect(abuse.video.channel).to.exist
@@ -295,39 +272,36 @@ describe('Test abuses', function () {
295 272
296 // register a second user to have two reporters/reportees 273 // register a second user to have two reporters/reportees
297 const user = { username: 'user2', password: 'password' } 274 const user = { username: 'user2', password: 'password' }
298 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) 275 await servers[0].users.create({ ...user })
299 const userAccessToken = await userLogin(servers[0], user) 276 const userAccessToken = await servers[0].login.getAccessToken(user)
300 277
301 // upload a third video via this user 278 // upload a third video via this user
302 const video3Attributes = { 279 const attributes = {
303 name: 'my second super name for server 1', 280 name: 'my second super name for server 1',
304 description: 'my second super description for server 1' 281 description: 'my second super description for server 1'
305 } 282 }
306 await uploadVideo(servers[0].url, userAccessToken, video3Attributes) 283 const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
307 284 const video3Id = id
308 const res1 = await getVideosList(servers[0].url)
309 const videos = res1.body.data
310 const video3 = videos.find(video => video.name === 'my second super name for server 1')
311 285
312 // resume with the test 286 // resume with the test
313 const reason3 = 'my super bad reason 3' 287 const reason3 = 'my super bad reason 3'
314 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) 288 await commands[0].report({ videoId: video3Id, reason: reason3 })
315 289
316 const reason4 = 'my super bad reason 4' 290 const reason4 = 'my super bad reason 4'
317 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) 291 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
318 292
319 { 293 {
320 const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 294 const body = await commands[0].getAdminList()
321 const abuses = res2.body.data as AdminAbuse[] 295 const abuses = body.data
322 296
323 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) 297 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
324 expect(abuseVideo3).to.not.be.undefined 298 expect(abuseVideo3).to.not.be.undefined
325 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") 299 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
326 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") 300 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
327 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") 301 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
328 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") 302 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
329 303
330 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id) 304 const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
331 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") 305 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
332 } 306 }
333 }) 307 })
@@ -337,20 +311,18 @@ describe('Test abuses', function () {
337 311
338 const reason5 = 'my super bad reason 5' 312 const reason5 = 'my super bad reason 5'
339 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] 313 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
340 const createdAbuse = (await reportAbuse({ 314 const createRes = await commands[0].report({
341 url: servers[0].url, 315 videoId: servers[0].store.videoCreated.id,
342 token: servers[0].accessToken,
343 videoId: servers[0].video.id,
344 reason: reason5, 316 reason: reason5,
345 predefinedReasons: predefinedReasons5, 317 predefinedReasons: predefinedReasons5,
346 startAt: 1, 318 startAt: 1,
347 endAt: 5 319 endAt: 5
348 })).body.abuse 320 })
349 321
350 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 322 const body = await commands[0].getAdminList()
351 323
352 { 324 {
353 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) 325 const abuse = body.data.find(a => a.id === createRes.abuse.id)
354 expect(abuse.reason).to.equals(reason5) 326 expect(abuse.reason).to.equals(reason5)
355 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") 327 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
356 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") 328 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
@@ -361,37 +333,30 @@ describe('Test abuses', function () {
361 it('Should delete the video abuse', async function () { 333 it('Should delete the video abuse', async function () {
362 this.timeout(10000) 334 this.timeout(10000)
363 335
364 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 336 await commands[1].delete({ abuseId: abuseServer2.id })
365 337
366 await waitJobs(servers) 338 await waitJobs(servers)
367 339
368 { 340 {
369 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 341 const body = await commands[1].getAdminList()
370 expect(res.body.total).to.equal(1) 342 expect(body.total).to.equal(1)
371 expect(res.body.data.length).to.equal(1) 343 expect(body.data.length).to.equal(1)
372 expect(res.body.data[0].id).to.not.equal(abuseServer2.id) 344 expect(body.data[0].id).to.not.equal(abuseServer2.id)
373 } 345 }
374 346
375 { 347 {
376 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 348 const body = await commands[0].getAdminList()
377 expect(res.body.total).to.equal(6) 349 expect(body.total).to.equal(6)
378 } 350 }
379 }) 351 })
380 352
381 it('Should list and filter video abuses', async function () { 353 it('Should list and filter video abuses', async function () {
382 this.timeout(10000) 354 this.timeout(10000)
383 355
384 async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) { 356 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
385 const options = { 357 const body = await commands[0].getAdminList(query)
386 url: servers[0].url,
387 token: servers[0].accessToken
388 }
389
390 Object.assign(options, query)
391 358
392 const res = await getAdminAbusesList(options) 359 return body.data
393
394 return res.body.data as AdminAbuse[]
395 } 360 }
396 361
397 expect(await list({ id: 56 })).to.have.lengthOf(0) 362 expect(await list({ id: 56 })).to.have.lengthOf(0)
@@ -424,24 +389,24 @@ describe('Test abuses', function () {
424 389
425 describe('Comment abuses', function () { 390 describe('Comment abuses', function () {
426 391
427 async function getComment (url: string, videoIdArg: number | string) { 392 async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
428 const videoId = typeof videoIdArg === 'string' 393 const videoId = typeof videoIdArg === 'string'
429 ? await getVideoIdFromUUID(url, videoIdArg) 394 ? await server.videos.getId({ uuid: videoIdArg })
430 : videoIdArg 395 : videoIdArg
431 396
432 const res = await getVideoCommentThreads(url, videoId, 0, 5) 397 const { data } = await server.comments.listThreads({ videoId })
433 398
434 return res.body.data[0] as VideoComment 399 return data[0]
435 } 400 }
436 401
437 before(async function () { 402 before(async function () {
438 this.timeout(50000) 403 this.timeout(50000)
439 404
440 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) 405 servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
441 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) 406 servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
442 407
443 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1') 408 await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
444 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2') 409 await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
445 410
446 await waitJobs(servers) 411 await waitJobs(servers)
447 }) 412 })
@@ -449,23 +414,23 @@ describe('Test abuses', function () {
449 it('Should report abuse on a comment', async function () { 414 it('Should report abuse on a comment', async function () {
450 this.timeout(15000) 415 this.timeout(15000)
451 416
452 const comment = await getComment(servers[0].url, servers[0].video.id) 417 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
453 418
454 const reason = 'it is a bad comment' 419 const reason = 'it is a bad comment'
455 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) 420 await commands[0].report({ commentId: comment.id, reason })
456 421
457 await waitJobs(servers) 422 await waitJobs(servers)
458 }) 423 })
459 424
460 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { 425 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
461 { 426 {
462 const comment = await getComment(servers[0].url, servers[0].video.id) 427 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
463 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 428 const body = await commands[0].getAdminList({ filter: 'comment' })
464 429
465 expect(res.body.total).to.equal(1) 430 expect(body.total).to.equal(1)
466 expect(res.body.data).to.have.lengthOf(1) 431 expect(body.data).to.have.lengthOf(1)
467 432
468 const abuse: AdminAbuse = res.body.data[0] 433 const abuse = body.data[0]
469 expect(abuse.reason).to.equal('it is a bad comment') 434 expect(abuse.reason).to.equal('it is a bad comment')
470 435
471 expect(abuse.reporterAccount.name).to.equal('root') 436 expect(abuse.reporterAccount.name).to.equal('root')
@@ -477,98 +442,102 @@ describe('Test abuses', function () {
477 expect(abuse.comment.id).to.equal(comment.id) 442 expect(abuse.comment.id).to.equal(comment.id)
478 expect(abuse.comment.text).to.equal(comment.text) 443 expect(abuse.comment.text).to.equal(comment.text)
479 expect(abuse.comment.video.name).to.equal('server 1') 444 expect(abuse.comment.video.name).to.equal('server 1')
480 expect(abuse.comment.video.id).to.equal(servers[0].video.id) 445 expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
481 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid) 446 expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
482 447
483 expect(abuse.countReportsForReporter).to.equal(5) 448 expect(abuse.countReportsForReporter).to.equal(5)
484 expect(abuse.countReportsForReportee).to.equal(5) 449 expect(abuse.countReportsForReportee).to.equal(5)
485 } 450 }
486 451
487 { 452 {
488 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 453 const body = await commands[1].getAdminList({ filter: 'comment' })
489 expect(res.body.total).to.equal(0) 454 expect(body.total).to.equal(0)
490 expect(res.body.data.length).to.equal(0) 455 expect(body.data.length).to.equal(0)
491 } 456 }
492 }) 457 })
493 458
494 it('Should report abuse on a remote comment', async function () { 459 it('Should report abuse on a remote comment', async function () {
495 this.timeout(10000) 460 this.timeout(10000)
496 461
497 const comment = await getComment(servers[0].url, servers[1].video.uuid) 462 const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid)
498 463
499 const reason = 'it is a really bad comment' 464 const reason = 'it is a really bad comment'
500 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) 465 await commands[0].report({ commentId: comment.id, reason })
501 466
502 await waitJobs(servers) 467 await waitJobs(servers)
503 }) 468 })
504 469
505 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 470 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
506 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 471 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.id)
507 472
508 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 473 {
509 expect(res1.body.total).to.equal(2) 474 const body = await commands[0].getAdminList({ filter: 'comment' })
510 expect(res1.body.data.length).to.equal(2) 475 expect(body.total).to.equal(2)
476 expect(body.data.length).to.equal(2)
511 477
512 const abuse: AdminAbuse = res1.body.data[0] 478 const abuse = body.data[0]
513 expect(abuse.reason).to.equal('it is a bad comment') 479 expect(abuse.reason).to.equal('it is a bad comment')
514 expect(abuse.countReportsForReporter).to.equal(6) 480 expect(abuse.countReportsForReporter).to.equal(6)
515 expect(abuse.countReportsForReportee).to.equal(5) 481 expect(abuse.countReportsForReportee).to.equal(5)
516 482
517 const abuse2: AdminAbuse = res1.body.data[1] 483 const abuse2 = body.data[1]
518 484
519 expect(abuse2.reason).to.equal('it is a really bad comment') 485 expect(abuse2.reason).to.equal('it is a really bad comment')
520 486
521 expect(abuse2.reporterAccount.name).to.equal('root') 487 expect(abuse2.reporterAccount.name).to.equal('root')
522 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 488 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
523 489
524 expect(abuse2.video).to.be.null 490 expect(abuse2.video).to.be.null
525 491
526 expect(abuse2.comment.deleted).to.be.false 492 expect(abuse2.comment.deleted).to.be.false
527 expect(abuse2.comment.id).to.equal(commentServer2.id) 493 expect(abuse2.comment.id).to.equal(commentServer2.id)
528 expect(abuse2.comment.text).to.equal(commentServer2.text) 494 expect(abuse2.comment.text).to.equal(commentServer2.text)
529 expect(abuse2.comment.video.name).to.equal('server 2') 495 expect(abuse2.comment.video.name).to.equal('server 2')
530 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) 496 expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
531 497
532 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 498 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
533 expect(abuse2.state.label).to.equal('Pending') 499 expect(abuse2.state.label).to.equal('Pending')
534 500
535 expect(abuse2.moderationComment).to.be.null 501 expect(abuse2.moderationComment).to.be.null
536 502
537 expect(abuse2.countReportsForReporter).to.equal(6) 503 expect(abuse2.countReportsForReporter).to.equal(6)
538 expect(abuse2.countReportsForReportee).to.equal(2) 504 expect(abuse2.countReportsForReportee).to.equal(2)
505 }
539 506
540 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 507 {
541 expect(res2.body.total).to.equal(1) 508 const body = await commands[1].getAdminList({ filter: 'comment' })
542 expect(res2.body.data.length).to.equal(1) 509 expect(body.total).to.equal(1)
510 expect(body.data.length).to.equal(1)
543 511
544 abuseServer2 = res2.body.data[0] 512 abuseServer2 = body.data[0]
545 expect(abuseServer2.reason).to.equal('it is a really bad comment') 513 expect(abuseServer2.reason).to.equal('it is a really bad comment')
546 expect(abuseServer2.reporterAccount.name).to.equal('root') 514 expect(abuseServer2.reporterAccount.name).to.equal('root')
547 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 515 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
548 516
549 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 517 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
550 expect(abuseServer2.state.label).to.equal('Pending') 518 expect(abuseServer2.state.label).to.equal('Pending')
551 519
552 expect(abuseServer2.moderationComment).to.be.null 520 expect(abuseServer2.moderationComment).to.be.null
553 521
554 expect(abuseServer2.countReportsForReporter).to.equal(1) 522 expect(abuseServer2.countReportsForReporter).to.equal(1)
555 expect(abuseServer2.countReportsForReportee).to.equal(1) 523 expect(abuseServer2.countReportsForReportee).to.equal(1)
524 }
556 }) 525 })
557 526
558 it('Should keep the comment abuse when deleting the comment', async function () { 527 it('Should keep the comment abuse when deleting the comment', async function () {
559 this.timeout(10000) 528 this.timeout(10000)
560 529
561 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 530 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.id)
562 531
563 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id) 532 await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id })
564 533
565 await waitJobs(servers) 534 await waitJobs(servers)
566 535
567 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 536 const body = await commands[0].getAdminList({ filter: 'comment' })
568 expect(res.body.total).to.equal(2) 537 expect(body.total).to.equal(2)
569 expect(res.body.data).to.have.lengthOf(2) 538 expect(body.data).to.have.lengthOf(2)
570 539
571 const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id) 540 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
572 expect(abuse).to.not.be.undefined 541 expect(abuse).to.not.be.undefined
573 542
574 expect(abuse.comment.text).to.be.empty 543 expect(abuse.comment.text).to.be.empty
@@ -579,72 +548,60 @@ describe('Test abuses', function () {
579 it('Should delete the comment abuse', async function () { 548 it('Should delete the comment abuse', async function () {
580 this.timeout(10000) 549 this.timeout(10000)
581 550
582 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 551 await commands[1].delete({ abuseId: abuseServer2.id })
583 552
584 await waitJobs(servers) 553 await waitJobs(servers)
585 554
586 { 555 {
587 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 556 const body = await commands[1].getAdminList({ filter: 'comment' })
588 expect(res.body.total).to.equal(0) 557 expect(body.total).to.equal(0)
589 expect(res.body.data.length).to.equal(0) 558 expect(body.data.length).to.equal(0)
590 } 559 }
591 560
592 { 561 {
593 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 562 const body = await commands[0].getAdminList({ filter: 'comment' })
594 expect(res.body.total).to.equal(2) 563 expect(body.total).to.equal(2)
595 } 564 }
596 }) 565 })
597 566
598 it('Should list and filter video abuses', async function () { 567 it('Should list and filter video abuses', async function () {
599 { 568 {
600 const res = await getAdminAbusesList({ 569 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
601 url: servers[0].url, 570 expect(body.total).to.equal(0)
602 token: servers[0].accessToken,
603 filter: 'comment',
604 searchReportee: 'foo'
605 })
606 expect(res.body.total).to.equal(0)
607 } 571 }
608 572
609 { 573 {
610 const res = await getAdminAbusesList({ 574 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
611 url: servers[0].url, 575 expect(body.total).to.equal(2)
612 token: servers[0].accessToken,
613 filter: 'comment',
614 searchReportee: 'ot'
615 })
616 expect(res.body.total).to.equal(2)
617 } 576 }
618 577
619 { 578 {
620 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } 579 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
621 580 expect(body.data).to.have.lengthOf(1)
622 const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) 581 expect(body.data[0].comment.text).to.be.empty
623 expect(res1.body.data).to.have.lengthOf(1) 582 }
624 expect(res1.body.data[0].comment.text).to.be.empty
625 583
626 const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) 584 {
627 expect(res2.body.data).to.have.lengthOf(1) 585 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
628 expect(res2.body.data[0].comment.text).to.equal('comment server 1') 586 expect(body.data).to.have.lengthOf(1)
587 expect(body.data[0].comment.text).to.equal('comment server 1')
629 } 588 }
630 }) 589 })
631 }) 590 })
632 591
633 describe('Account abuses', function () { 592 describe('Account abuses', function () {
634 593
635 async function getAccountFromServer (url: string, name: string, server: ServerInfo) { 594 function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
636 const res = await getAccount(url, name + '@' + server.host) 595 return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
637
638 return res.body as Account
639 } 596 }
640 597
641 before(async function () { 598 before(async function () {
642 this.timeout(50000) 599 this.timeout(50000)
643 600
644 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) 601 await servers[0].users.create({ username: 'user_1', password: 'donald' })
645 602
646 const token = await generateUserAccessToken(servers[1], 'user_2') 603 const token = await servers[1].users.generateUserAndToken('user_2')
647 await uploadVideo(servers[1].url, token, { name: 'super video' }) 604 await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
648 605
649 await waitJobs(servers) 606 await waitJobs(servers)
650 }) 607 })
@@ -652,22 +609,22 @@ describe('Test abuses', function () {
652 it('Should report abuse on an account', async function () { 609 it('Should report abuse on an account', async function () {
653 this.timeout(15000) 610 this.timeout(15000)
654 611
655 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) 612 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
656 613
657 const reason = 'it is a bad account' 614 const reason = 'it is a bad account'
658 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) 615 await commands[0].report({ accountId: account.id, reason })
659 616
660 await waitJobs(servers) 617 await waitJobs(servers)
661 }) 618 })
662 619
663 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { 620 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
664 { 621 {
665 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 622 const body = await commands[0].getAdminList({ filter: 'account' })
666 623
667 expect(res.body.total).to.equal(1) 624 expect(body.total).to.equal(1)
668 expect(res.body.data).to.have.lengthOf(1) 625 expect(body.data).to.have.lengthOf(1)
669 626
670 const abuse: AdminAbuse = res.body.data[0] 627 const abuse = body.data[0]
671 expect(abuse.reason).to.equal('it is a bad account') 628 expect(abuse.reason).to.equal('it is a bad account')
672 629
673 expect(abuse.reporterAccount.name).to.equal('root') 630 expect(abuse.reporterAccount.name).to.equal('root')
@@ -681,96 +638,100 @@ describe('Test abuses', function () {
681 } 638 }
682 639
683 { 640 {
684 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 641 const body = await commands[1].getAdminList({ filter: 'comment' })
685 expect(res.body.total).to.equal(0) 642 expect(body.total).to.equal(0)
686 expect(res.body.data.length).to.equal(0) 643 expect(body.data.length).to.equal(0)
687 } 644 }
688 }) 645 })
689 646
690 it('Should report abuse on a remote account', async function () { 647 it('Should report abuse on a remote account', async function () {
691 this.timeout(10000) 648 this.timeout(10000)
692 649
693 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) 650 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
694 651
695 const reason = 'it is a really bad account' 652 const reason = 'it is a really bad account'
696 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) 653 await commands[0].report({ accountId: account.id, reason })
697 654
698 await waitJobs(servers) 655 await waitJobs(servers)
699 }) 656 })
700 657
701 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 658 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
702 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 659 {
703 expect(res1.body.total).to.equal(2) 660 const body = await commands[0].getAdminList({ filter: 'account' })
704 expect(res1.body.data.length).to.equal(2) 661 expect(body.total).to.equal(2)
662 expect(body.data.length).to.equal(2)
705 663
706 const abuse: AdminAbuse = res1.body.data[0] 664 const abuse: AdminAbuse = body.data[0]
707 expect(abuse.reason).to.equal('it is a bad account') 665 expect(abuse.reason).to.equal('it is a bad account')
708 666
709 const abuse2: AdminAbuse = res1.body.data[1] 667 const abuse2: AdminAbuse = body.data[1]
710 expect(abuse2.reason).to.equal('it is a really bad account') 668 expect(abuse2.reason).to.equal('it is a really bad account')
711 669
712 expect(abuse2.reporterAccount.name).to.equal('root') 670 expect(abuse2.reporterAccount.name).to.equal('root')
713 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 671 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
714 672
715 expect(abuse2.video).to.be.null 673 expect(abuse2.video).to.be.null
716 expect(abuse2.comment).to.be.null 674 expect(abuse2.comment).to.be.null
717 675
718 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 676 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
719 expect(abuse2.state.label).to.equal('Pending') 677 expect(abuse2.state.label).to.equal('Pending')
720 678
721 expect(abuse2.moderationComment).to.be.null 679 expect(abuse2.moderationComment).to.be.null
680 }
722 681
723 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 682 {
724 expect(res2.body.total).to.equal(1) 683 const body = await commands[1].getAdminList({ filter: 'account' })
725 expect(res2.body.data.length).to.equal(1) 684 expect(body.total).to.equal(1)
685 expect(body.data.length).to.equal(1)
726 686
727 abuseServer2 = res2.body.data[0] 687 abuseServer2 = body.data[0]
728 688
729 expect(abuseServer2.reason).to.equal('it is a really bad account') 689 expect(abuseServer2.reason).to.equal('it is a really bad account')
730 690
731 expect(abuseServer2.reporterAccount.name).to.equal('root') 691 expect(abuseServer2.reporterAccount.name).to.equal('root')
732 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 692 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
733 693
734 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 694 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
735 expect(abuseServer2.state.label).to.equal('Pending') 695 expect(abuseServer2.state.label).to.equal('Pending')
736 696
737 expect(abuseServer2.moderationComment).to.be.null 697 expect(abuseServer2.moderationComment).to.be.null
698 }
738 }) 699 })
739 700
740 it('Should keep the account abuse when deleting the account', async function () { 701 it('Should keep the account abuse when deleting the account', async function () {
741 this.timeout(10000) 702 this.timeout(10000)
742 703
743 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) 704 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
744 await removeUser(servers[1].url, account.userId, servers[1].accessToken) 705 await servers[1].users.remove({ userId: account.userId })
745 706
746 await waitJobs(servers) 707 await waitJobs(servers)
747 708
748 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 709 const body = await commands[0].getAdminList({ filter: 'account' })
749 expect(res.body.total).to.equal(2) 710 expect(body.total).to.equal(2)
750 expect(res.body.data).to.have.lengthOf(2) 711 expect(body.data).to.have.lengthOf(2)
751 712
752 const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account') 713 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
753 expect(abuse).to.not.be.undefined 714 expect(abuse).to.not.be.undefined
754 }) 715 })
755 716
756 it('Should delete the account abuse', async function () { 717 it('Should delete the account abuse', async function () {
757 this.timeout(10000) 718 this.timeout(10000)
758 719
759 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 720 await commands[1].delete({ abuseId: abuseServer2.id })
760 721
761 await waitJobs(servers) 722 await waitJobs(servers)
762 723
763 { 724 {
764 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 725 const body = await commands[1].getAdminList({ filter: 'account' })
765 expect(res.body.total).to.equal(0) 726 expect(body.total).to.equal(0)
766 expect(res.body.data.length).to.equal(0) 727 expect(body.data.length).to.equal(0)
767 } 728 }
768 729
769 { 730 {
770 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 731 const body = await commands[0].getAdminList({ filter: 'account' })
771 expect(res.body.total).to.equal(2) 732 expect(body.total).to.equal(2)
772 733
773 abuseServer1 = res.body.data[0] 734 abuseServer1 = body.data[0]
774 } 735 }
775 }) 736 })
776 }) 737 })
@@ -778,20 +739,18 @@ describe('Test abuses', function () {
778 describe('Common actions on abuses', function () { 739 describe('Common actions on abuses', function () {
779 740
780 it('Should update the state of an abuse', async function () { 741 it('Should update the state of an abuse', async function () {
781 const body = { state: AbuseState.REJECTED } 742 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
782 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
783 743
784 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 744 const body = await commands[0].getAdminList({ id: abuseServer1.id })
785 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) 745 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
786 }) 746 })
787 747
788 it('Should add a moderation comment', async function () { 748 it('Should add a moderation comment', async function () {
789 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } 749 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
790 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
791 750
792 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 751 const body = await commands[0].getAdminList({ id: abuseServer1.id })
793 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) 752 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
794 expect(res.body.data[0].moderationComment).to.equal('It is valid') 753 expect(body.data[0].moderationComment).to.equal('Valid')
795 }) 754 })
796 }) 755 })
797 756
@@ -800,20 +759,20 @@ describe('Test abuses', function () {
800 let userAccessToken: string 759 let userAccessToken: string
801 760
802 before(async function () { 761 before(async function () {
803 userAccessToken = await generateUserAccessToken(servers[0], 'user_42') 762 userAccessToken = await servers[0].users.generateUserAndToken('user_42')
804 763
805 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) 764 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
806 765
807 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 766 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
808 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' }) 767 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
809 }) 768 })
810 769
811 it('Should correctly list my abuses', async function () { 770 it('Should correctly list my abuses', async function () {
812 { 771 {
813 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) 772 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
814 expect(res.body.total).to.equal(2) 773 expect(body.total).to.equal(2)
815 774
816 const abuses: UserAbuse[] = res.body.data 775 const abuses = body.data
817 expect(abuses[0].reason).to.equal('user reason 1') 776 expect(abuses[0].reason).to.equal('user reason 1')
818 expect(abuses[1].reason).to.equal('user reason 2') 777 expect(abuses[1].reason).to.equal('user reason 2')
819 778
@@ -821,95 +780,77 @@ describe('Test abuses', function () {
821 } 780 }
822 781
823 { 782 {
824 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) 783 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
825 expect(res.body.total).to.equal(2) 784 expect(body.total).to.equal(2)
826 785
827 const abuses: UserAbuse[] = res.body.data 786 const abuses: UserAbuse[] = body.data
828 expect(abuses[0].reason).to.equal('user reason 2') 787 expect(abuses[0].reason).to.equal('user reason 2')
829 } 788 }
830 789
831 { 790 {
832 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) 791 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
833 expect(res.body.total).to.equal(2) 792 expect(body.total).to.equal(2)
834 793
835 const abuses: UserAbuse[] = res.body.data 794 const abuses: UserAbuse[] = body.data
836 expect(abuses[0].reason).to.equal('user reason 1') 795 expect(abuses[0].reason).to.equal('user reason 1')
837 } 796 }
838 }) 797 })
839 798
840 it('Should correctly filter my abuses by id', async function () { 799 it('Should correctly filter my abuses by id', async function () {
841 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 }) 800 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
801 expect(body.total).to.equal(1)
842 802
843 expect(res.body.total).to.equal(1) 803 const abuses: UserAbuse[] = body.data
844
845 const abuses: UserAbuse[] = res.body.data
846 expect(abuses[0].reason).to.equal('user reason 1') 804 expect(abuses[0].reason).to.equal('user reason 1')
847 }) 805 })
848 806
849 it('Should correctly filter my abuses by search', async function () { 807 it('Should correctly filter my abuses by search', async function () {
850 const res = await getUserAbusesList({ 808 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
851 url: servers[0].url, 809 expect(body.total).to.equal(1)
852 token: userAccessToken,
853 search: 'server 2'
854 })
855
856 expect(res.body.total).to.equal(1)
857 810
858 const abuses: UserAbuse[] = res.body.data 811 const abuses: UserAbuse[] = body.data
859 expect(abuses[0].reason).to.equal('user reason 2') 812 expect(abuses[0].reason).to.equal('user reason 2')
860 }) 813 })
861 814
862 it('Should correctly filter my abuses by state', async function () { 815 it('Should correctly filter my abuses by state', async function () {
863 const body = { state: AbuseState.REJECTED } 816 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
864 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body)
865 817
866 const res = await getUserAbusesList({ 818 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
867 url: servers[0].url, 819 expect(body.total).to.equal(1)
868 token: userAccessToken,
869 state: AbuseState.REJECTED
870 })
871
872 expect(res.body.total).to.equal(1)
873 820
874 const abuses: UserAbuse[] = res.body.data 821 const abuses: UserAbuse[] = body.data
875 expect(abuses[0].reason).to.equal('user reason 1') 822 expect(abuses[0].reason).to.equal('user reason 1')
876 }) 823 })
877 }) 824 })
878 825
879 describe('Abuse messages', async function () { 826 describe('Abuse messages', async function () {
880 let abuseId: number 827 let abuseId: number
881 let userAccessToken: string 828 let userToken: string
882 let abuseMessageUserId: number 829 let abuseMessageUserId: number
883 let abuseMessageModerationId: number 830 let abuseMessageModerationId: number
884 831
885 before(async function () { 832 before(async function () {
886 userAccessToken = await generateUserAccessToken(servers[0], 'user_43') 833 userToken = await servers[0].users.generateUserAndToken('user_43')
887 834
888 const res = await reportAbuse({ 835 const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })
889 url: servers[0].url, 836 abuseId = body.abuse.id
890 token: userAccessToken,
891 videoId: servers[0].video.id,
892 reason: 'user 43 reason 1'
893 })
894
895 abuseId = res.body.abuse.id
896 }) 837 })
897 838
898 it('Should create some messages on the abuse', async function () { 839 it('Should create some messages on the abuse', async function () {
899 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1') 840 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
900 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2') 841 await commands[0].addMessage({ abuseId, message: 'message 2' })
901 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3') 842 await commands[0].addMessage({ abuseId, message: 'message 3' })
902 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4') 843 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
903 }) 844 })
904 845
905 it('Should have the correct messages count when listing abuses', async function () { 846 it('Should have the correct messages count when listing abuses', async function () {
906 const results = await Promise.all([ 847 const results = await Promise.all([
907 getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }), 848 commands[0].getAdminList({ start: 0, count: 50 }),
908 getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 }) 849 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
909 ]) 850 ])
910 851
911 for (const res of results) { 852 for (const body of results) {
912 const abuses: AdminAbuse[] = res.body.data 853 const abuses = body.data
913 const abuse = abuses.find(a => a.id === abuseId) 854 const abuse = abuses.find(a => a.id === abuseId)
914 expect(abuse.countMessages).to.equal(4) 855 expect(abuse.countMessages).to.equal(4)
915 } 856 }
@@ -917,14 +858,14 @@ describe('Test abuses', function () {
917 858
918 it('Should correctly list messages of this abuse', async function () { 859 it('Should correctly list messages of this abuse', async function () {
919 const results = await Promise.all([ 860 const results = await Promise.all([
920 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), 861 commands[0].listMessages({ abuseId }),
921 listAbuseMessages(servers[0].url, userAccessToken, abuseId) 862 commands[0].listMessages({ token: userToken, abuseId })
922 ]) 863 ])
923 864
924 for (const res of results) { 865 for (const body of results) {
925 expect(res.body.total).to.equal(4) 866 expect(body.total).to.equal(4)
926 867
927 const abuseMessages: AbuseMessage[] = res.body.data 868 const abuseMessages: AbuseMessage[] = body.data
928 869
929 expect(abuseMessages[0].message).to.equal('message 1') 870 expect(abuseMessages[0].message).to.equal('message 1')
930 expect(abuseMessages[0].byModerator).to.be.false 871 expect(abuseMessages[0].byModerator).to.be.false
@@ -948,19 +889,18 @@ describe('Test abuses', function () {
948 }) 889 })
949 890
950 it('Should delete messages', async function () { 891 it('Should delete messages', async function () {
951 await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId) 892 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
952 await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId) 893 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
953 894
954 const results = await Promise.all([ 895 const results = await Promise.all([
955 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), 896 commands[0].listMessages({ abuseId }),
956 listAbuseMessages(servers[0].url, userAccessToken, abuseId) 897 commands[0].listMessages({ token: userToken, abuseId })
957 ]) 898 ])
958 899
959 for (const res of results) { 900 for (const body of results) {
960 expect(res.body.total).to.equal(2) 901 expect(body.total).to.equal(2)
961
962 const abuseMessages: AbuseMessage[] = res.body.data
963 902
903 const abuseMessages: AbuseMessage[] = body.data
964 expect(abuseMessages[0].message).to.equal('message 2') 904 expect(abuseMessages[0].message).to.equal('message 2')
965 expect(abuseMessages[1].message).to.equal('message 4') 905 expect(abuseMessages[1].message).to.equal('message 4')
966 } 906 }