aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-06 17:39:07 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-07 08:33:34 +0200
commitfeb34f6b6b991046aab6a10df747b48fa4da07a7 (patch)
tree02bb7277d45be166ba48caef2ee73bf89dbe1258 /server/tests
parentd170c5c580abf6f90d7bf144e2417e248ce2ecf4 (diff)
downloadPeerTube-feb34f6b6b991046aab6a10df747b48fa4da07a7.tar.gz
PeerTube-feb34f6b6b991046aab6a10df747b48fa4da07a7.tar.zst
PeerTube-feb34f6b6b991046aab6a10df747b48fa4da07a7.zip
Use video abuse filters on client side
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-abuses.ts16
-rw-r--r--server/tests/api/users/users.ts2
-rw-r--r--server/tests/api/videos/video-abuse.ts70
3 files changed, 71 insertions, 17 deletions
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index bea2177f3..e643cb95e 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -76,6 +76,22 @@ describe('Test video abuses API validators', function () {
76 statusCodeExpected: 403 76 statusCodeExpected: 403
77 }) 77 })
78 }) 78 })
79
80 it('Should fail with a bad id filter', async function () {
81 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } })
82 })
83
84 it('Should fail with a bad state filter', async function () {
85 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
86 })
87
88 it('Should fail with a bad videoIs filter', async function () {
89 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
90 })
91
92 it('Should succeed with the correct params', async function () {
93 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 13 }, statusCodeExpected: 200 })
94 })
79 }) 95 })
80 96
81 describe('When reporting a video abuse', function () { 97 describe('When reporting a video abuse', function () {
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 60fbd2a20..f3b732632 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -901,7 +901,7 @@ describe('Test users', function () {
901 const reason = 'my super bad reason' 901 const reason = 'my super bad reason'
902 await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) 902 await reportVideoAbuse(server.url, user17AccessToken, videoId, reason)
903 903
904 const res1 = await getVideoAbusesList(server.url, server.accessToken) 904 const res1 = await getVideoAbusesList({ url: server.url, token: server.accessToken })
905 const abuseId = res1.body.data[0].id 905 const abuseId = res1.body.data[0].id
906 906
907 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) 907 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index 26bc3783b..a96be97f6 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -71,7 +71,7 @@ describe('Test video abuses', function () {
71 }) 71 })
72 72
73 it('Should not have video abuses', async function () { 73 it('Should not have video abuses', async function () {
74 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 74 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
75 75
76 expect(res.body.total).to.equal(0) 76 expect(res.body.total).to.equal(0)
77 expect(res.body.data).to.be.an('array') 77 expect(res.body.data).to.be.an('array')
@@ -89,7 +89,7 @@ describe('Test video abuses', function () {
89 }) 89 })
90 90
91 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { 91 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
92 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 92 const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
93 93
94 expect(res1.body.total).to.equal(1) 94 expect(res1.body.total).to.equal(1)
95 expect(res1.body.data).to.be.an('array') 95 expect(res1.body.data).to.be.an('array')
@@ -106,7 +106,7 @@ describe('Test video abuses', function () {
106 expect(abuse.countReportsForReporter).to.equal(1) 106 expect(abuse.countReportsForReporter).to.equal(1)
107 expect(abuse.countReportsForReportee).to.equal(1) 107 expect(abuse.countReportsForReportee).to.equal(1)
108 108
109 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 109 const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
110 expect(res2.body.total).to.equal(0) 110 expect(res2.body.total).to.equal(0)
111 expect(res2.body.data).to.be.an('array') 111 expect(res2.body.data).to.be.an('array')
112 expect(res2.body.data.length).to.equal(0) 112 expect(res2.body.data.length).to.equal(0)
@@ -123,7 +123,7 @@ describe('Test video abuses', function () {
123 }) 123 })
124 124
125 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { 125 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
126 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 126 const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
127 expect(res1.body.total).to.equal(2) 127 expect(res1.body.total).to.equal(2)
128 expect(res1.body.data).to.be.an('array') 128 expect(res1.body.data).to.be.an('array')
129 expect(res1.body.data.length).to.equal(2) 129 expect(res1.body.data.length).to.equal(2)
@@ -148,7 +148,7 @@ describe('Test video abuses', function () {
148 expect(abuse2.state.label).to.equal('Pending') 148 expect(abuse2.state.label).to.equal('Pending')
149 expect(abuse2.moderationComment).to.be.null 149 expect(abuse2.moderationComment).to.be.null
150 150
151 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 151 const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
152 expect(res2.body.total).to.equal(1) 152 expect(res2.body.total).to.equal(1)
153 expect(res2.body.data).to.be.an('array') 153 expect(res2.body.data).to.be.an('array')
154 expect(res2.body.data.length).to.equal(1) 154 expect(res2.body.data.length).to.equal(1)
@@ -166,7 +166,7 @@ describe('Test video abuses', function () {
166 const body = { state: VideoAbuseState.REJECTED } 166 const body = { state: VideoAbuseState.REJECTED }
167 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) 167 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
168 168
169 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 169 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
170 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED) 170 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED)
171 }) 171 })
172 172
@@ -174,7 +174,7 @@ describe('Test video abuses', function () {
174 const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' } 174 const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' }
175 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) 175 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
176 176
177 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 177 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
178 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED) 178 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED)
179 expect(res.body.data[0].moderationComment).to.equal('It is valid') 179 expect(res.body.data[0].moderationComment).to.equal('It is valid')
180 }) 180 })
@@ -186,7 +186,7 @@ describe('Test video abuses', function () {
186 await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this') 186 await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this')
187 await waitJobs(servers) 187 await waitJobs(servers)
188 188
189 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 189 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
190 expect(res.body.total).to.equal(3) 190 expect(res.body.total).to.equal(3)
191 } 191 }
192 192
@@ -195,7 +195,7 @@ describe('Test video abuses', function () {
195 { 195 {
196 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 196 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
197 197
198 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 198 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
199 expect(res.body.total).to.equal(2) 199 expect(res.body.total).to.equal(2)
200 200
201 const abuse = res.body.data.find(a => a.reason === 'will mute this') 201 const abuse = res.body.data.find(a => a.reason === 'will mute this')
@@ -205,7 +205,7 @@ describe('Test video abuses', function () {
205 { 205 {
206 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 206 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
207 207
208 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 208 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
209 expect(res.body.total).to.equal(3) 209 expect(res.body.total).to.equal(3)
210 } 210 }
211 }) 211 })
@@ -216,7 +216,7 @@ describe('Test video abuses', function () {
216 { 216 {
217 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) 217 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
218 218
219 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 219 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
220 expect(res.body.total).to.equal(2) 220 expect(res.body.total).to.equal(2)
221 221
222 const abuse = res.body.data.find(a => a.reason === 'will mute this') 222 const abuse = res.body.data.find(a => a.reason === 'will mute this')
@@ -226,7 +226,7 @@ describe('Test video abuses', function () {
226 { 226 {
227 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) 227 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
228 228
229 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 229 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
230 expect(res.body.total).to.equal(3) 230 expect(res.body.total).to.equal(3)
231 } 231 }
232 }) 232 })
@@ -238,7 +238,7 @@ describe('Test video abuses', function () {
238 238
239 await waitJobs(servers) 239 await waitJobs(servers)
240 240
241 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 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") 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") 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") 244 expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video")
@@ -274,7 +274,7 @@ describe('Test video abuses', function () {
274 const reason4 = 'my super bad reason 4' 274 const reason4 = 'my super bad reason 4'
275 await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4) 275 await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4)
276 276
277 const res2 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 277 const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
278 278
279 { 279 {
280 for (const abuse of res2.body.data as VideoAbuse[]) { 280 for (const abuse of res2.body.data as VideoAbuse[]) {
@@ -299,18 +299,56 @@ describe('Test video abuses', function () {
299 await waitJobs(servers) 299 await waitJobs(servers)
300 300
301 { 301 {
302 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 302 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
303 expect(res.body.total).to.equal(1) 303 expect(res.body.total).to.equal(1)
304 expect(res.body.data.length).to.equal(1) 304 expect(res.body.data.length).to.equal(1)
305 expect(res.body.data[0].id).to.not.equal(abuseServer2.id) 305 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
306 } 306 }
307 307
308 { 308 {
309 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 309 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
310 expect(res.body.total).to.equal(5) 310 expect(res.body.total).to.equal(5)
311 } 311 }
312 }) 312 })
313 313
314 it('Should list and filter video abuses', async function () {
315 async function list (query: Omit<Parameters<typeof getVideoAbusesList>[0], 'url' | 'token'>) {
316 const options = {
317 url: servers[0].url,
318 token: servers[0].accessToken
319 }
320
321 Object.assign(options, query)
322
323 const res = await getVideoAbusesList(options)
324
325 return res.body.data as VideoAbuse[]
326 }
327
328 expect(await list({ id: 56 })).to.have.lengthOf(0)
329 expect(await list({ id: 1 })).to.have.lengthOf(1)
330
331 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(3)
332 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
333
334 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
335
336 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(3)
337 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
338
339 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
340 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(4)
341
342 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(3)
343 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
344
345 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
346 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
347
348 expect(await list({ state: VideoAbuseState.ACCEPTED })).to.have.lengthOf(0)
349 expect(await list({ state: VideoAbuseState.PENDING })).to.have.lengthOf(5)
350 })
351
314 after(async function () { 352 after(async function () {
315 await cleanupTests(servers) 353 await cleanupTests(servers)
316 }) 354 })